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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
package test_core_container
import "core:testing"
import "core:container/small_array"
@(test)
test_small_array_removes :: proc(t: ^testing.T) {
array: small_array.Small_Array(10, int)
small_array.append(&array, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
small_array.ordered_remove(&array, 0)
testing.expect(t, slice_equal(small_array.slice(&array), []int { 1, 2, 3, 4, 5, 6, 7, 8, 9 }))
small_array.ordered_remove(&array, 5)
testing.expect(t, slice_equal(small_array.slice(&array), []int { 1, 2, 3, 4, 5, 7, 8, 9 }))
small_array.ordered_remove(&array, 6)
testing.expect(t, slice_equal(small_array.slice(&array), []int { 1, 2, 3, 4, 5, 7, 9 }))
small_array.unordered_remove(&array, 0)
testing.expect(t, slice_equal(small_array.slice(&array), []int { 9, 2, 3, 4, 5, 7 }))
small_array.unordered_remove(&array, 2)
testing.expect(t, slice_equal(small_array.slice(&array), []int { 9, 2, 7, 4, 5 }))
small_array.unordered_remove(&array, 4)
testing.expect(t, slice_equal(small_array.slice(&array), []int { 9, 2, 7, 4 }))
}
@(test)
test_small_array_inject_at :: proc(t: ^testing.T) {
array: small_array.Small_Array(13, int)
small_array.append(&array, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
testing.expect(t, small_array.inject_at(&array, 0, 0), "Expected to be able to inject into small array")
testing.expect(t, slice_equal(small_array.slice(&array), []int { 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }))
testing.expect(t, small_array.inject_at(&array, 0, 5), "Expected to be able to inject into small array")
testing.expect(t, slice_equal(small_array.slice(&array), []int { 0, 0, 1, 2, 3, 0, 4, 5, 6, 7, 8, 9 }))
testing.expect(t, small_array.inject_at(&array, 0, small_array.len(array)), "Expected to be able to inject into small array")
testing.expect(t, slice_equal(small_array.slice(&array), []int { 0, 0, 1, 2, 3, 0, 4, 5, 6, 7, 8, 9, 0 }))
}
@(test)
test_small_array_push_back_elems :: proc(t: ^testing.T) {
array: small_array.Small_Array(2, int)
testing.expect(t, slice_equal(small_array.slice(&array), []int { }))
testing.expect(t, small_array.append(&array, 0), "Expected to be able to append to empty small array")
testing.expect(t, slice_equal(small_array.slice(&array), []int { 0 }))
testing.expect(t, small_array.append(&array, 1, 2) == false, "Expected to fail appending multiple elements beyond capacity of small array")
testing.expect(t, small_array.append(&array, 1), "Expected to be able to append to small array")
testing.expect(t, slice_equal(small_array.slice(&array), []int { 0, 1 }))
testing.expect(t, small_array.append(&array, 1) == false, "Expected to fail appending to full small array")
testing.expect(t, small_array.append(&array, 1, 2) == false, "Expected to fail appending multiple elements to full small array")
small_array.clear(&array)
testing.expect(t, slice_equal(small_array.slice(&array), []int { }))
testing.expect(t, small_array.append(&array, 1, 2, 3) == false, "Expected to fail appending multiple elements to empty small array")
testing.expect(t, slice_equal(small_array.slice(&array), []int { }))
testing.expect(t, small_array.append(&array, 1, 2), "Expected to be able to append multiple elements to empty small array")
testing.expect(t, slice_equal(small_array.slice(&array), []int { 1, 2 }))
}
@(test)
test_small_array_resize :: proc(t: ^testing.T) {
array: small_array.Small_Array(4, int)
for i in 0..<4 {
small_array.append(&array, i+1)
}
testing.expect(t, slice_equal(small_array.slice(&array), []int{1, 2, 3, 4}), "Expected to initialize the array with 1, 2, 3, 4")
small_array.clear(&array)
testing.expect(t, slice_equal(small_array.slice(&array), []int{}), "Expected to clear the array")
small_array.non_zero_resize(&array, 4)
testing.expect(t, slice_equal(small_array.slice(&array), []int{1, 2, 3, 4}), "Expected non_zero_resize to set length 4 with previous values")
small_array.clear(&array)
small_array.resize(&array, 4)
testing.expect(t, slice_equal(small_array.slice(&array), []int{0, 0, 0, 0}), "Expected resize to set length 4 with zeroed values")
}
slice_equal :: proc(a, b: []int) -> bool {
if len(a) != len(b) {
return false
}
for a, i in a {
if b[i] != a {
return false
}
}
return true
}
|