|
| 1 | +import numpy as np |
| 2 | +import pytest |
| 3 | + |
| 4 | +from diffpy.morph import functions # noqa |
| 5 | + |
| 6 | + |
| 7 | +def test_dot_product_2D_list(): |
| 8 | + a = [1, 2] |
| 9 | + b = [3, 4] |
| 10 | + expected = 11.0 |
| 11 | + actual = functions.dot_product(a, b) |
| 12 | + assert actual == expected |
| 13 | + |
| 14 | + |
| 15 | +def test_dot_product_3D_list(): |
| 16 | + a = [1, 2, 3] |
| 17 | + b = [4, 5, 6] |
| 18 | + expected = 32.0 |
| 19 | + actual = functions.dot_product(a, b) |
| 20 | + assert actual == expected |
| 21 | + |
| 22 | + |
| 23 | +@pytest.mark.parametrize( |
| 24 | + "a, b, expected", |
| 25 | + [ |
| 26 | + # Test whether the dot product function works with 2D and 3D vectors |
| 27 | + # C1: lists, expect correct float output |
| 28 | + ([1, 2], [3, 4], 11.0), |
| 29 | + ([1, 2, 3], [4, 5, 6], 32.0), |
| 30 | + # C2: tuples, expect correct float output |
| 31 | + ((1, 2), (3, 4), 11.0), |
| 32 | + ((1, 2, 3), (4, 5, 6), 32.0), |
| 33 | + # C3: numpy arrays, expect correct float output |
| 34 | + (np.array([1, 2]), np.array([3, 4]), 11.0), |
| 35 | + (np.array([1, 2, 3]), np.array([4, 5, 6]), 32.0), |
| 36 | + ], |
| 37 | +) |
| 38 | +def test_dot_product(a, b, expected): |
| 39 | + actual = functions.dot_product(a, b) |
| 40 | + assert actual == expected |
0 commit comments