import pytest from matrixmania.compute import matmul, transpose # --- Tests für Transponieren --- def test_transpose_regular(): # Testet eine normale 2x3 Matrix matrix = [ [1, 2, 3], [4, 5, 6] ] expected = [ [1, 4], [2, 5], [3, 6] ] assert transpose(matrix) == expected def test_transpose_empty(): # Testet, ob der ValueError bei leerer Matrix kommt with pytest.raises(ValueError): transpose([]) # --- Tests für Matrixmultiplikation (matmul) --- def test_matmul_simple(): # Einfache Multiplikation 2x2 * 2x1 A = [[1, 2], [3, 4]] B = [[5], [6]] # Rechnung: # 1*5 + 2*6 = 5 + 12 = 17 # 3*5 + 4*6 = 15 + 24 = 39 expected = [[17], [39]] assert matmul(A, B) == expected def test_matmul_invalid_dimensions(): # Testet, ob Fehler geworfen wird, wenn Dimensionen nicht passen A = [[1, 2]] # 1x2 B = [[1, 2]] # 1x2 -> Spalten A (2) != Zeilen B (1) with pytest.raises(ValueError): matmul(A, B)