Esempio n. 1
0
def test_Particle_speed_should_remain_constant():
    almost_eq = approximately_eq(13)
    assert_speed_unchanged = assert_evolution(lambda:abs(p.vel), almost_eq)
    p = Particle(30, 40, 50, 60, 70)
    for dt in xrange(10,30,1):
        p.move(dt/1000.0)
        assert_speed_unchanged()
def test_assert_evolution_should_fail_with_non_constant_expression_and_eq():
    assert_invariant = assert_evolution(lambda:x, eq)
    x = 1
    assert_invariant()
    assert_invariant()
    x = 2
    with raises(AssertionError):
        assert_invariant()
def test_assert_evolution_should_work_with_increasing_expression_and_gt():
    assert_increasing = assert_evolution(lambda:x, gt)
    for x in range(20):
        assert_increasing()

    x -= 2
    with raises(AssertionError):
        assert_increasing()
def test_assert_evolution_should_work_with_increasing_expression_and_gt():
    assert_increasing = assert_evolution(lambda: x, gt)
    for x in range(20):
        assert_increasing()

    x -= 2
    with raises(AssertionError):
        assert_increasing()
def test_assert_evolution_should_fail_with_non_constant_expression_and_eq():
    assert_invariant = assert_evolution(lambda: x, eq)
    x = 1
    assert_invariant()
    assert_invariant()
    x = 2
    with raises(AssertionError):
        assert_invariant()
def test_assert_evolution_should_work_with_constant_expression_and_eq():
    assert_invariant = assert_evolution(lambda:x, eq)
    for x in 'aaaaa':
        assert_invariant()
def test_assert_evolution_should_fail_with_constant_expression_and_gt():
    assert_increasing = assert_evolution(lambda:x, gt)
    x = 1
    assert_increasing()
    with raises(AssertionError):
        assert_increasing()
def test_assert_evolution_should_work_with_constant_expression_and_eq():
    assert_invariant = assert_evolution(lambda: x, eq)
    for x in 'aaaaa':
        assert_invariant()
def test_assert_evolution_should_fail_with_constant_expression_and_gt():
    assert_increasing = assert_evolution(lambda: x, gt)
    x = 1
    assert_increasing()
    with raises(AssertionError):
        assert_increasing()