-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathStaticArrayTest.cc
64 lines (59 loc) · 1.6 KB
/
StaticArrayTest.cc
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
//------------------------------------------------------------------------------
// StaticArrayTest.cc
//------------------------------------------------------------------------------
#include "Pre.h"
#include "UnitTest++/src/UnitTest++.h"
#include "Core/Containers/StaticArray.h"
using namespace Oryol;
TEST(StaticArrayTest) {
StaticArray<int, 16> array0;
StaticArray<int, 16> array1;
CHECK(array0.Size() == 16);
CHECK(array1.Size() == 16);
array0.Fill(1);
for (int v : array0) {
CHECK(v == 1);
}
for (int i = 0; i < 16; i++) {
CHECK(array0[0] == 1);
}
for (int i = 0; i < 16; i++) {
array1[i] = i;
}
int i = 0;
for (int v : array1) {
CHECK(v == i++);
}
array0 = array1;
for (i = 0; i < 16; i++) {
CHECK(array0[i] == array1[i]);
CHECK(array0[i] == i);
}
array1.Fill(2);
for (int v : array1) {
CHECK(v == 2);
}
array1 = std::move(array0);
for (i = 0; i < 16; i++) {
CHECK(array1[i] == i);
}
StaticArray<int, 16> array2(array0);
StaticArray<int, 16> array3(std::move(array0));
for (i = 0; i < 16; i++) {
CHECK(array2[i] == i);
CHECK(array3[i] == i);
}
Slice<int> slice = array2.MakeSlice(2, 5);
CHECK(slice.Size() == 5);
CHECK(slice.Offset() == 2);
CHECK(slice[0] == 2);
CHECK(slice[1] == 3);
CHECK(slice[2] == 4);
CHECK(slice[3] == 5);
CHECK(slice[4] == 6);
slice = array2.MakeSlice();
CHECK(slice.Size() == 16);
CHECK(slice.Offset() == 0);
CHECK(slice[0] == 0);
CHECK(slice[15] == 15);
}