Files
cunicu/test/test_test.go
Steffen Vogel ef8be95fcc test: restructure test packages
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
2022-08-31 19:59:47 +02:00

47 lines
1.0 KiB
Go

package test_test
import (
"crypto/rand"
"testing"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"riasc.eu/wice/test"
)
func TestSuite(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Test Helper Suite")
}
var _ = test.SetupLogging()
var _ = Describe("entropy", func() {
Specify("that the entropy of an empty slice is zero", func() {
Expect(test.Entropy([]byte{})).To(BeNumerically("==", 0))
Expect(test.Entropy(nil)).To(BeNumerically("==", 0))
})
Specify("that the entropy of A is defined as", func() {
Expect(test.Entropy([]byte("AAAAAAAAAAAAAA"))).To(BeZero())
})
Specify("that the entropy of A is defined as", func() {
Expect(test.Entropy([]byte("This is some not-so random string"))).To(
And(
BeNumerically(">", 1),
BeNumerically("<", 5),
),
)
})
Specify("that the entropy of random data", func() {
random := make([]byte, 128)
n, err := rand.Read(random)
Expect(err).To(Succeed())
Expect(n).To(Equal(128))
Expect(test.Entropy(random)).To(BeNumerically(">", 5))
})
})