Пример #1
0
    def test_assert_chain_missing_variable(self):
        with Execution('y=3\nprint(y)') as e:
            assert_has_variable(e.student, 'x')
            assert_type(evaluate('x'), int)
            assert_equal(evaluate('x'), 3)
        self.assertFeedback(
            e, """Failed Instructor Test
Student code failed instructor test.
I ran your code.
The variable x was not created.""")
Пример #2
0
    def test_assert_chain_incompatible_type(self):
        with Execution('x=3\nprint(x)') as e:
            assert_has_variable(e.student, 'x')
            assert_type(evaluate('x'), list)
            assert_equal(evaluate('set(x)'), {})
        self.assertFeedback(
            e, """Failed Instructor Test
Student code failed instructor test.
I evaluated the expression:
    x
The value of the result was:
    'a number'
But I expected the result to not be a value of type:
    'a list'""")
Пример #3
0
    def test_command_block(self):
        with Execution('''
class Fruit:
    def __init__(self, name, weight=0):
        self.name = name
        self.weight = weight
def do_math(a, b):
    return a + b - 5
def weigh_fruits(fruits):
    return sum(fruit.weight for fruit in fruits)    
                ''',
                       run_tifa=False) as e:

            with CommandBlock():
                orange = call("Fruit", "Orange", 30, target="orange")
                self.assertIsInstance(orange, e.student.data['Fruit'])
                pineapple = call("Fruit", "Pineapple", 60, target="pineapple")
                run("fruits = [orange, pineapple]")
                total_weight = call('weigh_fruits', args_locals=["fruits"])
                assert_equal(evaluate('pineapple.weight'), 61)
        self.assertFeedback(
            e, """Failed Instructor Test
Student code failed instructor test.
I ran the code:
    orange = Fruit('Orange', 30)
    pineapple = Fruit('Pineapple', 60)
    fruits = [orange, pineapple]
    weigh_fruits(fruits)
I evaluated the expression:
    pineapple.weight
The value of the result was:
    60
But I expected the result to be equal to:
    61""")
Пример #4
0
    def test_assert_type_fails_int(self):
        with Execution('x="3"\nprint(x)') as e:
            assert_type(evaluate('x'), int)
        self.assertFeedback(
            e, """Failed Instructor Test
Student code failed instructor test.
I evaluated the expression:
    x
The value of the result was:
    'a string'
But I expected the result to not be a value of type:
    'a number'""")
Пример #5
0
    def test_assert_equal_variable_fails_wrong_value(self):
        with Execution('x=3\nprint(x)') as e:
            assert_has_variable(e.student, 'x')
            assert_equal(evaluate('x'), 7)
        self.assertFeedback(
            e, """Failed Instructor Test
Student code failed instructor test.
I evaluated the expression:
    x
The value of the result was:
    3
But I expected the result to be equal to:
    7""")
Пример #6
0
 def test_assert_chain_passes(self):
     with Execution('x=3\nprint(x)') as e:
         assert_has_variable(e.student, 'x')
         assert_type(evaluate('x'), int)
         assert_equal(evaluate('x'), 3)
     self.assertFeedback(e, SUCCESS_MESSAGE)
Пример #7
0
 def test_assert_type_passes_int(self):
     with Execution('x=3\nprint(x)') as e:
         assert_type(evaluate('x'), int)
     self.assertFeedback(e, SUCCESS_MESSAGE)
Пример #8
0
 def test_int_requires_integer(self):
     contextualize_report("x = '5'")
     commands.run()
     x = int(commands.evaluate("x"))
     self.assertIsNone(commands.get_exception())
Пример #9
0
 def test_range_requires_integer(self):
     contextualize_report("x = 5")
     commands.run()
     x = commands.evaluate("x")
     range(x)
     self.assertIsNone(commands.get_exception())
Пример #10
0
with phase("introduction", score=1 / 10):
    assert_has_variable(student, "INTRODUCTION")
    assert_is_instance(student['INTRODUCTION'], str)
    assert_true(student['INTRODUCTION'])

with phase("make_world", before="make_world_components"):
    ensure_signature('make_world', 0, returns='World')
    assert_has_function(student, 'make_world')
    call('make_world', target='initial_world')
    assert_is_instance(student["initial_world"], student["World"])

with phase("make_world_components", after="win_and_lose_paths"):
    student.start_grouping_context()
    call('make_world', target="initial_world")
    assert_in("status", student['initial_world'])
    assert_equal(evaluate("initial_world['status']", target='status'),
                 'playing')
    student.stop_grouping_context()

with phase("make_world_components", after="win_and_lose_paths"):
    initial_world = student.call('make_world', target='world')


@phase("make_world_components", after="win_and_lose_paths")
def grade_make_world_map():
    initial_world = student.call('make_world', target='world')
    # Map
    assertIn('locations', initial_world)
    assertIsInstance(initial_world['locations'], dict)
    x = initial_world['locations'].keys()
    assertGreaterEqual(