MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / TestMultiplyIncompatibleMatrix

Function TestMultiplyIncompatibleMatrix

math/matrix/multiply_test.go:52–89  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

50}
51
52func 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
91func BenchmarkMatrixMultiply(b *testing.B) {
92 // Create sample matrices for benchmarking

Callers

nothing calls this directly

Calls 2

NewFromElementsFunction · 0.92
MultiplyMethod · 0.80

Tested by

no test coverage detected