@@ 0,0 1,67 @@
+package moac
+
+import (
+ "math"
+ "testing"
+)
+
+const margin = 0.05 // acceptable error
+
+var tests = []struct {
+ name string
+ given Givens
+ quantum bool
+ // Expected values should be within 10% error
+ expectedBF float64
+ expectedME float64
+}{
+ { // from README
+ name: "hitchhiker",
+ quantum: true,
+ given: Givens{
+ Mass: 5.97e24,
+ Time: 1.45e17,
+ Password: "v¢JÊÙúQ§4mÀÛªZûYÍé©mËiÐ× \"½J6y.ñíí'è¦ïϵ°~",
+ },
+ expectedBF: 0.6807,
+ expectedME: 427.3,
+ },
+ { // from blog post: https://seirdy.one/2021/01/12/password-strength.html
+ name: "universe",
+ quantum: false,
+ given: Givens{
+ Mass: 9.18e52,
+ Entropy: 510,
+ },
+ expectedBF: 9.527e-62,
+ expectedME: 307.3,
+ },
+}
+
+func TestBruteForceability(t *testing.T) {
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ got, err := BruteForceability(&test.given, test.quantum)
+ if err != nil {
+ t.Fatalf("BruteForceability() = %v", err)
+ }
+ if math.Abs(got-test.expectedBF)/test.expectedBF > margin {
+ t.Errorf("Bruteforceability() = %.4g; want %.4g", got, test.expectedBF)
+ }
+ })
+ }
+}
+
+func TestMinEntropy(t *testing.T) {
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ got, err := MinEntropy(&test.given, test.quantum)
+ if err != nil {
+ t.Fatalf("MinEntropy() = %v", err)
+ }
+ if math.Abs(got-test.expectedME)/test.expectedME > margin {
+ t.Errorf("MinEntropy() = %.4g; want %.4g", got, test.expectedME)
+ }
+ })
+ }
+}