forked from datacamp/pythonwhat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_test_while_loop.py
More file actions
68 lines (58 loc) · 2.06 KB
/
test_test_while_loop.py
File metadata and controls
68 lines (58 loc) · 2.06 KB
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
import unittest
import helper
class TestWhileLoop(unittest.TestCase):
def setUp(self):
self.data = {
"DC_PEC": '',
"DC_SOLUTION": '''
offset = 8
while offset != 0 :
offset = offset - 1
''',
"DC_SCT": '''
for i in range(-1,2):
test_while_loop(1, test=lambda i=i: test_expression_result({"offset": i}))
for i in range(3,4):
test_while_loop(1, body=lambda i=i: test_object_after_expression("offset", {"offset": i}))
success_msg("Great!")
'''
}
def test_Pass(self):
self.data["DC_CODE"] = '''
offset = 8
while offset != 0 :
offset = offset - 1
'''
sct_payload = helper.run(self.data)
self.assertTrue(sct_payload['correct'])
self.assertEqual(sct_payload['message'], "Great!")
def test_Fail(self):
self.data["DC_CODE"] = '''
offset = 8
while offset != 4 :
offset = offset - 1
'''
sct_payload = helper.run(self.data)
self.assertFalse(sct_payload['correct'])
self.assertIn("Check your code in the condition of the first while loop", sct_payload['message'])
self.assertIn("Unexpected expression", sct_payload['message'])
helper.test_lines(self, sct_payload, 3, 3, 7, 17)
def test_Fail2(self):
self.data["DC_CODE"] = '''
offset = 8
while offset != 0 :
offset = offset - 2
'''
sct_payload = helper.run(self.data)
self.assertFalse(sct_payload['correct'])
self.assertIn("Check your code in the body of the first while loop", sct_payload['message'])
self.assertIn("Are you sure you assigned the correct value to <code>offset</code>", sct_payload['message'])
helper.test_lines(self, sct_payload, 4, 4, 5, 23)
def test_Pass_no_lam(self):
self.data["DC_SCT"] = helper.remove_lambdas(self.data["DC_SCT"], with_args=True)
self.test_Pass()
def test_Fail2_no_lam(self):
self.data["DC_SCT"] = helper.remove_lambdas(self.data["DC_SCT"], with_args=True)
self.test_Fail2()
if __name__ == "__main__":
unittest.main()