From 2acccb9e0d4f34e2bb0432ee0ea9dd581defe67e Mon Sep 17 00:00:00 2001 From: Mazer1x Date: Fri, 3 Oct 2025 14:44:52 +0300 Subject: [PATCH 1/6] added 1 task --- .github/workflows/code_style.yml | 2 +- .github/workflows/mypy.yml | 29 +++++++ .github/workflows/tests.yml | 28 +++++++ project/Task1/__init__.py | 0 project/Task1/matrix_operations.py | 129 +++++++++++++++++++++++++++++ project/Task1/vector_operations.py | 119 ++++++++++++++++++++++++++ tests/Tests1/__init__.py | 0 tests/Tests1/matrix_tests.py | 97 ++++++++++++++++++++++ tests/Tests1/vector_tests.py | 45 ++++++++++ 9 files changed, 448 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/mypy.yml create mode 100644 .github/workflows/tests.yml create mode 100644 project/Task1/__init__.py create mode 100644 project/Task1/matrix_operations.py create mode 100644 project/Task1/vector_operations.py create mode 100644 tests/Tests1/__init__.py create mode 100644 tests/Tests1/matrix_tests.py create mode 100644 tests/Tests1/vector_tests.py diff --git a/.github/workflows/code_style.yml b/.github/workflows/code_style.yml index bd1ae279..d2060715 100644 --- a/.github/workflows/code_style.yml +++ b/.github/workflows/code_style.yml @@ -23,7 +23,7 @@ jobs: matrix: # Each option you define in the matrix has a key and value - python-version: [ 3.8 ] + python-version: [ 3.9 ] # Steps represent a sequence of tasks that will be executed as part of the job steps: diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml new file mode 100644 index 00000000..4f292bcc --- /dev/null +++ b/.github/workflows/mypy.yml @@ -0,0 +1,29 @@ +name: Types check with myPy + +on: [push, pull_request] + +jobs: + mypy: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.9] + + steps: + - name: Set up Git repository + uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip wheel setuptools + python -m pip install -r requirements.txt + python -m pip install mypy + + - name: Run MyPy + run: | + mypy project/ \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..a5fde444 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,28 @@ +name: Run Tests + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.9] + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest + + - name: Run tests + run: | + PYTHONPATH=project python -m pytest tests/Tests1/ -v \ No newline at end of file diff --git a/project/Task1/__init__.py b/project/Task1/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/project/Task1/matrix_operations.py b/project/Task1/matrix_operations.py new file mode 100644 index 00000000..2f7443c7 --- /dev/null +++ b/project/Task1/matrix_operations.py @@ -0,0 +1,129 @@ +def matrix_add(matrix1, matrix2): + """ + Add two matrices element-wise. + + Args: + matrix1 (list): First matrix as list of lists. + matrix2 (list): Second matrix as list of lists. + + Returns: + list: Resulting matrix after addition. + + Raises: + ValueError: If matrices have different dimensions. + """ + if len(matrix1) != len(matrix2) or len(matrix1[0]) != len(matrix2[0]): + raise ValueError("Matrices must have the same dimensions") + + return [ + [matrix1[i][j] + matrix2[i][j] for j in range(len(matrix1[0]))] + for i in range(len(matrix1)) + ] + + +def matrix_multiply(matrix1, matrix2): + """ + Multiply two matrices. + + Args: + matrix1 (list): First matrix. + matrix2 (list): Second matrix. + + Returns: + list: Resulting matrix after multiplication. + + Raises: + ValueError: If number of columns in first matrix doesn't match + number of rows in second matrix. + """ + if len(matrix1[0]) != len(matrix2): + raise ValueError( + "Number of columns in first matrix must equal " + "number of rows in second matrix" + ) + + result = [[0] * len(matrix2[0]) for _ in range(len(matrix1))] + for i in range(len(matrix1)): + for k in range(len(matrix2)): + for j in range(len(matrix2[0])): + result[i][j] += matrix1[i][k] * matrix2[k][j] + return result + + +def matrix_transpose(matrix): + """ + Transpose a matrix (swap rows and columns). + + Args: + matrix (list): Input matrix. + + Returns: + list: Transposed matrix. + """ + return [list(row) for row in zip(*matrix)] + + +class Matrix: + """ + A class representing a mathematical matrix. + + Attributes: + data (list): Matrix data as list of lists. + """ + + def __init__(self, data): + """ + Initialize a matrix with given data. + + Args: + data (list): Matrix data as list of lists. + + Raises: + ValueError: If rows have inconsistent lengths. + """ + if not all(len(row) == len(data[0]) for row in data): + raise ValueError("All rows must have the same length") + self.data = data + self.rows = len(data) + self.cols = len(data[0]) + + def add(self, other): + """ + Add another matrix to this matrix. + + Args: + other (Matrix): Another matrix. + + Returns: + Matrix: Result of addition. + """ + return Matrix(matrix_add(self.data, other.data)) + + def multiply(self, other): + """ + Multiply with another matrix. + + Args: + other (Matrix): Another matrix. + + Returns: + Matrix: Result of multiplication. + """ + return Matrix(matrix_multiply(self.data, other.data)) + + def transpose(self): + """ + Transpose the matrix. + + Returns: + Matrix: Transposed matrix. + """ + return Matrix(matrix_transpose(self.data)) + + def __repr__(self): + return f"Matrix({self.data})" + + def __eq__(self, other): + if not isinstance(other, Matrix): + return False + return self.data == other.data \ No newline at end of file diff --git a/project/Task1/vector_operations.py b/project/Task1/vector_operations.py new file mode 100644 index 00000000..c64bdc8a --- /dev/null +++ b/project/Task1/vector_operations.py @@ -0,0 +1,119 @@ +import math + +def dot_product(vector1, vector2): + """ + Calculate the dot product of two vectors. + + Args: + vector1 (list): First vector as a list of numbers. + vector2 (list): Second vector as a list of numbers. + + Returns: + float: Dot product of the two vectors. + + Raises: + ValueError: If vectors have different lengths. + """ + if len(vector1) != len(vector2): + raise ValueError("Vectors must have the same length") + return sum(v1 * v2 for v1, v2 in zip(vector1, vector2)) + + +def vector_length(vector): + """ + Calculate the Euclidean length (magnitude) of a vector. + + Args: + vector (list): Vector as a list of numbers. + + Returns: + float: Length of the vector. + """ + return math.sqrt(sum(x * x for x in vector)) + + +def angle_between(vector1, vector2): + """ + Calculate the angle between two vectors in radians. + + Args: + vector1 (list): First vector. + vector2 (list): Second vector. + + Returns: + float: Angle between vectors in radians. + + Raises: + ValueError: If either vector is a zero vector. + """ + dot = dot_product(vector1, vector2) + len1 = vector_length(vector1) + len2 = vector_length(vector2) + + if len1 == 0 or len2 == 0: + raise ValueError("Vectors cannot be zero vectors") + + # Ensure cosine value is within valid range to avoid floating point errors + cos_angle = dot / (len1 * len2) + cos_angle = max(min(cos_angle, 1.0), -1.0) + + return math.acos(cos_angle) + + +class Vector: + """ + A class representing a mathematical vector. + + Attributes: + components (list): The components of the vector. + """ + + def __init__(self, components): + """ + Initialize a vector with given components. + + Args: + components (list): List of numerical components. + """ + self.components = list(components) + + def dot(self, other): + """ + Calculate dot product with another vector. + + Args: + other (Vector): Another vector. + + Returns: + float: Dot product. + """ + return dot_product(self.components, other.components) + + def length(self): + """ + Calculate the length of the vector. + + Returns: + float: Vector length. + """ + return vector_length(self.components) + + def angle_with(self, other): + """ + Calculate angle with another vector. + + Args: + other (Vector): Another vector. + + Returns: + float: Angle in radians. + """ + return angle_between(self.components, other.components) + + def __repr__(self): + return f"Vector({self.components})" + + def __eq__(self, other): + if not isinstance(other, Vector): + return False + return self.components == other.components \ No newline at end of file diff --git a/tests/Tests1/__init__.py b/tests/Tests1/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/Tests1/matrix_tests.py b/tests/Tests1/matrix_tests.py new file mode 100644 index 00000000..ce048c80 --- /dev/null +++ b/tests/Tests1/matrix_tests.py @@ -0,0 +1,97 @@ +import pytest +import sys +import os + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../../')) +from project.Task1.matrix_operations import matrix_add, matrix_multiply, matrix_transpose, Matrix + +class TestMatrixOperations: + """Test cases for matrix operations.""" + + def test_matrix_add(self): + """Test matrix addition.""" + result = matrix_add([[1, 2], [3, 4]], [[5, 6], [7, 8]]) + assert result == [[6, 8], [10, 12]] + + def test_matrix_add_invalid_dimensions(self): + """Test matrix addition with invalid dimensions.""" + with pytest.raises(ValueError, match="Matrices must have the same dimensions"): + matrix_add([[1, 2]], [[3, 4, 5]]) + + def test_matrix_multiply(self): + """Test matrix multiplication.""" + result = matrix_multiply([[1, 2], [3, 4]], [[2, 0], [1, 2]]) + assert result == [[4, 4], [10, 8]] + + # Test identity matrix multiplication + identity = [[1, 0], [0, 1]] + matrix = [[1, 2], [3, 4]] + result = matrix_multiply(matrix, identity) + assert result == matrix + + def test_matrix_multiply_invalid_dimensions(self): + """Test matrix multiplication with invalid dimensions.""" + with pytest.raises(ValueError): + matrix_multiply([[1, 2]], [[3, 4, 5]]) + + def test_matrix_transpose(self): + """Test matrix transposition.""" + result = matrix_transpose([[1, 2, 3], [4, 5, 6]]) + assert result == [[1, 4], [2, 5], [3, 6]] + + # Test square matrix transpose + result = matrix_transpose([[1, 2], [3, 4]]) + assert result == [[1, 3], [2, 4]] + + +class TestMatrixClass: + """Test cases for Matrix class.""" + + def test_matrix_creation(self): + """Test Matrix object creation.""" + m = Matrix([[1, 2], [3, 4]]) + assert m.data == [[1, 2], [3, 4]] + assert m.rows == 2 + assert m.cols == 2 + + def test_matrix_creation_invalid(self): + """Test Matrix creation with invalid data.""" + with pytest.raises(ValueError, match="All rows must have the same length"): + Matrix([[1, 2], [3, 4, 5]]) + + def test_matrix_addition(self): + """Test matrix addition using Matrix class.""" + m1 = Matrix([[1, 2], [3, 4]]) + m2 = Matrix([[5, 6], [7, 8]]) + result = m1.add(m2) + expected = Matrix([[6, 8], [10, 12]]) + assert result == expected + + def test_matrix_multiplication(self): + """Test matrix multiplication using Matrix class.""" + m1 = Matrix([[1, 2], [3, 4]]) + m2 = Matrix([[2, 0], [1, 2]]) + result = m1.multiply(m2) + expected = Matrix([[4, 4], [10, 8]]) + assert result == expected + + def test_matrix_transpose_method(self): + """Test matrix transposition using Matrix class.""" + m = Matrix([[1, 2, 3], [4, 5, 6]]) + result = m.transpose() + expected = Matrix([[1, 4], [2, 5], [3, 6]]) + assert result == expected + + def test_matrix_repr(self): + """Test Matrix string representation.""" + m = Matrix([[1, 2], [3, 4]]) + assert repr(m) == "Matrix([[1, 2], [3, 4]])" + + def test_matrix_equality(self): + """Test Matrix equality comparison.""" + m1 = Matrix([[1, 2], [3, 4]]) + m2 = Matrix([[1, 2], [3, 4]]) + m3 = Matrix([[5, 6], [7, 8]]) + assert m1 == m2 + assert m1 != m3 + assert m1 != "not a matrix" \ No newline at end of file diff --git a/tests/Tests1/vector_tests.py b/tests/Tests1/vector_tests.py new file mode 100644 index 00000000..6146a53a --- /dev/null +++ b/tests/Tests1/vector_tests.py @@ -0,0 +1,45 @@ +import pytest +import math +import sys +import os + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../../')) +from project.Task1.vector_operations import dot_product, vector_length, angle_between, Vector + +class TestVectorOperations: + """Test cases for vector operations.""" + + def test_dot_product(self): + """Test dot product calculation.""" + assert dot_product([1, 2], [3, 4]) == 11 + assert dot_product([0, 0], [1, 2]) == 0 + + def test_dot_product_invalid_input(self): + """Test dot product with invalid inputs.""" + with pytest.raises(ValueError): + dot_product([1, 2], [1]) + + def test_vector_length(self): + """Test vector length calculation.""" + assert vector_length([3, 4]) == 5.0 + assert vector_length([0]) == 0.0 + + def test_angle_between(self): + """Test angle between vectors calculation.""" + assert math.isclose(angle_between([1, 0], [0, 1]), math.pi / 2) + assert angle_between([1, 0], [1, 0]) == 0.0 + + +class TestVectorClass: + """Test cases for Vector class.""" + + def test_vector_creation(self): + """Test Vector object creation.""" + v = Vector([1, 2, 3]) + assert v.components == [1, 2, 3] + + def test_vector_dot_product(self): + """Test dot product using Vector class.""" + v1 = Vector([1, 2]) + v2 = Vector([3, 4]) + assert v1.dot(v2) == 11 \ No newline at end of file From 05b91208b565e9702de317ecebfdb827f2f40b1d Mon Sep 17 00:00:00 2001 From: Mazer1x Date: Fri, 3 Oct 2025 14:50:57 +0300 Subject: [PATCH 2/6] fixed code with pre-commit --- .github/workflows/mypy.yml | 2 +- .github/workflows/tests.yml | 2 +- project/Task1/matrix_operations.py | 36 +++++++++++++-------------- project/Task1/vector_operations.py | 35 +++++++++++++------------- tests/Tests1/matrix_tests.py | 40 +++++++++++++++++------------- tests/Tests1/vector_tests.py | 24 +++++++++++------- 6 files changed, 76 insertions(+), 63 deletions(-) diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index 4f292bcc..a35e1609 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -26,4 +26,4 @@ jobs: - name: Run MyPy run: | - mypy project/ \ No newline at end of file + mypy project/ diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a5fde444..1feb408b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -25,4 +25,4 @@ jobs: - name: Run tests run: | - PYTHONPATH=project python -m pytest tests/Tests1/ -v \ No newline at end of file + PYTHONPATH=project python -m pytest tests/Tests1/ -v diff --git a/project/Task1/matrix_operations.py b/project/Task1/matrix_operations.py index 2f7443c7..2caccee0 100644 --- a/project/Task1/matrix_operations.py +++ b/project/Task1/matrix_operations.py @@ -14,7 +14,7 @@ def matrix_add(matrix1, matrix2): """ if len(matrix1) != len(matrix2) or len(matrix1[0]) != len(matrix2[0]): raise ValueError("Matrices must have the same dimensions") - + return [ [matrix1[i][j] + matrix2[i][j] for j in range(len(matrix1[0]))] for i in range(len(matrix1)) @@ -33,7 +33,7 @@ def matrix_multiply(matrix1, matrix2): list: Resulting matrix after multiplication. Raises: - ValueError: If number of columns in first matrix doesn't match + ValueError: If number of columns in first matrix doesn't match number of rows in second matrix. """ if len(matrix1[0]) != len(matrix2): @@ -41,7 +41,7 @@ def matrix_multiply(matrix1, matrix2): "Number of columns in first matrix must equal " "number of rows in second matrix" ) - + result = [[0] * len(matrix2[0]) for _ in range(len(matrix1))] for i in range(len(matrix1)): for k in range(len(matrix2)): @@ -66,18 +66,18 @@ def matrix_transpose(matrix): class Matrix: """ A class representing a mathematical matrix. - + Attributes: data (list): Matrix data as list of lists. """ - + def __init__(self, data): """ Initialize a matrix with given data. - + Args: data (list): Matrix data as list of lists. - + Raises: ValueError: If rows have inconsistent lengths. """ @@ -86,44 +86,44 @@ def __init__(self, data): self.data = data self.rows = len(data) self.cols = len(data[0]) - + def add(self, other): """ Add another matrix to this matrix. - + Args: other (Matrix): Another matrix. - + Returns: Matrix: Result of addition. """ return Matrix(matrix_add(self.data, other.data)) - + def multiply(self, other): """ Multiply with another matrix. - + Args: other (Matrix): Another matrix. - + Returns: Matrix: Result of multiplication. """ return Matrix(matrix_multiply(self.data, other.data)) - + def transpose(self): """ Transpose the matrix. - + Returns: Matrix: Transposed matrix. """ return Matrix(matrix_transpose(self.data)) - + def __repr__(self): return f"Matrix({self.data})" - + def __eq__(self, other): if not isinstance(other, Matrix): return False - return self.data == other.data \ No newline at end of file + return self.data == other.data diff --git a/project/Task1/vector_operations.py b/project/Task1/vector_operations.py index c64bdc8a..4b7e451b 100644 --- a/project/Task1/vector_operations.py +++ b/project/Task1/vector_operations.py @@ -1,5 +1,6 @@ import math + def dot_product(vector1, vector2): """ Calculate the dot product of two vectors. @@ -49,71 +50,71 @@ def angle_between(vector1, vector2): dot = dot_product(vector1, vector2) len1 = vector_length(vector1) len2 = vector_length(vector2) - + if len1 == 0 or len2 == 0: raise ValueError("Vectors cannot be zero vectors") - + # Ensure cosine value is within valid range to avoid floating point errors cos_angle = dot / (len1 * len2) cos_angle = max(min(cos_angle, 1.0), -1.0) - + return math.acos(cos_angle) class Vector: """ A class representing a mathematical vector. - + Attributes: components (list): The components of the vector. """ - + def __init__(self, components): """ Initialize a vector with given components. - + Args: components (list): List of numerical components. """ self.components = list(components) - + def dot(self, other): """ Calculate dot product with another vector. - + Args: other (Vector): Another vector. - + Returns: float: Dot product. """ return dot_product(self.components, other.components) - + def length(self): """ Calculate the length of the vector. - + Returns: float: Vector length. """ return vector_length(self.components) - + def angle_with(self, other): """ Calculate angle with another vector. - + Args: other (Vector): Another vector. - + Returns: float: Angle in radians. """ return angle_between(self.components, other.components) - + def __repr__(self): return f"Vector({self.components})" - + def __eq__(self, other): if not isinstance(other, Vector): return False - return self.components == other.components \ No newline at end of file + return self.components == other.components diff --git a/tests/Tests1/matrix_tests.py b/tests/Tests1/matrix_tests.py index ce048c80..fd246dd3 100644 --- a/tests/Tests1/matrix_tests.py +++ b/tests/Tests1/matrix_tests.py @@ -2,43 +2,49 @@ import sys import os -sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../../')) -from project.Task1.matrix_operations import matrix_add, matrix_multiply, matrix_transpose, Matrix +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../")) +from project.Task1.matrix_operations import ( + matrix_add, + matrix_multiply, + matrix_transpose, + Matrix, +) + class TestMatrixOperations: """Test cases for matrix operations.""" - + def test_matrix_add(self): """Test matrix addition.""" result = matrix_add([[1, 2], [3, 4]], [[5, 6], [7, 8]]) assert result == [[6, 8], [10, 12]] - + def test_matrix_add_invalid_dimensions(self): """Test matrix addition with invalid dimensions.""" with pytest.raises(ValueError, match="Matrices must have the same dimensions"): matrix_add([[1, 2]], [[3, 4, 5]]) - + def test_matrix_multiply(self): """Test matrix multiplication.""" result = matrix_multiply([[1, 2], [3, 4]], [[2, 0], [1, 2]]) assert result == [[4, 4], [10, 8]] - + # Test identity matrix multiplication identity = [[1, 0], [0, 1]] matrix = [[1, 2], [3, 4]] result = matrix_multiply(matrix, identity) assert result == matrix - + def test_matrix_multiply_invalid_dimensions(self): """Test matrix multiplication with invalid dimensions.""" with pytest.raises(ValueError): matrix_multiply([[1, 2]], [[3, 4, 5]]) - + def test_matrix_transpose(self): """Test matrix transposition.""" result = matrix_transpose([[1, 2, 3], [4, 5, 6]]) assert result == [[1, 4], [2, 5], [3, 6]] - + # Test square matrix transpose result = matrix_transpose([[1, 2], [3, 4]]) assert result == [[1, 3], [2, 4]] @@ -46,19 +52,19 @@ def test_matrix_transpose(self): class TestMatrixClass: """Test cases for Matrix class.""" - + def test_matrix_creation(self): """Test Matrix object creation.""" m = Matrix([[1, 2], [3, 4]]) assert m.data == [[1, 2], [3, 4]] assert m.rows == 2 assert m.cols == 2 - + def test_matrix_creation_invalid(self): """Test Matrix creation with invalid data.""" with pytest.raises(ValueError, match="All rows must have the same length"): Matrix([[1, 2], [3, 4, 5]]) - + def test_matrix_addition(self): """Test matrix addition using Matrix class.""" m1 = Matrix([[1, 2], [3, 4]]) @@ -66,7 +72,7 @@ def test_matrix_addition(self): result = m1.add(m2) expected = Matrix([[6, 8], [10, 12]]) assert result == expected - + def test_matrix_multiplication(self): """Test matrix multiplication using Matrix class.""" m1 = Matrix([[1, 2], [3, 4]]) @@ -74,19 +80,19 @@ def test_matrix_multiplication(self): result = m1.multiply(m2) expected = Matrix([[4, 4], [10, 8]]) assert result == expected - + def test_matrix_transpose_method(self): """Test matrix transposition using Matrix class.""" m = Matrix([[1, 2, 3], [4, 5, 6]]) result = m.transpose() expected = Matrix([[1, 4], [2, 5], [3, 6]]) assert result == expected - + def test_matrix_repr(self): """Test Matrix string representation.""" m = Matrix([[1, 2], [3, 4]]) assert repr(m) == "Matrix([[1, 2], [3, 4]])" - + def test_matrix_equality(self): """Test Matrix equality comparison.""" m1 = Matrix([[1, 2], [3, 4]]) @@ -94,4 +100,4 @@ def test_matrix_equality(self): m3 = Matrix([[5, 6], [7, 8]]) assert m1 == m2 assert m1 != m3 - assert m1 != "not a matrix" \ No newline at end of file + assert m1 != "not a matrix" diff --git a/tests/Tests1/vector_tests.py b/tests/Tests1/vector_tests.py index 6146a53a..211f055e 100644 --- a/tests/Tests1/vector_tests.py +++ b/tests/Tests1/vector_tests.py @@ -3,27 +3,33 @@ import sys import os -sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../../')) -from project.Task1.vector_operations import dot_product, vector_length, angle_between, Vector +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../")) +from project.Task1.vector_operations import ( + dot_product, + vector_length, + angle_between, + Vector, +) + class TestVectorOperations: """Test cases for vector operations.""" - + def test_dot_product(self): """Test dot product calculation.""" assert dot_product([1, 2], [3, 4]) == 11 assert dot_product([0, 0], [1, 2]) == 0 - + def test_dot_product_invalid_input(self): """Test dot product with invalid inputs.""" with pytest.raises(ValueError): dot_product([1, 2], [1]) - + def test_vector_length(self): """Test vector length calculation.""" assert vector_length([3, 4]) == 5.0 assert vector_length([0]) == 0.0 - + def test_angle_between(self): """Test angle between vectors calculation.""" assert math.isclose(angle_between([1, 0], [0, 1]), math.pi / 2) @@ -32,14 +38,14 @@ def test_angle_between(self): class TestVectorClass: """Test cases for Vector class.""" - + def test_vector_creation(self): """Test Vector object creation.""" v = Vector([1, 2, 3]) assert v.components == [1, 2, 3] - + def test_vector_dot_product(self): """Test dot product using Vector class.""" v1 = Vector([1, 2]) v2 = Vector([3, 4]) - assert v1.dot(v2) == 11 \ No newline at end of file + assert v1.dot(v2) == 11 From 1b1e2be07f6fa20e58b4d1720ae9ea6d8ac71f2e Mon Sep 17 00:00:00 2001 From: Mazer1x Date: Fri, 3 Oct 2025 14:54:36 +0300 Subject: [PATCH 3/6] fixed tests dir --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1feb408b..60668a43 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -25,4 +25,4 @@ jobs: - name: Run tests run: | - PYTHONPATH=project python -m pytest tests/Tests1/ -v + PYTHONPATH=project python -m pytest tests/Tests1/matrix_tests.py tests/Tests1/vector_tests.py -v From c79444fc26f00e058c16a4e77c46869fe15067ca Mon Sep 17 00:00:00 2001 From: Mazer1x Date: Fri, 3 Oct 2025 14:58:12 +0300 Subject: [PATCH 4/6] changed reqs.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 30544ac2..61500b18 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ black +mypy pre-commit pytest From f185e094afc0fda52a66b25a15ce348fbdc8ae42 Mon Sep 17 00:00:00 2001 From: Mazer1x Date: Fri, 3 Oct 2025 15:06:12 +0300 Subject: [PATCH 5/6] fixed tests --- .github/workflows/tests.yml | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 60668a43..181606d4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,28 +1,23 @@ -name: Run Tests +name: Run All Tests on: [push, pull_request] jobs: test: runs-on: ubuntu-latest - strategy: - matrix: - python-version: [3.9] - steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} + - name: Set up Python uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python-version }} + python-version: '3.9' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install pytest + - name: Install pytest + run: pip install pytest - - name: Run tests - run: | - PYTHONPATH=project python -m pytest tests/Tests1/matrix_tests.py tests/Tests1/vector_tests.py -v + - name: Run all tests + env: + PYTHONPATH: project + run: pytest tests/ -v From 0ac672e8efaa8497d7ba5fd6504b4618418fc256 Mon Sep 17 00:00:00 2001 From: Mazer1x Date: Fri, 3 Oct 2025 15:12:22 +0300 Subject: [PATCH 6/6] fixed tests --- .github/workflows/tests.yml | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 181606d4..21476aef 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,23 +1,17 @@ -name: Run All Tests - +name: Run Tests on: [push, pull_request] - jobs: test: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - - name: Set up Python uses: actions/setup-python@v4 with: - python-version: '3.9' - + python-version: '3.10' - name: Install pytest run: pip install pytest - - - name: Run all tests - env: - PYTHONPATH: project - run: pytest tests/ -v + - name: Run tests using project script + run: | + python ./scripts/run_tests.py