package captcha import "testing" func TestPrngKnownVectors(t *testing.T) { cases := []struct { seed string length int want string }{ {"hello", 8, "eb492c6e"}, {"hello", 16, "eb492c6e1655ea8c"}, {"test", 32, "9c7ca3730a4a283aa6e4bc1c1d83b14f"}, {"a", 8, "441aaeb8"}, {"z", 8, "da40eb31"}, } for _, c := range cases { if got := prng(c.seed, c.length); got != c.want { t.Errorf("prng(%q,%d)=%q want %q", c.seed, c.length, got, c.want) } } } func TestPrngLengthAndDeterminism(t *testing.T) { for _, n := range []int{1, 8, 16, 32, 64} { if got := prng("x", n); len(got) != n { t.Errorf("len(prng(\"x\",%d))=%d want %d", n, len(got), n) } } if prng("seed1", 16) == prng("seed2", 16) { t.Error("different seeds produced identical output") } a, b := prng("test", 16), prng("test", 16) if a != b { t.Error("prng not deterministic") } }