You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
1.6 KiB
Go

package maths
import (
"reflect"
"testing"
)
func TestRotateClockwise(t *testing.T) {
matrix := Matrix[int]{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
}
expected := Matrix[int]{
{7, 4, 1},
{8, 5, 2},
{9, 6, 3},
}
result := matrix.RotateClockwise()
if !reflect.DeepEqual(result, expected) {
t.Errorf("RotateClockwise() = %v, want %v", result, expected)
}
}
func TestTranspose(t *testing.T) {
matrix := Matrix[int]{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
}
expected := Matrix[int]{
{1, 4, 7},
{2, 5, 8},
{3, 6, 9},
}
result := matrix.Transpose()
if !reflect.DeepEqual(result, expected) {
t.Errorf("Transpose() = %v, want %v", result, expected)
}
}
func TestDuplicate(t *testing.T) {
matrix := Matrix[int]{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
}
expected := Matrix[int]{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
}
result := matrix.Duplicate()
if !reflect.DeepEqual(result, expected) {
t.Errorf("Duplicate() = %v, want %v", result, expected)
}
}
func TestEqual(t *testing.T) {
matrix1 := Matrix[int]{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
}
matrix2 := Matrix[int]{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
}
if !matrix1.Equal(matrix2) {
t.Errorf("Equal() = false, want true")
}
matrix3 := Matrix[int]{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
}
matrix4 := Matrix[int]{
{1, 2, 3},
{4, 5, 6},
{7, 8, 0},
}
if matrix3.Equal(matrix4) {
t.Errorf("Equal() = true, want false")
}
matrix5 := Matrix[int]{
{1, 2},
{3, 4},
}
matrix6 := Matrix[int]{
{1, 2, 3},
{4, 5, 6},
}
if matrix5.Equal(matrix6) {
t.Errorf("Equal() = true, want false")
}
}