-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_vector.py
More file actions
46 lines (28 loc) · 777 Bytes
/
test_vector.py
File metadata and controls
46 lines (28 loc) · 777 Bytes
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 11 11:46:34 2022
@author: hernando
"""
from vector import Vector
import random
#import pytest as pt
def inputs():
n = random.sample(range(2, 11), 1)[0]
a = [random.uniform(-1, 1) for i in range(n)]
b = [random.uniform(-1, 1) for i in range(n)]
return Vector(a), Vector(b)
def test_vector_add():
a, b = inputs()
null = 0 * a
assert a + b == b + a
assert a + null == null + a
assert a + (a + b) == (a + a) + b
return True
def test_vector_mul():
a, b = inputs()
assert 0 * a == 0 * a
assert 1 * a == a
alpha = b[1]
assert a * alpha == alpha * a
return True