Skip to content

Commit 7af3920

Browse files
committed
wiki examples
1 parent 19a30d4 commit 7af3920

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

tests/test_test_wiki.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,67 @@ def test_for_body():
186186
sct_payload = helper.run(self.data)
187187
self.assertTrue(sct_payload['correct'])
188188

189+
class TestPartChecks(unittest.TestCase):
190+
def test_pass_simple(self):
191+
self.data = {
192+
"DC_SOLUTION": '''
193+
L2 = [i*2 for i in range(0,10) if i>2]
194+
''',
195+
"DC_SCT": '''
196+
list_comp = Ex().check_list_comp(1, missing_msg="Did you include a list comprehension?")
197+
list_comp.check_body().test_student_typed('i\*2')
198+
list_comp.check_iter().has_equal_value()
199+
list_comp.check_ifs(1).multi([has_equal_value(context_vals=[i]) for i in range(0,10)])
200+
'''
201+
}
202+
self.data["DC_CODE"] = "L2 = [i*2 for i in range(10) if i>2]"
203+
sct_payload = helper.run(self.data)
204+
self.assertTrue(sct_payload['correct'])
205+
206+
def test_pass_complex1(self):
207+
self.data = {
208+
"DC_SOLUTION": """L3 = [i*2 if i> 5 else 0 for i in range(0,10)]""",
209+
"DC_SCT": """
210+
(Ex().check_list_comp(1) # first comptehension
211+
.check_body() # comp's body
212+
.set_context(i=6)
213+
.check_if_exp(1) # body's inline if
214+
.has_equal_value()
215+
)
216+
"""
217+
}
218+
self.data['DC_CODE'] = self.data['DC_SOLUTION']
219+
sct_payload = helper.run(self.data)
220+
self.assertTrue(sct_payload['correct'])
221+
222+
def test_fail_complex1(self):
223+
self.data = {
224+
"DC_SOLUTION": """L3 = [i*2 if i> 5 else 0 for i in range(0,10)]""",
225+
"DC_SCT": """
226+
(Ex().check_list_comp(1) # first comptehension
227+
.check_body() # comp's body
228+
.set_context(i=6)
229+
.check_if_exp(1) # body's inline if
230+
.has_equal_value()
231+
)
232+
"""
233+
}
234+
self.data['DC_CODE'] = """L3 = [i*2 for i in range(0,10)]""" # no inline if
235+
sct_payload = helper.run(self.data)
236+
self.assertFalse(sct_payload['correct'])
189237

238+
def test_pass_complex2(self):
239+
self.data = {
240+
"DC_SOLUTION": """L3 = [i*2 if i> 5 else 0 for i in range(0,10)]""",
241+
"DC_SCT": """
242+
(Ex().check_list_comp(1) # first comptehension
243+
.check_body().set_context(i=6).has_equal_value()
244+
)
245+
"""
246+
}
247+
self.data['DC_CODE'] = self.data['DC_SOLUTION']
248+
sct_payload = helper.run(self.data)
249+
self.assertTrue(sct_payload['correct'])
190250

191251
if __name__ == "__main__":
192252
unittest.main()

0 commit comments

Comments
 (0)