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

from secret_handshake import handshake, code


class HandshakeTest(unittest.TestCase):
    def test_shake_int(self):
        self.assertEqual(handshake(9), ['wink', 'jump'])

    def test_shake_bin1(self):
        self.assertEqual(
            handshake('10110'), ['close your eyes', 'double blink'])

    def test_shake_bin2(self):
        self.assertEqual(handshake('101'), ['wink', 'close your eyes'])

    def test_shake_negative_int(self):
        self.assertEqual(handshake(-9), [])

    def test_shake_bin_invalid(self):
        self.assertEqual(handshake('121'), [])

    def test_unknown_action(self):
        self.assertEqual(code(['wink', 'sneeze']), '0')

    def test_code1(self):
        self.assertEqual(code(['close your eyes', 'jump']), '1100')

    def test_code2(self):
        self.assertEqual(code(['wink', 'double blink']), '11')

    def test_code3(self):
        self.assertEqual(code(['jump', 'double blink']), '11010')

    def test_composition1(self):
        self.assertEqual(code(handshake(27)), '11011')

    def test_composition2(self):
        self.assertEqual(code(handshake(1)), '1')

    def test_composition3(self):
        self.assertEqual(code(handshake('111')), '111')

    def test_composition4(self):
        inp = ['wink', 'double blink', 'jump']
        self.assertEqual(handshake(code(inp)), inp)


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