MCPcopy Create free account
hub / github.com/GuyARoss/orbit / TestStack

Function TestStack

pkg/allocated_stack/allocated_stack_test.go:13–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestStack(t *testing.T) {
14 t.Run("not exceed maxSize", func(t *testing.T) {
15 s := New(5)
16
17 for i := 0; i < 15; i++ {
18 s.Add("stuff")
19
20 if i >= 5 && s.Len() > 5 {
21 t.Errorf("incorrect size expected %d got %d", 5, s.Len())
22 }
23
24 if i < 5 && s.Len() != i+1 {
25 t.Errorf("incorrect size expected %d got %d", i+1, s.Len())
26 }
27 }
28 })
29
30 t.Run("arr", func(t *testing.T) {
31 s := New(2)
32 s.Add("1")
33 s.Add("2")
34 s.Add("3")
35 s.Add("4")
36 s.Add("5")
37 s.Add("6")
38
39 a := s.Arr()
40 if a[0] != "6" && a[1] != "5" {
41 t.Errorf("got %s", a)
42 }
43 })
44
45 t.Run("remove correctly", func(t *testing.T) {
46 length := 3
47 s := New(uint(length))
48
49 lst := make([]string, 20)
50 for i := 0; i < 10; i++ {
51 str := uuid.NewString()
52 lst[i] = str
53 s.Add(str)
54
55 if !s.Contains(str) {
56 t.Errorf("does not contain str")
57 }
58
59 if i > length {
60 offset := i - length
61 if offset > 1 {
62 shouldNotExist := lst[:offset-1]
63
64 for _, e := range shouldNotExist {
65 if s.Contains(e) {
66 t.Errorf("element should not exist on stack")
67 }
68 }
69 } else {
70 if s.Contains(lst[0]) {

Callers

nothing calls this directly

Calls 5

ArrMethod · 0.80
ContainsMethod · 0.80
NewFunction · 0.70
AddMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected