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

Function TestMatrixSet

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

Source from the content-addressed store, hash-verified

99}
100
101func TestMatrixSet(t *testing.T) {
102 // Create a sample matrix for testing
103 matrix := matrix.New(3, 3, 0)
104
105 // Test case 1: Valid Set
106 err1 := matrix.Set(1, 1, 42)
107 if err1 != nil {
108 t.Errorf("matrix.Set(1, 1, 42) returned an error: %v, expected no error", err1)
109 }
110 val1, err := matrix.Get(1, 1)
111 if err != nil {
112 t.Fatalf("Failed to copy matrix: %v", err)
113 }
114 if val1 != 42 {
115 t.Errorf("matrix.Set(1, 1, 42) did not set the value correctly, expected 42, got %v", val1)
116 }
117
118 // Test case 2: Set with invalid indices
119 err2 := matrix.Set(10, 10, 100)
120 expectedError2 := errors.New("index out of bounds")
121 if err2 == nil || err2.Error() != expectedError2.Error() {
122 t.Errorf("matrix.Set(10, 10, 100) returned error: %v, expected error: %v", err2, expectedError2)
123 }
124 // Test case 3: Get with invalid indices
125 err3 := matrix.Set(-13, -1, 100)
126 expectedError3 := errors.New("index out of bounds")
127 if err3 == nil || err3.Error() != expectedError3.Error() {
128 t.Errorf("matrix.Get(10, 10) returned error: %v, expected error: %v", err3, expectedError3)
129 }
130}
131
132func TestMatrixRows(t *testing.T) {
133 // Create a sample matrix

Callers

nothing calls this directly

Calls 3

NewFunction · 0.92
SetMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected