-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprotocol_test.go
53 lines (44 loc) · 1.29 KB
/
protocol_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
package main
import (
"testing"
"github.com/matryer/is"
)
func TestSheddingThreshold_NextValue(t *testing.T) {
t.Run("Sanity", func(t *testing.T) {
is := is.New(t)
s := newSheddingThreshold(1, 1000)
curr := s.val
is.True(s.val > s.min) // CurrVal should be bigger than minimum.
is.True(s.val < s.max) // CurrVal should be bigger than minimum.
next := s.NextValue()
is.True(next > s.min) // NextValue should be bigger than minimum.
is.True(next < s.max) // NextValue should be bigger than minimum.
is.True(next > curr) // Next should increase until it reaches the maximum.
})
t.Run("MustDecreaseIfGreaterThanMaximum", func(t *testing.T) {
is := is.New(t)
s := newSheddingThreshold(1, 1000)
s.max = s.val + 1
v := s.val
next := s.NextValue()
is.True(next < v)
is.True(next < s.max)
})
t.Run("MustIncreaseIfLessThanMinimum", func(t *testing.T) {
is := is.New(t)
s := newSheddingThreshold(1, 1000)
s.min = s.val + 2*s.nextEntropy() // Guaranteeing next value is less than min.
v := s.val
next := s.NextValue()
is.True(next > v)
is.True(next > s.min)
})
}
func TestSheddingThreshold_GC(t *testing.T) {
is := is.New(t)
s := newSheddingThreshold(1, 1000)
next := s.NextValue()
s.GC()
v := s.val
is.True(v < next) // Val should decrease when GC is called.
}