コード例 #1
0
def test_problem1_7_scalar(xs, n, expected):
    v = Vector(*xs)
    assert v * n == Vector(*expected)
コード例 #2
0
def test_problem1_6(xs, ys, expected):
    u, v = Vector(*xs), Vector(*ys)
    assert u - v == Vector(*expected)
コード例 #3
0
def test_problem1_6_invalid():
    u, v = Vector(1, 2), Vector(1, 2, 3)
    with pytest.raises(ValueError):
        w = u - v
コード例 #4
0
def test_problem1_4(xs, expected):
    v = Vector(*xs)
    assert -v == Vector(*expected)
    assert -(-v) == Vector(*xs)
コード例 #5
0
def test_problem1_1(n):
    v = Vector(*list(range(n)))
コード例 #6
0
def test_problem1_2(xs, expected):
    v = Vector(*xs)
    assert str(v) == expected
コード例 #7
0
def test_problem1_3(n):
    v = Vector(*list(range(n)))
    assert len(v) == n
コード例 #8
0
def test_problem1_8_invalid():
    u, v = Vector(1, 2), Vector(1, 2, 3)
    with pytest.raises(TypeError):
        w = u / v
    with pytest.raises(TypeError):
        w = u // v
コード例 #9
0
def test_problem1_8_floordiv(xs, n, expected):
    v = Vector(*xs)
    assert v // n == Vector(*expected)
コード例 #10
0
def test_problem1_8_truediv(xs, n, expected):
    v = Vector(*xs)
    assert v / n == Vector(*expected)
コード例 #11
0
def test_problem1_7_dot_product(xs, ys, expected):
    u, v = Vector(*xs), Vector(*ys)
    assert u * v == expected
コード例 #12
0
def test_problem1_1_invalid():
    with pytest.raises(ValueError):
        v = Vector()
    with pytest.raises(ValueError):
        v = Vector(1)