2020-07-13 21:26:50 -04:00
|
|
|
import unittest
|
2015-07-02 23:03:04 -04:00
|
|
|
|
|
|
|
|
2020-07-13 21:26:50 -04:00
|
|
|
class TestHanoi(unittest.TestCase):
|
2015-07-06 05:44:06 -04:00
|
|
|
|
2015-07-02 23:03:04 -04:00
|
|
|
def test_hanoi(self):
|
2016-11-19 09:01:44 -05:00
|
|
|
hanoi = Hanoi()
|
2015-07-02 23:03:04 -04:00
|
|
|
num_disks = 3
|
|
|
|
src = Stack()
|
|
|
|
buff = Stack()
|
|
|
|
dest = Stack()
|
|
|
|
|
2015-07-06 05:44:06 -04:00
|
|
|
print('Test: None towers')
|
2020-07-13 21:26:50 -04:00
|
|
|
self.assertRaises(TypeError, hanoi.move_disks, num_disks, None, None, None)
|
2015-07-02 23:03:04 -04:00
|
|
|
|
|
|
|
print('Test: 0 disks')
|
2016-11-19 09:01:44 -05:00
|
|
|
hanoi.move_disks(num_disks, src, dest, buff)
|
2020-07-13 21:26:50 -04:00
|
|
|
self.assertEqual(dest.pop(), None)
|
2015-07-02 23:03:04 -04:00
|
|
|
|
|
|
|
print('Test: 1 disk')
|
|
|
|
src.push(5)
|
2016-11-19 09:01:44 -05:00
|
|
|
hanoi.move_disks(num_disks, src, dest, buff)
|
2020-07-13 21:26:50 -04:00
|
|
|
self.assertEqual(dest.pop(), 5)
|
2015-07-02 23:03:04 -04:00
|
|
|
|
|
|
|
print('Test: 2 or more disks')
|
2016-11-19 09:01:44 -05:00
|
|
|
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):
|
2020-07-13 21:26:50 -04:00
|
|
|
self.assertEqual(dest.pop(), disk_index)
|
2015-07-02 23:03:04 -04:00
|
|
|
|
|
|
|
print('Success: test_hanoi')
|
|
|
|
|
2015-07-11 15:39:59 -04:00
|
|
|
|
2015-07-02 23:03:04 -04:00
|
|
|
def main():
|
|
|
|
test = TestHanoi()
|
|
|
|
test.test_hanoi()
|
2015-07-06 05:44:06 -04:00
|
|
|
|
2015-07-11 15:39:59 -04:00
|
|
|
|
2015-07-02 23:03:04 -04:00
|
|
|
if __name__ == '__main__':
|
2020-07-13 21:26:50 -04:00
|
|
|
main()
|