[🤖] Add Unit-Tests
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m34s

This commit is contained in:
2026-04-27 10:46:08 +02:00
parent dad0e3240d
commit 02d6894ec6
116 changed files with 18795 additions and 1 deletions
+68
View File
@@ -0,0 +1,68 @@
package langext
import (
"git.blackforestbytes.com/BlackForestBytes/goext/tst"
"testing"
)
func TestFormatBytesToSI(t *testing.T) {
tst.AssertEqual(t, FormatBytesToSI(0), "0 B")
tst.AssertEqual(t, FormatBytesToSI(999), "999 B")
tst.AssertEqual(t, FormatBytesToSI(1000), "1.0 kB")
tst.AssertEqual(t, FormatBytesToSI(1500), "1.5 kB")
tst.AssertEqual(t, FormatBytesToSI(1000*1000), "1.0 MB")
tst.AssertEqual(t, FormatBytesToSI(1000*1000*1000), "1.0 GB")
}
func TestFormatBytes(t *testing.T) {
tst.AssertEqual(t, FormatBytes(0), "0 B")
tst.AssertEqual(t, FormatBytes(1023), "1023 B")
tst.AssertEqual(t, FormatBytes(1024), "1.0 KiB")
tst.AssertEqual(t, FormatBytes(1024*1024), "1.0 MiB")
tst.AssertEqual(t, FormatBytes(1024*1024*1024), "1.0 GiB")
tst.AssertEqual(t, FormatBytes(1536), "1.5 KiB")
}
func TestBytesXOR(t *testing.T) {
a := []byte{0x01, 0x02, 0x03, 0xFF}
b := []byte{0xFF, 0xFE, 0xFD, 0x00}
r, err := BytesXOR(a, b)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
expected := []byte{0xFE, 0xFC, 0xFE, 0xFF}
tst.AssertArrayEqual(t, r, expected)
}
func TestBytesXORLengthMismatch(t *testing.T) {
a := []byte{0x01, 0x02}
b := []byte{0x01, 0x02, 0x03}
_, err := BytesXOR(a, b)
if err == nil {
t.Fatalf("expected error on length mismatch, got nil")
}
}
func TestBytesXOREmpty(t *testing.T) {
r, err := BytesXOR([]byte{}, []byte{})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
tst.AssertEqual(t, len(r), 0)
}
func TestBytesXORSelfIsZero(t *testing.T) {
a := []byte{0xAB, 0xCD, 0xEF}
r, err := BytesXOR(a, a)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
for i, v := range r {
if v != 0 {
t.Errorf("expected zero at index %d, got %#x", i, v)
}
}
}