entropy_test.gno
1.68 Kb ยท 77 lines
1package entropy
2
3import (
4 "strconv"
5 "testing"
6)
7
8func TestInstance(t *testing.T) {
9 instance := New()
10 if instance == nil {
11 t.Errorf("instance should not be nil")
12 }
13}
14
15func TestInstanceValue(t *testing.T) {
16 baseEntropy := New()
17 baseResult := computeValue(t, baseEntropy)
18
19 sameHeightEntropy := New()
20 sameHeightResult := computeValue(t, sameHeightEntropy)
21
22 if baseResult != sameHeightResult {
23 t.Errorf("should have the same result: new=%s, base=%s", sameHeightResult, baseResult)
24 }
25
26 testing.SkipHeights(1)
27 differentHeightEntropy := New()
28 differentHeightResult := computeValue(t, differentHeightEntropy)
29
30 if baseResult == differentHeightResult {
31 t.Errorf("should have different result: new=%s, base=%s", differentHeightResult, baseResult)
32 }
33}
34
35func TestInstanceValue64(t *testing.T) {
36 baseEntropy := New()
37 baseResult := computeValue64(t, baseEntropy)
38
39 sameHeightEntropy := New()
40 sameHeightResult := computeValue64(t, sameHeightEntropy)
41
42 if baseResult != sameHeightResult {
43 t.Errorf("should have the same result: new=%s, base=%s", sameHeightResult, baseResult)
44 }
45
46 testing.SkipHeights(1)
47 differentHeightEntropy := New()
48 differentHeightResult := computeValue64(t, differentHeightEntropy)
49
50 if baseResult == differentHeightResult {
51 t.Errorf("should have different result: new=%s, base=%s", differentHeightResult, baseResult)
52 }
53}
54
55func computeValue(t *testing.T, r *Instance) string {
56 t.Helper()
57
58 out := ""
59 for i := 0; i < 10; i++ {
60 val := int(r.Value())
61 out += strconv.Itoa(val) + " "
62 }
63
64 return out
65}
66
67func computeValue64(t *testing.T, r *Instance) string {
68 t.Helper()
69
70 out := ""
71 for i := 0; i < 10; i++ {
72 val := int(r.Value64())
73 out += strconv.Itoa(val) + " "
74 }
75
76 return out
77}