interactive-coding-challenges/recursion_dynamic/hanoi/test_hanoi.py

41 lines
1009 B
Python
Raw Normal View History

from nose.tools import assert_equal, assert_raises
2015-07-03 11:03:04 +08:00
class TestHanoi(object):
2015-07-03 11:03:04 +08:00
def test_hanoi(self):
hanoi = Hanoi()
2015-07-03 11:03:04 +08:00
num_disks = 3
src = Stack()
buff = Stack()
dest = Stack()
print('Test: None towers')
assert_raises(TypeError, hanoi.move_disks, num_disks, None, None, None)
2015-07-03 11:03:04 +08:00
print('Test: 0 disks')
hanoi.move_disks(num_disks, src, dest, buff)
2015-07-03 11:03:04 +08:00
assert_equal(dest.pop(), None)
print('Test: 1 disk')
src.push(5)
hanoi.move_disks(num_disks, src, dest, buff)
2015-07-03 11:03:04 +08:00
assert_equal(dest.pop(), 5)
print('Test: 2 or more disks')
for disk_index in range(num_disks, -1, -1):
src.push(disk_index)
hanoi.move_disks(num_disks, src, dest, buff)
for disk_index in range(0, num_disks):
assert_equal(dest.pop(), disk_index)
2015-07-03 11:03:04 +08:00
print('Success: test_hanoi')
2015-07-12 03:39:59 +08:00
2015-07-03 11:03:04 +08:00
def main():
test = TestHanoi()
test.test_hanoi()
2015-07-12 03:39:59 +08:00
2015-07-03 11:03:04 +08:00
if __name__ == '__main__':
main()