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

Function TestMatrixGet

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

Source from the content-addressed store, hash-verified

69}
70
71func TestMatrixGet(t *testing.T) {
72 // Create a sample matrix for testing
73 matrix := matrix.New(3, 3, 0)
74 err := matrix.Set(1, 1, 42) // Set a specific value for testing
75 if err != nil {
76 t.Errorf("copyMatrix.Set error: %s", err.Error())
77 }
78 // Test case 1: Valid Get
79 val1, err1 := matrix.Get(1, 1)
80 if err1 != nil {
81 t.Errorf("matrix.Get(1, 1) returned an error: %v, expected no error", err1)
82 }
83 if val1 != 42 {
84 t.Errorf("matrix.Get(1, 1) returned %v, expected 42", val1)
85 }
86
87 // Test case 2: Get with invalid indices
88 _, err2 := matrix.Get(10, 10)
89 expectedError2 := errors.New("index out of range")
90 if err2 == nil || err2.Error() != expectedError2.Error() {
91 t.Errorf("matrix.Get(10, 10) returned error: %v, expected error: %v", err2, expectedError2)
92 }
93 // Test case 3: Get with invalid indices
94 _, err3 := matrix.Get(-1, -3)
95 expectedError3 := errors.New("index out of range")
96 if err3 == nil || err3.Error() != expectedError3.Error() {
97 t.Errorf("matrix.Get(10, 10) returned error: %v, expected error: %v", err3, expectedError3)
98 }
99}
100
101func TestMatrixSet(t *testing.T) {
102 // Create a sample matrix for testing

Callers

nothing calls this directly

Calls 3

NewFunction · 0.92
SetMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected