| 49 | } |
| 50 | |
| 51 | func 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. |
| 74 | func BenchmarkSubMatrix(b *testing.B) { |