Skip to content

Commit e3f9f58

Browse files
seongjuswapagarwal
authored andcommitted
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.
1 parent 5128bf1 commit e3f9f58

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

modules/src/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
'anime',
33
'book',
44
'bye',
5+
'coin',
56
'currency',
67
'dictionary',
78
'fact',

modules/src/coin.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import random
2+
from templates.text import TextTemplate
3+
4+
def process(input, entities):
5+
output = {}
6+
output['input'] = input
7+
if random.randrange(0,2,1):
8+
output['output'] = TextTemplate("Sure, it's heads!").get_message()
9+
else:
10+
output['output'] = TextTemplate("Sure, it's tails!").get_message()
11+
output['success'] = True
12+
return output

modules/tests/test_coin.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import modules
2+
3+
def test_coinflip():
4+
assert('coin' == modules.process_query('Flip a coin')[0])
5+
assert('coin' == modules.process_query('Jarvis flip a coin')[0])
6+
assert('coin' == modules.process_query('Can you flip a coin')[0])
7+
assert('coin' != modules.process_query('something random')[0])

0 commit comments

Comments
 (0)