-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestMonkeyTrouble.py
74 lines (60 loc) · 2.34 KB
/
TestMonkeyTrouble.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# AUTOGENERATED FILE -- RENAME OR YOUR EDITS WILL BE OVERWRITTEN
import unittest
actual_io_trace = '' # Receives test values print()'ed and input().
global_input = [] # Assigned in each test to provide input() values to the function under test.
# 3 functions unchanged from starter:
# print() is mocked to see if the tests recreate the .exem-specified i/o in actual_io_trace.
def print(line="") -> None:
global actual_io_trace
if line is str:
line = line.translate(str.maketrans({"'": r"\'"})) # Escape single quotes
actual_io_trace += ">" + str(line) + '\n'
# input() is mocked to return the test-specified input as well as add it to actual_io_trace.
def input(variable_name: str = "") -> str:
# (variable_name is ignored because it may not have been specified by the .exem.)
global actual_io_trace
result = global_input.pop(0)
result = result.translate(str.maketrans({"'": r"\'"})) # Escape single quotes
actual_io_trace += "<" + result + '\n' # Eg, '<Albert\n'
return result
# The generated function under Stage 2 (i.e., a test per example) testing.
def monkey_trouble():
a_smile = int(input("a_smile:")) # Eg, 1
b_smile = int(input("b_smile:")) # Eg, 1
if (a_smile and b_smile) or (not a_smile and not b_smile):
print('1')
return '1'
else: # == elif True:
print('0')
return '0'
class TestMonkeyTrouble(unittest.TestCase):
def setUp(self):
global actual_io_trace
actual_io_trace = ''
self.maxDiff = None
def test_monkey_trouble7(self):
global global_input
global_input = ['1', '1'] # From the .exem
monkey_trouble() # The function under test is used to write to actual_io_trace.
self.assertEqual('''<1
<1
>1
''', actual_io_trace)
def test_monkey_trouble14(self):
global global_input
global_input = ['0', '0'] # From the .exem
monkey_trouble() # The function under test is used to write to actual_io_trace.
self.assertEqual('''<0
<0
>1
''', actual_io_trace)
def test_monkey_trouble20(self):
global global_input
global_input = ['1', '0'] # From the .exem
monkey_trouble() # The function under test is used to write to actual_io_trace.
self.assertEqual('''<1
<0
>0
''', actual_io_trace)
if __name__ == '__main__':
unittest.main()