| 7 | ) |
| 8 | |
| 9 | func TestIsValid(t *testing.T) { |
| 10 | // Test case 1: Valid matrix with consistent row lengths |
| 11 | validMatrix := [][]int{ |
| 12 | {1, 2, 3}, |
| 13 | {4, 5, 6}, |
| 14 | {7, 8, 9}, |
| 15 | } |
| 16 | result1 := matrix.IsValid(validMatrix) |
| 17 | if !result1 { |
| 18 | t.Errorf("IsValid(validMatrix) returned false, expected true (valid matrix)") |
| 19 | } |
| 20 | |
| 21 | // Test case 2: Valid matrix with empty rows (no inconsistency) |
| 22 | validMatrixEmptyRows := [][]int{ |
| 23 | {}, |
| 24 | {}, |
| 25 | {}, |
| 26 | } |
| 27 | result2 := matrix.IsValid(validMatrixEmptyRows) |
| 28 | if !result2 { |
| 29 | t.Errorf("IsValid(validMatrixEmptyRows) returned false, expected true (valid matrix with empty rows)") |
| 30 | } |
| 31 | |
| 32 | // Test case 3: Invalid matrix with inconsistent row lengths |
| 33 | invalidMatrix := [][]int{ |
| 34 | {1, 2, 3}, |
| 35 | {4, 5}, |
| 36 | {6, 7, 8}, |
| 37 | } |
| 38 | result3 := matrix.IsValid(invalidMatrix) |
| 39 | if result3 { |
| 40 | t.Errorf("IsValid(invalidMatrix) returned true, expected false (invalid matrix with inconsistent row lengths)") |
| 41 | } |
| 42 | |
| 43 | } |
| 44 | |
| 45 | func BenchmarkIsValid(b *testing.B) { |
| 46 | // Create a sample matrix for benchmarking |