(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func TestAdd(t *testing.T) { |
| 11 | // Create two matrices with the same dimensions for addition |
| 12 | m1 := matrix.New(2, 2, 1) |
| 13 | m2 := matrix.New(2, 2, 2) |
| 14 | |
| 15 | // Test case 1: Valid matrix addition |
| 16 | addedMatrix, err := m1.Add(m2) |
| 17 | if err != nil { |
| 18 | t.Errorf("Add(m1, m2) returned an error: %v, expected no error", err) |
| 19 | } |
| 20 | expectedMatrix := matrix.New(2, 2, 3) |
| 21 | res := addedMatrix.CheckEqual(expectedMatrix) |
| 22 | if !res { |
| 23 | t.Errorf("Add(m1, m2) returned incorrect result:\n%v\nExpected:\n%v", addedMatrix, expectedMatrix) |
| 24 | } |
| 25 | |
| 26 | // Create two matrices with different dimensions for addition |
| 27 | m3 := matrix.New(2, 2, 1) |
| 28 | m4 := matrix.New(2, 3, 2) |
| 29 | |
| 30 | // Test case 2: Matrices with different dimensions |
| 31 | _, err2 := m3.Add(m4) |
| 32 | expectedError2 := fmt.Errorf("matrices are not compatible for addition") |
| 33 | if err2 == nil || err2.Error() != expectedError2.Error() { |
| 34 | t.Errorf("Add(m3, m4) returned error: %v, expected error: %v", err2, expectedError2) |
| 35 | } |
| 36 | |
| 37 | } |
| 38 | |
| 39 | func BenchmarkAddSmallMatrix(b *testing.B) { |
| 40 | m1 := matrix.New(10, 10, 0) // Create a 10x10 matrix with all zeros |
nothing calls this directly
no test coverage detected