Skip to content

Commit

Permalink
Fixed Tests Issues nd Organized Test File UTSAVS26#21
Browse files Browse the repository at this point in the history
  • Loading branch information
SpreadSheets600 committed Oct 6, 2024
1 parent 8887a6a commit aa34c5a
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Tests/files/test_file_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import os
import unittest
from Snippets.Files.file_reader import read_file
from pysnippets.files.file_reader import read_file


class TestFileReader(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion Tests/maths/test_complex_number.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from snippets.complex_numbers import add_complex, multiply_complex
from pysnippets.maths.complex_number_operations import add_complex, multiply_complex

class TestComplexNumbers(unittest.TestCase):

Expand Down
10 changes: 5 additions & 5 deletions Tests/maths/test_matrix_operations.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import unittest
from snippets.matrix_operations import add_matrices, multiply_matrices, transpose_matrix
from pysnippets.maths.matrix_operations import matrix_multiplication, matrix_addition, matrix_transpose

class TestMatrixOperations(unittest.TestCase):

def test_add_matrices(self):
# Test case for normal behavior
self.assertEqual(add_matrices([[1, 2], [3, 4]], [[5, 6], [7, 8]]), [[6, 8], [10, 12]])
self.assertEqual(matrix_addition([[1, 2], [3, 4]], [[5, 6], [7, 8]]), [[6, 8], [10, 12]])

def test_multiply_matrices(self):
# Test case for normal behavior
self.assertEqual(multiply_matrices([[1, 2], [3, 4]], [[5, 6], [7, 8]]), [[19, 22], [43, 50]])
self.assertEqual(matrix_multiplication([[1, 2], [3, 4]], [[5, 6], [7, 8]]), [[19, 22], [43, 50]])

def test_transpose_matrix(self):
# Test case for normal behavior
self.assertEqual(transpose_matrix([[1, 2, 3], [4, 5, 6]]), [[1, 4], [2, 5], [3, 6]])
self.assertEqual(matrix_transpose([[1, 2, 3], [4, 5, 6]]), [[1, 4], [2, 5], [3, 6]])

def test_add_matrices_invalid(self):
# Test case for invalid input
with self.assertRaises(ValueError):
add_matrices([[1, 2]], [[3, 4], [5, 6]])
matrix_addition([[1, 2]], [[3, 4], [5, 6]])

if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion Tests/numbers/test_number_formatting.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# test_number_formatting.py

import unittest
from pysnippets.Numbers.number_formatting import format_number
from pysnippets.numbers.number_formatting import format_number


class TestNumberFormatting(unittest.TestCase):
Expand Down
3 changes: 2 additions & 1 deletion Tests/stats/test_data_distribution.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
from snippets.statistics import quantile, z_score_normalization
from pysnippets.stats.quantile import quantile
from pysnippets.stats.z_score_normalization import z_score_normalization

class TestDataDistribution(unittest.TestCase):

Expand Down
4 changes: 3 additions & 1 deletion Tests/stats/test_statistics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import unittest
from snippets.statistics import mean, median, mode, variance, standard_deviation
from pysnippets.stats.mean_median_mode import mean, median, mode
from pysnippets.stats.standard_deviation import standard_deviation
from pysnippets.stats.variance import variance

class TestStatistics(unittest.TestCase):

Expand Down
2 changes: 1 addition & 1 deletion Tests/strings/test_list_to_comma_string.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# test_list_to_comma_string.py

import unittest
from Snippets.Strings.list_to_comma_string import list_to_comma_string
from pysnippets.strings.list_to_comma_string import list_to_comma_string


class TestListToCommaString(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion Tests/strings/test_string_manipulation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# test_string_manipulation.py
import unittest
from string_manipulation import reverse_string, count_vowels, to_uppercase, to_lowercase, is_palindrome
from pysnippets.strings.string_manipulation import reverse_string, count_vowels, to_uppercase, to_lowercase, is_palindrome

class TestStringManipulation(unittest.TestCase):

Expand Down
4 changes: 2 additions & 2 deletions pysnippets/maths/mathematics.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Wellcome To PySnippet's Mathematics Module Section, This Section Contains The Do
- [Introduction](#introduction)
- [Matrix Operations](#matrix-operations)
- [Matrix Addition](#matrix-addition)
- [Matrix Multiplication](#matrix-multiplication)
- [Matrix Transpose](#matrix-transpose)
- [Matrix Multiplication](#matrix-multiplication)
- [Determinant](#determinant)
- [Determinant of a Matrix](#determinant-of-a-matrix)
- [Complex Numbers](#complex-numbers)
Expand Down Expand Up @@ -69,7 +69,7 @@ transpose(matrix)
- **Returns**: The transposed matrix.
- **Example**:
```python
>>> transpose([[1, 2], [3, 4]])
>>> matrix_transpose([[1, 2], [3, 4]])
[[1, 3], [2, 4]]
```

Expand Down
44 changes: 0 additions & 44 deletions pysnippets/maths/matrix_multiplication.py

This file was deleted.

99 changes: 99 additions & 0 deletions pysnippets/maths/matrix_operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# matrix_multiplication.py
def matrix_addition(A, B):
"""
Add two matrices A and B.
Args:
A (list of list of int/float): First matrix.
B (list of list of int/float): Second matrix.
Returns:
list of list of int/float: The resulting matrix after addition.
Raises:
ValueError: If the dimensions of the two matrices are not the same.
Example:
>>> A = [[1, 2], [3, 4]]
>>> B = [[5, 6], [7, 8]]
>>> add_matrices(A, B)
[[6, 8], [10, 12]]
"""
# Check if the dimensions of the two matrices are the same
if len(A) != len(B) or len(A[0]) != len(B[0]):
raise ValueError("The dimensions of the two matrices must be the same.")

# Initialize the result matrix with zeros
result = [[0 for _ in range(len(A[0]))] for _ in range(len(A))]

# Perform matrix addition
for i in range(len(A)):
for j in range(len(A[0])):
result[i][j] = A[i][j] + B[i][j]

return result

def matrix_multiplication(A, B):
"""
Multiply two matrices A and B.
Args:
A (list of list of int/float): First matrix.
B (list of list of int/float): Second matrix.
Returns:
list of list of int/float: The resulting matrix after multiplication.
Raises:
ValueError: If the number of columns in A does not match the number of rows in B.
Example:
>>> A = [[1, 2, 3], [4, 5, 6]]
>>> B = [[7, 8], [9, 10], [11, 12]]
>>> matrix_multiply(A, B)
[[58, 64], [139, 154]]
"""
# Check if the number of columns in A matches the number of rows in B
if len(A[0]) != len(B):
raise ValueError("Number of columns in A must match number of rows in B.")

# Initialize the result matrix with zeros
result = [[0 for _ in range(len(B[0]))] for _ in range(len(A))]

# Perform matrix multiplication
for i in range(len(A)):
for j in range(len(B[0])):
for k in range(len(B)):
result[i][j] += A[i][k] * B[k][j]

return result

def matrix_transpose(A):
"""
Transpose a matrix A.
Args:
A (list of list of int/float):
The matrix to be transposed.
Returns:
list of list of int/float:
The transposed matrix.
Example:
>>> A = [[1, 2, 3], [4, 5, 6]]
>>> transpose_matrix(A)
[[1, 4], [2, 5], [3, 6]]
"""
return [[A[j][i] for j in range(len(A))] for i in range(len(A[0]))]


# Example usage
if __name__ == "__main__":
# Example usage of the function
A = [[1, 2, 3], [4, 5, 6]]
B = [[7, 8], [9, 10], [11, 12]]
result = matrix_multiplication(A, B)
print(result)


0 comments on commit aa34c5a

Please sign in to comment.