Sha256: 5ee37e8b883a0fd44ecfe13941f7304462554a2863cc489f5b0949a52441ae61

Contents?: true

Size: 787 Bytes

Versions: 14

Compression:

Stored size: 787 Bytes

Contents

require 'test_helper'

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

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

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

  test 'Fixnum#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

14 entries across 14 versions & 1 rubygems

Version Path
ndr_support-5.3.1 test/fixnum/calculations_test.rb
ndr_support-5.3.0 test/fixnum/calculations_test.rb
ndr_support-5.2.0 test/fixnum/calculations_test.rb
ndr_support-5.1.0 test/fixnum/calculations_test.rb
ndr_support-4.2.0 test/fixnum/calculations_test.rb
ndr_support-5.0.0 test/fixnum/calculations_test.rb
ndr_support-4.1.2 test/fixnum/calculations_test.rb
ndr_support-4.1.1 test/fixnum/calculations_test.rb
ndr_support-4.0.1 test/fixnum/calculations_test.rb
ndr_support-4.0.0 test/fixnum/calculations_test.rb
ndr_support-3.3.0 test/fixnum/calculations_test.rb
ndr_support-3.2.1 test/fixnum/calculations_test.rb
ndr_support-3.2.0 test/fixnum/calculations_test.rb
ndr_support-3.1.1 test/fixnum/calculations_test.rb