-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass_test.rb
104 lines (84 loc) · 1.99 KB
/
class_test.rb
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
require "test/unit"
require "tower_of_hanoi"
class ClassTest < Test::Unit::TestCase
def setup
@tower = ::TowerOfHanoi.new
end
def teardown
end
def test_initially_empty_rods
check_rods([], [], [])
end
def test_rods_setup
@tower.setup 4
assert_equal(4, @tower.get_rod(1).size, 'Should have 4 items')
assert_equal(0, @tower.get_rod(2).size)
assert_equal(0, @tower.get_rod(3).size)
end
def test_rod1_initialized_with_weights
@tower.setup 4
assert_equal([4,3,2,1], @tower.get_rod(1))
end
def test_can_move_disc
setup_rods [3, 2, 1], [], []
from_rod = 1
to_rod = 2
@tower.move(from_rod, to_rod)
check_rods [3, 2], [1], []
end
def test_can_not_move_from_heavy_to_light
setup_rods [], [3], [2]
assert(@tower.can_move?(2, 3) == false)
end
def test_can_move_from_light_to_heavy
setup_rods [], [3], [2]
assert(@tower.can_move?(3, 2))
end
def test_can_not_move_from_empty_to_any
setup_rods [], [3], [2]
assert(@tower.can_move?(1, 2) == false)
end
def test_can_move_to_empty
setup_rods [], [3], [2]
assert(@tower.can_move?(2, 1))
end
def test_validate_index
assert_raises RuntimeError do
@tower.get_rod 0
end
end
def test_if_can_move_to_2_and_3_move_3
setup_rods [3, 2, 1], [], []
@tower.step
check_rods [3, 2], [], [1]
end
def test_initial_goal_odd
@tower.setup 3
assert(@tower.goal(1) == 3)
assert(@tower.goal(2) == 2)
end
def test_initial_goal_even
@tower.setup 4
assert(@tower.goal(1) == 2)
assert(@tower.goal(2) == 3)
end
def test_amount
@tower.setup 9
assert(@tower.amount == 9)
end
def test_amount_with_setup
setup_rods([2,1],[],[3])
assert_equal 3, @tower.amount
end
private
def check_rods rod_1_val, rod_2_val, rod_3_val
assert_equal(rod_1_val, @tower.get_rod(1))
assert_equal(rod_2_val, @tower.get_rod(2))
assert_equal(rod_3_val, @tower.get_rod(3))
end
def setup_rods rod_1_val, rod_2_val, rod_3_val
@tower.set_rod(1, rod_1_val)
@tower.set_rod(2, rod_2_val)
@tower.set_rod(3, rod_3_val)
end
end