Files
goext/langext/compare_test.go
T
Mikescher 02d6894ec6
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m34s
[🤖] Add Unit-Tests
2026-04-27 16:31:29 +02:00

64 lines
1.8 KiB
Go

package langext
import (
"git.blackforestbytes.com/BlackForestBytes/goext/tst"
"testing"
)
func TestCompareIntArrLess(t *testing.T) {
tst.AssertEqual(t, CompareIntArr([]int{1, 2, 3}, []int{1, 2, 4}), true)
tst.AssertEqual(t, CompareIntArr([]int{0}, []int{1}), true)
}
func TestCompareIntArrGreater(t *testing.T) {
tst.AssertEqual(t, CompareIntArr([]int{1, 2, 5}, []int{1, 2, 4}), false)
tst.AssertEqual(t, CompareIntArr([]int{2}, []int{1}), false)
}
func TestCompareIntArrEqual(t *testing.T) {
tst.AssertEqual(t, CompareIntArr([]int{1, 2, 3}, []int{1, 2, 3}), false)
tst.AssertEqual(t, CompareIntArr([]int{}, []int{}), false)
}
func TestCompareArrLess(t *testing.T) {
tst.AssertEqual(t, CompareArr([]int{1, 2, 3}, []int{1, 2, 4}), -1)
}
func TestCompareArrGreater(t *testing.T) {
r := CompareArr([]int{1, 2, 5}, []int{1, 2, 4})
if r <= 0 {
t.Errorf("expected positive, got %d", r)
}
}
func TestCompareArrEqual(t *testing.T) {
tst.AssertEqual(t, CompareArr([]int{1, 2, 3}, []int{1, 2, 3}), 0)
tst.AssertEqual(t, CompareArr([]int{}, []int{}), 0)
}
func TestCompareString(t *testing.T) {
tst.AssertEqual(t, CompareString("a", "b"), -1)
tst.AssertEqual(t, CompareString("b", "a"), 1)
tst.AssertEqual(t, CompareString("a", "a"), 0)
}
func TestCompareInt(t *testing.T) {
tst.AssertEqual(t, CompareInt(1, 2), -1)
tst.AssertEqual(t, CompareInt(2, 1), 1)
tst.AssertEqual(t, CompareInt(2, 2), 0)
}
func TestCompareInt64(t *testing.T) {
tst.AssertEqual(t, CompareInt64(int64(1), int64(2)), -1)
tst.AssertEqual(t, CompareInt64(int64(2), int64(1)), 1)
tst.AssertEqual(t, CompareInt64(int64(0), int64(0)), 0)
}
func TestCompareGeneric(t *testing.T) {
tst.AssertEqual(t, Compare(1, 2), -1)
tst.AssertEqual(t, Compare(2, 1), 1)
tst.AssertEqual(t, Compare(2, 2), 0)
tst.AssertEqual(t, Compare("x", "y"), -1)
tst.AssertEqual(t, Compare(3.5, 1.2), 1)
}