-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestLeapYear.py
129 lines (108 loc) · 4.05 KB
/
TestLeapYear.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# 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 leap_year():
i1 = int(input("i1:")) # Eg, 399
if i1%400==0:
print('True')
return 'True'
elif i1%4==0 and i1%100!=0:
print('True')
return 'True'
else: # == elif True:
print('False')
return 'False'
class TestLeapYear(unittest.TestCase):
def setUp(self):
global actual_io_trace
actual_io_trace = ''
self.maxDiff = None
def test_leap_year4(self):
global global_input
global_input = ['399'] # From the .exem
leap_year() # The function under test is used to write to actual_io_trace.
self.assertEqual('''<399
>False
''', actual_io_trace)
def test_leap_year8(self):
global global_input
global_input = ['400'] # From the .exem
leap_year() # The function under test is used to write to actual_io_trace.
self.assertEqual('''<400
>True
''', actual_io_trace)
def test_leap_year12(self):
global global_input
global_input = ['2012'] # From the .exem
leap_year() # The function under test is used to write to actual_io_trace.
self.assertEqual('''<2012
>True
''', actual_io_trace)
def test_leap_year16(self):
global global_input
global_input = ['2000'] # From the .exem
leap_year() # The function under test is used to write to actual_io_trace.
self.assertEqual('''<2000
>True
''', actual_io_trace)
def test_leap_year20(self):
global global_input
global_input = ['2013'] # From the .exem
leap_year() # The function under test is used to write to actual_io_trace.
self.assertEqual('''<2013
>False
''', actual_io_trace)
def test_leap_year24(self):
global global_input
global_input = ['2014'] # From the .exem
leap_year() # The function under test is used to write to actual_io_trace.
self.assertEqual('''<2014
>False
''', actual_io_trace)
def test_leap_year28(self):
global global_input
global_input = ['2015'] # From the .exem
leap_year() # The function under test is used to write to actual_io_trace.
self.assertEqual('''<2015
>False
''', actual_io_trace)
def test_leap_year32(self):
global global_input
global_input = ['2016'] # From the .exem
leap_year() # The function under test is used to write to actual_io_trace.
self.assertEqual('''<2016
>True
''', actual_io_trace)
def test_leap_year35(self):
global global_input
global_input = ['2020'] # From the .exem
leap_year() # The function under test is used to write to actual_io_trace.
self.assertEqual('''<2020
>True
''', actual_io_trace)
def test_leap_year37(self):
global global_input
global_input = ['2400'] # From the .exem
leap_year() # The function under test is used to write to actual_io_trace.
self.assertEqual('''<2400
>True
''', actual_io_trace)
if __name__ == '__main__':
unittest.main()