MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / TestNonSquareMatrix

Function TestNonSquareMatrix

math/matrix/determinant_test.go:70–96  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

68}
69
70func TestNonSquareMatrix(t *testing.T) {
71 // Creating non-square matrix for testing.
72 initialValue := 0
73 initialRows := 4
74 initialCols := 2
75
76 nonSquareMatrix := matrix.New(initialRows, initialCols, initialValue)
77
78 determinant, err := nonSquareMatrix.Determinant()
79 // Check if non square matrix returns an error.
80 if err == nil {
81 t.Fatalf("No error was returned for a non-square matrix")
82 }
83
84 // Check if the correct error was returned.
85 expectedError := errors.New("Matrix rows and columns must equal in order to find the determinant.")
86
87 if err.Error() != expectedError.Error() {
88 t.Errorf("Error returned from non-square matrix was \n\"%v\"; \nwanted \n\"%v\"", err, expectedError)
89 }
90
91 // Check if the determinant of the non-square matrix is 0.
92 if determinant != 0 {
93 t.Errorf("Determinant of non-square matrix was not 0 but was %d", determinant)
94 }
95
96}
97
98// Test matrix returned from matrix.New
99func TestDefaultMatrix(t *testing.T) {

Callers

nothing calls this directly

Calls 2

NewFunction · 0.92
DeterminantMethod · 0.80

Tested by

no test coverage detected