-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathisvalid_test.go
64 lines (55 loc) · 1.39 KB
/
isvalid_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package matrix_test
import (
"testing"
"github.com/TheAlgorithms/Go/math/matrix"
)
func TestIsValid(t *testing.T) {
// Test case 1: Valid matrix with consistent row lengths
validMatrix := [][]int{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
}
result1 := matrix.IsValid(validMatrix)
if !result1 {
t.Errorf("IsValid(validMatrix) returned false, expected true (valid matrix)")
}
// Test case 2: Valid matrix with empty rows (no inconsistency)
validMatrixEmptyRows := [][]int{
{},
{},
{},
}
result2 := matrix.IsValid(validMatrixEmptyRows)
if !result2 {
t.Errorf("IsValid(validMatrixEmptyRows) returned false, expected true (valid matrix with empty rows)")
}
// Test case 3: Invalid matrix with inconsistent row lengths
invalidMatrix := [][]int{
{1, 2, 3},
{4, 5},
{6, 7, 8},
}
result3 := matrix.IsValid(invalidMatrix)
if result3 {
t.Errorf("IsValid(invalidMatrix) returned true, expected false (invalid matrix with inconsistent row lengths)")
}
}
func BenchmarkIsValid(b *testing.B) {
// Create a sample matrix for benchmarking
rows := 100
columns := 100
elements := make([][]int, rows)
for i := range elements {
elements[i] = make([]int, columns)
for j := range elements[i] {
elements[i][j] = i*columns + j // Some arbitrary values
}
}
// Reset the benchmark timer
b.ResetTimer()
// Run the benchmark
for i := 0; i < b.N; i++ {
_ = matrix.IsValid(elements)
}
}