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

Function TestMatrixInvalidSubMatrix

math/matrix/submatrix_test.go:51–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

49}
50
51func TestMatrixInvalidSubMatrix(t *testing.T) {
52 // Create a sample matrix
53 data := [][]int{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
54 matrix, err := matrix.NewFromElements(data)
55 if err != nil {
56 t.Fatalf("Failed to copy matrix: %v", err)
57 }
58 // Attempt to extract an invalid submatrix
59 _, err = matrix.SubMatrix(1, 1, 3, 3)
60
61 // Check if an error is returned
62 if err == nil {
63 t.Error("Expected an error for invalid submatrix dimensions, but got nil")
64 }
65
66 // Check the error message
67 expectedErrorMessage := "submatrix dimensions exceed matrix bounds"
68 if err.Error() != expectedErrorMessage {
69 t.Errorf("Expected error message '%s', but got '%s'", expectedErrorMessage, err.Error())
70 }
71}
72
73// BenchmarkSubMatrix benchmarks the SubMatrix function.
74func BenchmarkSubMatrix(b *testing.B) {

Callers

nothing calls this directly

Calls 1

SubMatrixMethod · 0.80

Tested by

no test coverage detected