forked from thought-works/BootCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchance_not_test.rb
More file actions
46 lines (36 loc) · 1.31 KB
/
chance_not_test.rb
File metadata and controls
46 lines (36 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
$LOAD_PATH << File.dirname(__FILE__)
require 'chance_not'
require 'test/unit'
class ChanceTest < Test::Unit::TestCase
def test_calculate_not_chance
assert ChanceNot.new(0.5) == ChanceNot.new(0.5).not_chance
assert ChanceNot.new(0.25) == ChanceNot.new(0.75).not_chance
assert ChanceNot.new(0.75) == ChanceNot.new(0.25).not_chance
end
def test_calculate_chance
assert_equal 50, ChanceNot.new(0.5).get_chance
assert_equal 25, ChanceNot.new(0.25).get_chance
end
def test_compare_chances
assert_equal ChanceNot.new(0.5), ChanceNot.new(0.5)
assert_equal ChanceNot.new(0.25), ChanceNot.new(0.25)
assert_not_equal ChanceNot.new(0.5), ChanceNot.new(0.4)
assert_not_equal ChanceNot.new(0.1), ChanceNot.new(0.5)
end
def test_compare_different_types
assert_not_equal ChanceNot.new(0.5), nil
assert_not_equal ChanceNot.new(0.25), "0.25"
end
def test_add_chances
assert_equal ChanceNot.new(0.24), (ChanceNot.new(0.40) & ChanceNot.new(0.60))
end
def test_or_chances_mutually_exclusive
assert_equal ChanceNot.new(0.50), (ChanceNot.new(0.25) + ChanceNot.new(0.25))
end
def test_or_chances
assert_equal ChanceNot.new(0.75), (ChanceNot.new(0.50) | ChanceNot.new(0.50))
end
def test_subtract_chances
assert_equal ChanceNot.new(0.25), (ChanceNot.new(0.5) - ChanceNot.new(0.25))
end
end