Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

secret handshake: sync with canonical data #1813

Merged
merged 2 commits into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions exercises/secret-handshake/example.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
gestures = ['wink', 'double blink', 'close your eyes', 'jump']


def handshake(code):
def commands(number):
actions = [gestures[i] for i in range(len(gestures))
if (code >> i) % 2 == 1]
return actions if code < 16 else list(reversed(actions))
if (number >> i) % 2 == 1]
return actions if number < 16 else list(reversed(actions))


def secret_code(actions):
Expand Down
2 changes: 1 addition & 1 deletion exercises/secret-handshake/secret_handshake.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def handshake(code):
def commands(number):
pass


Expand Down
44 changes: 22 additions & 22 deletions exercises/secret-handshake/secret_handshake_test.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
import unittest

from secret_handshake import handshake, secret_code
from secret_handshake import commands, secret_code


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

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

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

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

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

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

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

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

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

def test_all_possible_actions(self):
self.assertEqual(handshake(15), ['wink',
'double blink',
'close your eyes',
'jump'])
self.assertEqual(commands(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'])
self.assertEqual(commands(31), ['jump',
'close your eyes',
'double blink',
'wink'])

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

# Track-specific tests

Expand All @@ -61,20 +61,20 @@ def test_code3(self):

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

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

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

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


if __name__ == '__main__':
Expand Down