Sha256: 0f0e02bd1fa97f773e447c5ef37db31959303082c66e4b7239098a431cb505b6

Contents?: true

Size: 790 Bytes

Versions: 27

Compression:

Stored size: 790 Bytes

Contents

require 'test_helper'

# This tests our Integer calculations extension
class Integer::CalculationsTest < Minitest::Test
  test 'Integer should be extended with #factorial' do
    assert 1.respond_to?(:factorial)
  end

  test 'Integer#factorial should behave correctly' do
    assert_equal 1, 0.factorial
    assert_equal 24, 4.factorial
    assert_raises(RuntimeError) { -1.factorial }
  end

  test 'Integer should be extended with #choose' do
    assert 1.respond_to?(:choose)
  end

  test 'Integer#choose should behave correctly' do
    pascal_row = [1, 5, 10, 10, 5, 1]
    pascal_row.each_with_index do |target, index|
      assert_equal target, 5.choose(index)
    end

    assert_raises(ArgumentError) { 10.choose(11) }
    assert_raises(ArgumentError) { 10.choose(-1) }
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
ndr_support-5.10.4 test/integer/calculations_test.rb
ndr_support-5.10.3 test/integer/calculations_test.rb
ndr_support-5.10.2 test/integer/calculations_test.rb
ndr_support-5.10.1 test/integer/calculations_test.rb
ndr_support-5.10.0 test/integer/calculations_test.rb
ndr_support-5.9.7 test/integer/calculations_test.rb
ndr_support-5.9.6 test/integer/calculations_test.rb
ndr_support-5.9.5 test/integer/calculations_test.rb
ndr_support-5.9.4 test/integer/calculations_test.rb
ndr_support-5.9.3 test/integer/calculations_test.rb
ndr_support-5.9.2 test/integer/calculations_test.rb
ndr_support-5.9.1 test/integer/calculations_test.rb
ndr_support-5.9.0 test/integer/calculations_test.rb
ndr_support-5.8.4 test/integer/calculations_test.rb
ndr_support-5.8.3 test/integer/calculations_test.rb
ndr_support-5.8.2 test/integer/calculations_test.rb
ndr_support-5.8.1 test/integer/calculations_test.rb
ndr_support-5.8.0 test/integer/calculations_test.rb
ndr_support-5.7.1 test/integer/calculations_test.rb
ndr_support-5.7.0 test/integer/calculations_test.rb