some testing ang enchancments

This commit is contained in:
2026-02-06 13:46:09 +03:00
parent 948ac0a1b0
commit 4ba746956a
7 changed files with 286 additions and 94 deletions

78
slice_test.go Normal file
View File

@@ -0,0 +1,78 @@
package extypes
import (
"fmt"
"testing"
)
type A struct {
i int
b bool
s string
}
func TestSlice_Index(t *testing.T) {
s := make(Slice[int], 10)
for i := 0; i < 10; i++ {
s[i] = i + 1
}
if s.Index(0) != -1 {
t.Errorf("s.Index(0) != -1")
}
if s.Index(5) != 4 {
t.Errorf("s.Index(5) != 4")
}
s2 := make(Slice[A], 5)
for i := 0; i < 5; i++ {
s2[i] = A{i + 1, false, fmt.Sprint(i)}
}
if s2.Index(A{2, false, "1"}) != 1 {
t.Errorf("s2 wrong index")
}
}
func TestSlice_Equal(t *testing.T) {
a1 := make(Slice[int], 10)
a2 := make(Slice[int], 10)
a3 := make(Slice[int], 5)
for i := 0; i < 10; i++ {
a1[i] = i
a2[i] = i + 1
}
for i := 0; i < 5; i++ {
a3[i] = i
}
if a1.Equal(a2) {
t.Errorf("a1 == a2")
}
if a1.Equal(a3) {
t.Errorf("a1 == a3")
}
if a2.Equal(a3) {
t.Errorf("a2 == a3")
}
}
func TestSlice_Pop(t *testing.T) {
a1 := make(Slice[int], 10)
a2 := make(Slice[int], 9)
for i := 0; i < 10; i++ {
a1[i] = i
}
for i := 0; i < 9; i++ {
a2[i] = i
}
a1 = a1.Pop(a1.Len() - 1)
if a1.Len() != 9 {
t.Errorf("a1.Len() != 9")
}
if !a1.Equal(a2) {
t.Errorf("a1 != a2")
}
}