Last active
July 4, 2018 12:05
-
-
Save vadella/a31688f23f89eb0cd19727f799f35f5c to your computer and use it in GitHub Desktop.
some tests for my hanoi implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import chain | |
from my_hanoi import ( | |
pad_disk, | |
format_row, | |
buffer_peg, | |
pad_left_reverse, | |
solve_tower, | |
) | |
def test_solve(): | |
steps = tuple(solve_tower(2)) | |
assert steps == ( | |
((2, 1), (), ()), | |
((2,), (), (1,)), | |
((), (2,), (1,)), | |
((), (2, 1), ()), | |
) | |
def test_pad_disk(): | |
assert tuple(pad_disk(1, num_disks=4)) == (1, 1, 1, 0, 0, 1, 1, 1) | |
def test_row(): | |
row = [2, 0, 1] | |
num_disks = 4 | |
assert tuple(format_row(row, num_disks)) == tuple(chain( | |
buffer_peg(), | |
(1, 1, 0, 0, 0, 0, 1, 1,), | |
buffer_peg(), | |
(1, 1, 1, 1, 1, 1, 1, 1,), | |
buffer_peg(), | |
(1, 1, 1, 0, 0, 1, 1, 1,), | |
buffer_peg(), | |
)) | |
def test_left_pad(): | |
assert tuple(tuple(pad_left_reverse([2, 1], 5, 0))) == (0, 0, 0, 1, 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment