(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func TestList(t *testing.T) { |
| 19 | t.Run("Empty", func(t *testing.T) { |
| 20 | if size := NewList[string]().Len(); size != 0 { |
| 21 | t.Fatalf("unexpected size: %d", size) |
| 22 | } |
| 23 | }) |
| 24 | |
| 25 | t.Run("Shallow", func(t *testing.T) { |
| 26 | list := NewList[string]() |
| 27 | list = list.Append("foo") |
| 28 | if v := list.Get(0); v != "foo" { |
| 29 | t.Fatalf("unexpected value: %v", v) |
| 30 | } |
| 31 | |
| 32 | other := list.Append("bar") |
| 33 | if v := other.Get(0); v != "foo" { |
| 34 | t.Fatalf("unexpected value: %v", v) |
| 35 | } else if v := other.Get(1); v != "bar" { |
| 36 | t.Fatalf("unexpected value: %v", v) |
| 37 | } |
| 38 | |
| 39 | if v := list.Len(); v != 1 { |
| 40 | t.Fatalf("unexpected value: %v", v) |
| 41 | } |
| 42 | }) |
| 43 | |
| 44 | t.Run("Deep", func(t *testing.T) { |
| 45 | list := NewList[int]() |
| 46 | var array []int |
| 47 | for i := 0; i < 100000; i++ { |
| 48 | list = list.Append(i) |
| 49 | array = append(array, i) |
| 50 | } |
| 51 | |
| 52 | if got, exp := len(array), list.Len(); got != exp { |
| 53 | t.Fatalf("List.Len()=%d, exp %d", got, exp) |
| 54 | } |
| 55 | for j := range array { |
| 56 | if got, exp := list.Get(j), array[j]; got != exp { |
| 57 | t.Fatalf("%d. List.Get(%d)=%d, exp %d", len(array), j, got, exp) |
| 58 | } |
| 59 | } |
| 60 | }) |
| 61 | |
| 62 | t.Run("Set", func(t *testing.T) { |
| 63 | list := NewList[string]() |
| 64 | list = list.Append("foo") |
| 65 | list = list.Append("bar") |
| 66 | |
| 67 | if v := list.Get(0); v != "foo" { |
| 68 | t.Fatalf("unexpected value: %v", v) |
| 69 | } |
| 70 | |
| 71 | list = list.Set(0, "baz") |
| 72 | if v := list.Get(0); v != "baz" { |
| 73 | t.Fatalf("unexpected value: %v", v) |
| 74 | } else if v := list.Get(1); v != "bar" { |
| 75 | t.Fatalf("unexpected value: %v", v) |
nothing calls this directly
no test coverage detected
searching dependent graphs…