From e3f9f587b9b6d05efb1a2769a4cd75fb4855b4f9 Mon Sep 17 00:00:00 2001 From: Seongju Peter Park Date: Tue, 1 Nov 2016 14:30:07 -0400 Subject: [PATCH] Add coin module (#106) * Added new module and test file for coinflip feature. (src/coinflip.py and tests/test_coinflip.py) * Fixed the typo error in test_coinflip.py * actually fixed the parenthesis error this time. * Changed module name to 'coinflip'. Cleaned up code. Fixed error in test. --- modules/src/__init__.py | 1 + modules/src/coin.py | 12 ++++++++++++ modules/tests/test_coin.py | 7 +++++++ 3 files changed, 20 insertions(+) create mode 100644 modules/src/coin.py create mode 100644 modules/tests/test_coin.py diff --git a/modules/src/__init__.py b/modules/src/__init__.py index e47d4310..526dca5d 100644 --- a/modules/src/__init__.py +++ b/modules/src/__init__.py @@ -2,6 +2,7 @@ 'anime', 'book', 'bye', + 'coin', 'currency', 'dictionary', 'fact', diff --git a/modules/src/coin.py b/modules/src/coin.py new file mode 100644 index 00000000..cdf83dc9 --- /dev/null +++ b/modules/src/coin.py @@ -0,0 +1,12 @@ +import random +from templates.text import TextTemplate + +def process(input, entities): + output = {} + output['input'] = input + if random.randrange(0,2,1): + output['output'] = TextTemplate("Sure, it's heads!").get_message() + else: + output['output'] = TextTemplate("Sure, it's tails!").get_message() + output['success'] = True + return output diff --git a/modules/tests/test_coin.py b/modules/tests/test_coin.py new file mode 100644 index 00000000..186502fc --- /dev/null +++ b/modules/tests/test_coin.py @@ -0,0 +1,7 @@ +import modules + +def test_coinflip(): + assert('coin' == modules.process_query('Flip a coin')[0]) + assert('coin' == modules.process_query('Jarvis flip a coin')[0]) + assert('coin' == modules.process_query('Can you flip a coin')[0]) + assert('coin' != modules.process_query('something random')[0])