-
Notifications
You must be signed in to change notification settings - Fork 0
/
algo_test.go
46 lines (33 loc) · 899 Bytes
/
algo_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package f0
import (
"fmt"
"os"
"strings"
"testing"
"time"
)
// This test should work because it's memory is significantly higher than the unique count.
// TODO: I need to tweak the algorithm so that this works.
func TestBible(t *testing.T) {
source, err := os.ReadFile("bible.txt")
if err != nil {
t.Error(err)
}
vx := strings.ReplaceAll(string(source), ".", "")
ax := strings.Split(vx, " ")
mapMethod := time.Now()
og := make(map[string]struct{})
for _, word := range ax {
if _, ok := og[word]; !ok {
og[word] = struct{}{}
}
}
fmt.Println("Map time:", time.Since(mapMethod))
uniqueCount := float64(len(og))
// At this scale, with such small memory, inaccuracies are expected.
estTime := time.Now()
if n := Estimate(ax, 0.01, 0.001); n != uniqueCount {
t.Errorf("wanted %f, got %f", uniqueCount, n)
}
fmt.Println("Estimate time:", time.Since(estTime))
}