Skip to content

Commit

Permalink
Add coin module (#106)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
seongju authored and swapagarwal committed Nov 1, 2016
1 parent 5128bf1 commit e3f9f58
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'anime',
'book',
'bye',
'coin',
'currency',
'dictionary',
'fact',
Expand Down
12 changes: 12 additions & 0 deletions modules/src/coin.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions modules/tests/test_coin.py
Original file line number Diff line number Diff line change
@@ -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])

0 comments on commit e3f9f58

Please sign in to comment.