-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_vector_operations.py
81 lines (61 loc) · 2.62 KB
/
test_vector_operations.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# test_vector_operations.py
import numpy as np
import vector_operations
def test_vector_addition():
a = np.array([1, 2, 3], dtype=np.float64)
b = np.array([4, 5, 6], dtype=np.float64)
expected_result = np.array([5, 7, 9], dtype=np.float64)
result = vector_operations.vector_addition(a, b)
assert np.array_equal(result, expected_result), "Test failed."
def test_scalar_multiplication():
a = np.array([1, 2, 3], dtype=np.float64)
scalar = 2
expected_result = np.array([2, 4, 6], dtype=np.float64)
result = vector_operations.scalar_multiplication(a, scalar)
assert np.array_equal(result, expected_result), "Test failed."
def test_vector_multiplication():
a = np.array([1, 2, 3], dtype=np.float64)
b = np.array([4, 5, 6], dtype=np.float64)
expected_result = np.array([4, 10, 18], dtype=np.float64)
result = vector_operations.vector_multiplication(a, b)
assert np.array_equal(result, expected_result), "Test failed."
def test_dot_product():
a = np.array([1, 2, 3], dtype=np.float64)
b = np.array([4, 5, 6], dtype=np.float64)
expected_result = 32.0
result = vector_operations.dot_product(a, b)
assert result == expected_result, "Test failed."
def test_vector_subtraction():
a = np.array([4, 5, 6], dtype=np.float64)
b = np.array([1, 2, 3], dtype=np.float64)
expected_result = np.array([3, 3, 3], dtype=np.float64)
result = vector_operations.vector_subtraction(a, b)
assert np.array_equal(result, expected_result), "Test failed."
def test_vector_division():
a = np.array([4, 6, 8], dtype=np.float64)
b = np.array([2, 3, 4], dtype=np.float64)
expected_result = np.array([2, 2, 2], dtype=np.float64)
result = vector_operations.vector_division(a, b)
assert np.array_equal(result, expected_result), "Test failed."
def test_scalar_component():
a = np.array([1, 2, 3], dtype=np.float64)
b = np.array([4, 5, 6], dtype=np.float64)
expected_result = np.array([8, 10, 12], dtype=np.float64)
result = vector_operations.scalar_component(a, b)
assert np.array_equal(result, expected_result), "Test failed."
def test_cross_product():
a = np.array([1, 0, 0], dtype=np.float64)
b = np.array([0, 1, 0], dtype=np.float64)
expected_result = np.array([0, 0, 1], dtype=np.float64)
result = vector_operations.cross_product(a, b)
assert np.array_equal(result, expected_result), "Test failed."
# Run the tests
test_vector_addition()
test_scalar_multiplication()
test_vector_multiplication()
test_dot_product()
test_vector_subtraction()
test_vector_division()
#test_scalar_component()
test_cross_product()
print("All tests passed.")