forked from datacamp/pythonwhat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_test_correct.py
More file actions
75 lines (60 loc) · 2.78 KB
/
test_test_correct.py
File metadata and controls
75 lines (60 loc) · 2.78 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
69
70
71
72
73
74
75
import unittest
import helper
class TestExercise1(unittest.TestCase):
def setUp(self):
self.data = {
"DC_PEC": 'import numpy as np',
"DC_SCT": "test_correct(lambda: test_object('test'), lambda: test_function('numpy.sum'))",
"DC_SOLUTION": 'test = np.sum([5, 2, 4, 9])'
}
def test_Pass1(self):
self.data["DC_CODE"] = 'test = np.sum([5, 2, 4, 9])'
sct_payload = helper.run(self.data)
self.assertTrue(sct_payload['correct'])
def test_Pass2(self):
self.data["DC_CODE"] = 'test = np.sum([5, 3, 3, 9])'
sct_payload = helper.run(self.data)
self.assertTrue(sct_payload['correct'])
def test_Pass3(self):
self.data["DC_CODE"] = 'test = np.sum([5, 2, 4, 4, 5])'
sct_payload = helper.run(self.data)
self.assertTrue(sct_payload['correct'])
def test_Fail1(self):
self.data["DC_CODE"] = 'test = 19'
sct_payload = helper.run(self.data)
self.assertFalse(sct_payload['correct'])
self.assertEqual(sct_payload['message'], "Have you called <code>np.sum()</code>?")
def test_Fail2(self):
self.data["DC_CODE"] = 'test = np.sum([5, 2, 3])'
sct_payload = helper.run(self.data)
self.assertFalse(sct_payload['correct'])
self.assertEqual(sct_payload['message'], 'Did you call <code>np.sum()</code> with the correct arguments? The first argument seems to be incorrect.')
def test_Fail3(self):
self.data["DC_SCT"] = "test_correct(lambda: test_object('test'), lambda: test_function('numpy.sum', args=[]))"
self.data["DC_CODE"] = 'test = np.sum([5, 2, 3])'
sct_payload = helper.run(self.data)
self.assertFalse(sct_payload['correct'])
self.assertEqual(sct_payload['message'], 'The contents of <code>test</code> aren\'t correct.')
def test_Fail2_no_lam(self):
self.data["DC_SCT"] = helper.remove_lambdas(self.data["DC_SCT"])
self.test_Fail2()
def test_Pass2_no_lam(self):
self.data["DC_SCT"] = helper.remove_lambdas(self.data["DC_SCT"])
self.test_Pass2()
def test_Pass2_spec2(self):
self.data["DC_SCT"] = "Ex().test_correct(check_object('test').has_equal_value(), test_function('numpy.sum'))"
self.test_Pass2()
def test_Pass2_spec2_F(self):
self.data["DC_SCT"] = """
test = F().test_correct(check_object('test').has_equal_value(), test_function('numpy.sum'))
Ex().multi(test)
"""
self.test_Pass2()
def test_Fail2_mix_lam(self):
self.data["DC_SCT"] = helper.remove_lambdas(self.data["DC_SCT"], count=1)
self.test_Fail2()
def test_Pass2_mix_lam(self):
self.data["DC_SCT"] = helper.remove_lambdas(self.data["DC_SCT"], count=1)
self.test_Pass2()
if __name__ == "__main__":
unittest.main()