76 lines
2.4 KiB
Python
76 lines
2.4 KiB
Python
import unittest
|
|
from matrixmania.compute import transpose # Anpassung an deine Paketstruktur
|
|
|
|
class TestTranspose(unittest.TestCase):
|
|
|
|
def test_square_matrix(self):
|
|
# Testfall: Standard 3x3 Quadratische Matrix
|
|
matrix = [
|
|
[1, 2, 3],
|
|
[4, 5, 6],
|
|
[7, 8, 9]
|
|
]
|
|
expected = [
|
|
[1, 4, 7],
|
|
[2, 5, 8],
|
|
[3, 6, 9]
|
|
]
|
|
self.assertEqual(transpose(matrix), expected, "Sollte quadratische Matrix korrekt transponieren")
|
|
|
|
def test_rectangular_matrix_2x3(self):
|
|
# Testfall: Rechteckige Matrix 2x3 -> 3x2
|
|
matrix = [
|
|
[10, 20, 30],
|
|
[40, 50, 60]
|
|
]
|
|
expected = [
|
|
[10, 40],
|
|
[20, 50],
|
|
[30, 60]
|
|
]
|
|
self.assertEqual(transpose(matrix), expected, "Sollte rechteckige 2x3 Matrix korrekt transponieren zu 3x2")
|
|
|
|
def test_rectangular_matrix_3x2(self):
|
|
# Testfall: Rechteckige Matrix 3x2 -> 2x3
|
|
matrix = [
|
|
[1, 2],
|
|
[3, 4],
|
|
[5, 6]
|
|
]
|
|
expected = [
|
|
[1, 3, 5],
|
|
[2, 4, 6]
|
|
]
|
|
self.assertEqual(transpose(matrix), expected, "Sollte rechteckige 3x2 Matrix korrekt transponieren zu 2x3")
|
|
|
|
def test_single_row(self):
|
|
# Testfall: Matrix mit nur einer Zeile (1xN)
|
|
matrix = [[1, 2, 3, 4]]
|
|
expected = [
|
|
[1],
|
|
[2],
|
|
[3],
|
|
[4]
|
|
]
|
|
self.assertEqual(transpose(matrix), expected, "Sollte eine 1xN Matrix zu einer Nx1 Matrix transponieren")
|
|
|
|
def test_empty_matrix_error(self):
|
|
# Testfall: Fehlerprüfung bei leerer Matrix
|
|
matrix = []
|
|
with self.assertRaises(ValueError) as context:
|
|
transpose(matrix)
|
|
self.assertTrue('matrix is empty' in str(context.exception), "Sollte ValueError bei leerer Matrix werfen")
|
|
|
|
def test_inconsistent_columns_error(self):
|
|
# Testfall: Fehlerprüfung bei ungleichmäßiger Spaltenanzahl (Ragged Matrix)
|
|
matrix = [
|
|
[1, 2, 3],
|
|
[4, 5], # Diese Zeile hat nur 2 Spalten
|
|
[7, 8, 9]
|
|
]
|
|
with self.assertRaises(ValueError) as context:
|
|
transpose(matrix)
|
|
self.assertTrue('Inconsistent number of columns' in str(context.exception), "Sollte ValueError bei ungleichmäßiger Spaltenanzahl werfen")
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main() |