Class: SubsetTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
MoreMath
Defined in:
tests/subset_test.rb

Constant Summary

Constants included from MoreMath

MoreMath::Infinity, MoreMath::STD_NORMAL_DISTRIBUTION, MoreMath::VERSION, MoreMath::VERSION_ARRAY, MoreMath::VERSION_BUILD, MoreMath::VERSION_MAJOR, MoreMath::VERSION_MINOR

Instance Method Summary collapse

Instance Method Details

#test_empty_setObject



9
10
11
# File 'tests/subset_test.rb', line 9

def test_empty_set
  assert_equal [[]], Subset.for([]).map(&:value)
end

#test_one_element_setObject



13
14
15
# File 'tests/subset_test.rb', line 13

def test_one_element_set
  assert_equal [[], [1]], Subset.for([1]).map(&:value)
end

#test_projectObject



23
24
25
26
27
28
29
30
31
32
# File 'tests/subset_test.rb', line 23

def test_project
  a      = %i[ a b c d e ]
  subset = Subset.new(a.size, 23)
  assert_raises(ArgumentError) { subset.project a + %i[ f ] }
  (2 ** a.size).times do |i|
    subset  = Subset.new(a.size, i)
    projected = subset.project(a)
    assert_equal(projected, Subset.power_set(a)[i])
  end
end

#test_three_element_setObject



17
18
19
20
21
# File 'tests/subset_test.rb', line 17

def test_three_element_set
  expected = [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]
  assert_equal expected, Subset.for([1, 2, 3]).map(&:value)
  assert_equal expected, Subset.power_set([1, 2, 3])
end