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

Function TestMatrixCopy

math/matrix/copy_test.go:9–43  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestMatrixCopy(t *testing.T) {
10 // Create a sample matrix
11 data := [][]int{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
12 // Ensure that the copy is not the same as the original
13 matrix, err := matrix.NewFromElements(data)
14 if err != nil {
15 t.Fatalf("Failed to copy matrix: %v", err)
16 }
17 copyMatrix, err := matrix.Copy()
18 if err != nil {
19 t.Fatalf("Failed to copy matrix: %v", err)
20 }
21
22 // Ensure that the copy is not the same as the original
23 if &matrix == &copyMatrix {
24 t.Errorf("Copy did not create a new matrix.")
25 }
26
27 for i := 0; i < matrix.Rows(); i++ {
28 for j := 0; j < matrix.Columns(); j++ {
29 val1, err := matrix.Get(i, j)
30 if err != nil {
31 t.Fatalf("Failed to copy matrix: %v", err)
32 }
33 val2, err := copyMatrix.Get(i, j)
34 if err != nil {
35 t.Fatalf("Failed to copy matrix: %v", err)
36 }
37 if val1 != val2 {
38 t.Errorf("Copy did not correctly copy element (%d, %d).", i, j)
39 }
40 }
41 }
42
43}
44
45func TestMatrixCopyEmpty(t *testing.T) {
46 // Create an empty matrix

Callers

nothing calls this directly

Calls 4

CopyMethod · 0.80
RowsMethod · 0.80
ColumnsMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected