-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestPrimeNumber.py
98 lines (81 loc) · 3.09 KB
/
TestPrimeNumber.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# 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 prime_number():
inp = int(input("inp:")) # Eg, 0
if inp<=1:
print('False')
return 'False'
elif inp>1:
for j in range(2, 6, 1):
if j==inp:
print('True')
elif inp%j==0:
print('False')
break
class TestPrimeNumber(unittest.TestCase):
def setUp(self):
global actual_io_trace
actual_io_trace = ''
self.maxDiff = None
def test_prime_number3(self):
global global_input
global_input = ['1008'] # From the .exem
prime_number() # The function under test is used to write to actual_io_trace.
self.assertEqual('''<1008
>False
''', actual_io_trace)
def test_prime_number8(self):
global global_input
global_input = ['0'] # From the .exem
prime_number() # The function under test is used to write to actual_io_trace.
self.assertEqual('''<0
>False
''', actual_io_trace)
def test_prime_number13(self):
global global_input
global_input = ['1'] # From the .exem
prime_number() # The function under test is used to write to actual_io_trace.
self.assertEqual('''<1
>False
''', actual_io_trace)
def test_prime_number16(self):
global global_input
global_input = ['3'] # From the .exem
prime_number() # The function under test is used to write to actual_io_trace.
self.assertEqual('''<3
>True
''', actual_io_trace)
def test_prime_number23(self):
global global_input
global_input = ['4'] # From the .exem
prime_number() # The function under test is used to write to actual_io_trace.
self.assertEqual('''<4
>False
''', actual_io_trace)
def test_prime_number32(self):
global global_input
global_input = ['5'] # From the .exem
prime_number() # The function under test is used to write to actual_io_trace.
self.assertEqual('''<5
>True
''', actual_io_trace)
if __name__ == '__main__':
unittest.main()