-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgopar3_test.go
63 lines (54 loc) · 1.1 KB
/
gopar3_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
package gopar3
import (
"bytes"
"hash/crc32"
"testing"
"github.com/klauspost/reedsolomon"
)
func TestIdenticalQuorumShardsWithDifferentParity(t *testing.T) {
quorum := [][]byte{
[]byte("aaa"),
[]byte("bbb"),
[]byte("ccc"),
[]byte("ddd"),
[]byte("eee"),
}
enc, err := reedsolomon.New(len(quorum), 3)
if err != nil {
t.Fatal(err)
}
threeMore := append(quorum, nil, nil, nil)
err = enc.Reconstruct(threeMore)
if err != nil {
t.Fatal(err)
}
enc, err = reedsolomon.New(len(quorum), 5)
if err != nil {
t.Fatal(err)
}
fiveMore := append(quorum, nil, nil, nil, nil, nil)
err = enc.Reconstruct(fiveMore)
if err != nil {
t.Fatal(err)
}
for i, shard := range threeMore {
if !bytes.Equal(shard, fiveMore[i]) {
t.Logf("threeMore: %q", shard)
t.Logf("fiveMore: %q", fiveMore[i])
t.Fatal("shards do not match")
}
}
}
func TestIfCastagnoliSumAlwaysSame(t *testing.T) {
crc := crc32.New(castagnoliTable)
_, err := crc.Write([]byte("a"))
if err != nil {
t.Fatal(err)
}
sum := crc.Sum32()
crc.Sum(nil)
sum2 := crc.Sum32()
if sum != sum2 {
t.Fatal("unequal sums")
}
}