-
Notifications
You must be signed in to change notification settings - Fork 1
/
strata_test.go
67 lines (55 loc) · 1.49 KB
/
strata_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package reconcile
import (
"fmt"
"math"
"math/rand"
"testing"
)
func TestStrata(t *testing.T) {
numDifferences := 4
numBaseElements := 500
keysize := 32
cellSize := 80
localkeys := [][]byte{}
remotekeys := [][]byte{}
for i := 0; i < numBaseElements; i++ {
element := make([]byte, keysize)
_, err := rand.Read(element)
if err != nil {
t.Error("Could not get random bytes for set element")
return
}
localkeys = append(localkeys, element)
remotekeys = append(remotekeys, element)
}
for i := 0; i < numDifferences; i++ {
element := make([]byte, keysize)
_, err := rand.Read(element)
if err != nil {
t.Error("Could not get random bytes for set element")
return
}
// Add to a set at random
diffSet := &localkeys
if rand.Intn(2) == 0 {
diffSet = &remotekeys
}
*diffSet = append(*diffSet, element)
}
//calculate the depth required to contain all values
var count int
if len(localkeys) > len(remotekeys) {
count = len(localkeys)
} else {
count = len(remotekeys)
}
depth := int(math.Ceil(math.Log2(float64(count))))
localstrata := NewStrata(cellSize, keysize, depth)
remotestrata := NewStrata(cellSize, keysize, depth)
localstrata.Populate(localkeys)
remotestrata.Populate(remotekeys)
diffloc := localstrata.Estimate(remotestrata)
//diffrem := remotestrata.Estimate(localstrata)
fmt.Printf("Real Diff: %v, Strata Estimated: %v \n", numDifferences, diffloc)
//fmt.Printf("Error: %v%%\n", 100*math.Abs(1.0-float64(diffloc)/float64(numDifferences)))
}