Files
goext/langext/rand_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

35 lines
657 B
Go

package langext
import (
"git.blackforestbytes.com/BlackForestBytes/goext/tst"
"testing"
)
func TestRandBytesLength(t *testing.T) {
for _, sz := range []int{0, 1, 16, 32, 1024} {
b := RandBytes(sz)
tst.AssertEqual(t, len(b), sz)
}
}
func TestRandBytesDistinct(t *testing.T) {
a := RandBytes(32)
b := RandBytes(32)
// Two cryptographic random sequences should not be equal in 32 bytes.
if len(a) != 32 || len(b) != 32 {
t.Fatalf("unexpected length")
}
equal := true
for i := range a {
if a[i] != b[i] {
equal = false
break
}
}
if equal {
t.Errorf("two consecutive 32-byte RandBytes calls returned identical results")
}
}