1
exercism fetch python secret-handshake

secret_handshake_test.py

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
import unittest

from secret_handshake import handshake, secret_code


# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0

class HandshakeTest(unittest.TestCase):
    def test_wink_for_1(self):
        self.assertEqual(handshake(1), ['wink'])

    def test_double_blink_for_10(self):
        self.assertEqual(handshake(2), ['double blink'])

    def test_close_your_eyes_for_100(self):
        self.assertEqual(handshake(4), ['close your eyes'])

    def test_jump_for_1000(self):
        self.assertEqual(handshake(8), ['jump'])

    def test_combine_two_actions(self):
        self.assertEqual(handshake(3), ['wink', 'double blink'])

    def test_reverse_two_actions(self):
        self.assertEqual(handshake(19), ['double blink', 'wink'])

    def test_reversing_one_action_gives_the_same_action(self):
        self.assertEqual(handshake(24), ['jump'])

    def test_reversing_no_actions_still_gives_no_actions(self):
        self.assertEqual(handshake(16), [])

    def test_all_possible_actions(self):
        self.assertEqual(handshake(15), ['wink',
                                         'double blink',
                                         'close your eyes',
                                         'jump'])

    def test_reverse_all_possible_actions(self):
        self.assertEqual(handshake(31), ['jump',
                                         'close your eyes',
                                         'double blink',
                                         'wink'])

    def test_do_nothing_for_zero(self):
        self.assertEqual(handshake(0), [])

    # Track-specific tests

    @unittest.skip('extra-credit')
    def test_code1(self):
        self.assertEqual(secret_code(['close your eyes', 'jump']), 12)

    @unittest.skip('extra-credit')
    def test_code2(self):
        self.assertEqual(secret_code(['wink', 'double blink']), 3)

    @unittest.skip('extra-credit')
    def test_code3(self):
        self.assertEqual(secret_code(['jump', 'double blink']), 26)

    @unittest.skip('extra-credit')
    def test_reversible1(self):
        self.assertEqual(secret_code(handshake(27)), 27)

    @unittest.skip('extra-credit')
    def test_reversible2(self):
        self.assertEqual(secret_code(handshake(1)), 1)

    @unittest.skip('extra-credit')
    def test_reversible3(self):
        self.assertEqual(secret_code(handshake(7)), 7)

    @unittest.skip('extra-credit')
    def test_reversible4(self):
        inp = ['wink', 'double blink', 'jump']
        self.assertEqual(handshake(secret_code(inp)), inp)


if __name__ == '__main__':
    unittest.main()