"""Test Maths.""" from decimal import Decimal import math import pytest from video.utils import maths @pytest.mark.parametrize(('n', 'x', 'expected_return'), [ (0, 0, None), (0, 1, None), (1, 0, 0), (1, 1, 1), (2, 0, 0), (2, 2, 2), (2, 3, 4), (2, 4, 4), (2, 511, 512), (2, 512, 512), (2, 513, 512), (7, 2, 0), (7, 3.49, 0), (7, 3.5, 0), (7, 8, 7), (7, 13.123, 14), (2, 405, 404), ]) def test_find_multiple_of_n_nearest_x(n, x, expected_return): """Test find_multiple_of_n_nearest_x.""" assert expected_return == maths.find_multiple_of_n_nearest_x(n, x) @pytest.mark.parametrize( ('n1', 'n2', 'result'), [ (1, 2, 100), (2, 1, -50), (1, 0, -100), (0, 1, math.inf), (0.515, 15.5454, Decimal('2918.524271844660266198500751')), (33.2234, 3, Decimal('-90.97021978485043620890832615')), (-10, 10, 200), (10, -10, -200), (-10, -20, -100), (10, 10, 0), (-10, -10, 0), ] ) def test_percent_change(n1, n2, result): """Test percent_change.""" assert result == maths.percent_change(n1, n2) @pytest.mark.parametrize( ('x1', 'y1', 'x2', 'y2', 'expected_distance'), [ (0, 0, 1, 0, 1), (0, 0, 0, 1, 1), (0, 0, 1, 1, 1.4142135623730951), (1, 2, 3, 4, 2.8284271247461903), (-1, -2, -3, -4, 2.8284271247461903), (-1, 2, -3, 4, 2.8284271247461903), ] ) def test_euclidean_distance_2d(x1, y1, x2, y2, expected_distance): """Test euclidean_distance_2d.""" assert maths.euclidean_distance_2d(x1, y1, x2, y2) == expected_distance