(t *testing.T)
| 50 | } |
| 51 | |
| 52 | func TestMultiplyIncompatibleMatrix(t *testing.T) { |
| 53 | // Test case with incompatible matrices |
| 54 | t.Run("Incompatible Matrices", func(t *testing.T) { |
| 55 | mat1 := [][]int{{1, 2, 3}, {4, 5, 6}} |
| 56 | mat2 := [][]int{{7, 8}, {9, 10}} |
| 57 | m1, err := matrix.NewFromElements(mat1) |
| 58 | if err != nil { |
| 59 | t.Fatalf("Failed to copy matrix: %v", err) |
| 60 | } |
| 61 | m2, err := matrix.NewFromElements(mat2) |
| 62 | if err != nil { |
| 63 | t.Fatalf("Failed to copy matrix: %v", err) |
| 64 | } |
| 65 | |
| 66 | _, err = m1.Multiply(m2) |
| 67 | if err == nil { |
| 68 | t.Error("Expected an error, but got none") |
| 69 | } |
| 70 | }) |
| 71 | |
| 72 | t.Run("Incompatible Matrices", func(t *testing.T) { |
| 73 | mat1 := [][]int{{1, 2}} |
| 74 | mat2 := [][]int{{}} |
| 75 | m1, err := matrix.NewFromElements(mat1) |
| 76 | if err != nil { |
| 77 | t.Fatalf("Failed to copy matrix: %v", err) |
| 78 | } |
| 79 | m2, err := matrix.NewFromElements(mat2) |
| 80 | if err != nil { |
| 81 | t.Fatalf("Failed to copy matrix: %v", err) |
| 82 | } |
| 83 | _, err = m1.Multiply(m2) |
| 84 | |
| 85 | if err == nil { |
| 86 | t.Error("Expected an error, but got none") |
| 87 | } |
| 88 | }) |
| 89 | } |
| 90 | |
| 91 | func BenchmarkMatrixMultiply(b *testing.B) { |
| 92 | // Create sample matrices for benchmarking |
nothing calls this directly
no test coverage detected