MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / TestNewStat

Function TestNewStat

internal/utils/cachehits/stat_test.go:17–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestNewStat(t *testing.T) {
18 var a = assert.NewAssertion(t)
19
20 {
21 var stat = cachehits.NewStat(20)
22 for i := 0; i < 1000; i++ {
23 stat.IncreaseCached("a")
24 }
25
26 a.IsTrue(stat.IsGood("a"))
27 }
28
29 {
30 var stat = cachehits.NewStat(5)
31 for i := 0; i < 10000; i++ {
32 stat.IncreaseCached("a")
33 }
34 for i := 0; i < 500; i++ {
35 stat.IncreaseHit("a")
36 }
37
38 stat.IncreaseHit("b") // empty
39
40 a.IsTrue(stat.IsGood("a"))
41 a.IsTrue(stat.IsGood("b"))
42 }
43
44 {
45 var stat = cachehits.NewStat(10)
46 for i := 0; i < 10000; i++ {
47 stat.IncreaseCached("a")
48 }
49 for i := 0; i < 1000; i++ {
50 stat.IncreaseHit("a")
51 }
52
53 stat.IncreaseHit("b") // empty
54
55 a.IsTrue(stat.IsGood("a"))
56 a.IsTrue(stat.IsGood("b"))
57 }
58
59 {
60 var stat = cachehits.NewStat(5)
61 for i := 0; i < 100001; i++ {
62 stat.IncreaseCached("a")
63 }
64 for i := 0; i < 4999; i++ {
65 stat.IncreaseHit("a")
66 }
67
68 a.IsFalse(stat.IsGood("a"))
69 }
70}
71
72func TestNewStat_Memory(t *testing.T) {
73 if !testutils.IsSingleTesting() {

Callers

nothing calls this directly

Calls 4

NewStatFunction · 0.92
IncreaseCachedMethod · 0.80
IsGoodMethod · 0.80
IncreaseHitMethod · 0.65

Tested by

no test coverage detected