1 | // |
---|
2 | // Lol Engine |
---|
3 | // |
---|
4 | // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> |
---|
5 | // This program is free software; you can redistribute it and/or |
---|
6 | // modify it under the terms of the Do What The Fuck You Want To |
---|
7 | // Public License, Version 2, as published by Sam Hocevar. See |
---|
8 | // http://www.wtfpl.net/ for more details. |
---|
9 | // |
---|
10 | |
---|
11 | #if defined HAVE_CONFIG_H |
---|
12 | # include "config.h" |
---|
13 | #endif |
---|
14 | |
---|
15 | #include "core.h" |
---|
16 | #include "lol/unit.h" |
---|
17 | |
---|
18 | namespace lol |
---|
19 | { |
---|
20 | |
---|
21 | LOLUNIT_FIXTURE(ArrayTest) |
---|
22 | { |
---|
23 | void SetUp() {} |
---|
24 | |
---|
25 | void TearDown() {} |
---|
26 | |
---|
27 | LOLUNIT_TEST(ArrayPush) |
---|
28 | { |
---|
29 | Array<int> a; |
---|
30 | a.Push(0); |
---|
31 | a.Push(1); |
---|
32 | a.Push(2); |
---|
33 | a.Push(3); |
---|
34 | |
---|
35 | LOLUNIT_ASSERT_EQUAL(a[0], 0); |
---|
36 | LOLUNIT_ASSERT_EQUAL(a[1], 1); |
---|
37 | LOLUNIT_ASSERT_EQUAL(a[2], 2); |
---|
38 | LOLUNIT_ASSERT_EQUAL(a[3], 3); |
---|
39 | } |
---|
40 | |
---|
41 | LOLUNIT_TEST(ArrayPushWithShift) |
---|
42 | { |
---|
43 | Array<int> a; |
---|
44 | a << 0 << 1 << 2 << 3; |
---|
45 | |
---|
46 | LOLUNIT_ASSERT_EQUAL(a[0], 0); |
---|
47 | LOLUNIT_ASSERT_EQUAL(a[1], 1); |
---|
48 | LOLUNIT_ASSERT_EQUAL(a[2], 2); |
---|
49 | LOLUNIT_ASSERT_EQUAL(a[3], 3); |
---|
50 | } |
---|
51 | |
---|
52 | LOLUNIT_TEST(ArrayCopy) |
---|
53 | { |
---|
54 | Array<int> a; |
---|
55 | a << 0 << 1 << 2 << 3; |
---|
56 | |
---|
57 | Array<int> b = a; |
---|
58 | |
---|
59 | LOLUNIT_ASSERT_EQUAL(b[0], 0); |
---|
60 | LOLUNIT_ASSERT_EQUAL(b[1], 1); |
---|
61 | LOLUNIT_ASSERT_EQUAL(b[2], 2); |
---|
62 | LOLUNIT_ASSERT_EQUAL(b[3], 3); |
---|
63 | } |
---|
64 | |
---|
65 | LOLUNIT_TEST(ArrayRemove) |
---|
66 | { |
---|
67 | Array<int> a; |
---|
68 | a << 0 << 1 << 2 << 3; |
---|
69 | a.Remove(1); |
---|
70 | |
---|
71 | LOLUNIT_ASSERT_EQUAL(a[0], 0); |
---|
72 | LOLUNIT_ASSERT_EQUAL(a[1], 2); |
---|
73 | LOLUNIT_ASSERT_EQUAL(a[2], 3); |
---|
74 | } |
---|
75 | |
---|
76 | LOLUNIT_TEST(EightElements) |
---|
77 | { |
---|
78 | Array<int, long, float, double, unsigned, char, bool, void *> a; |
---|
79 | a.Push(1, 2, 3.f, 4.0, 5, 'a', true, 0); |
---|
80 | |
---|
81 | LOLUNIT_ASSERT_EQUAL(a[0].m1, 1); |
---|
82 | LOLUNIT_ASSERT_EQUAL(a[0].m2, 2); |
---|
83 | LOLUNIT_ASSERT_EQUAL(a[0].m3, 3.f); |
---|
84 | LOLUNIT_ASSERT_EQUAL(a[0].m4, 4.0); |
---|
85 | LOLUNIT_ASSERT_EQUAL(a[0].m5, 5); |
---|
86 | LOLUNIT_ASSERT_EQUAL(a[0].m6, 'a'); |
---|
87 | LOLUNIT_ASSERT_EQUAL(a[0].m7, true); |
---|
88 | LOLUNIT_ASSERT_EQUAL(a[0].m8, 0); |
---|
89 | } |
---|
90 | |
---|
91 | LOLUNIT_TEST(ArrayConcat) |
---|
92 | { |
---|
93 | Array<int> a, b; |
---|
94 | a << 0 << 1; |
---|
95 | b << 2 << 3; |
---|
96 | |
---|
97 | Array<int> c = a + b; |
---|
98 | LOLUNIT_ASSERT_EQUAL(c[0], 0); |
---|
99 | LOLUNIT_ASSERT_EQUAL(c[1], 1); |
---|
100 | LOLUNIT_ASSERT_EQUAL(c[2], 2); |
---|
101 | LOLUNIT_ASSERT_EQUAL(c[3], 3); |
---|
102 | } |
---|
103 | |
---|
104 | LOLUNIT_TEST(ArrayAppend) |
---|
105 | { |
---|
106 | Array<int> a, b; |
---|
107 | a << 0 << 1; |
---|
108 | b << 2 << 3; |
---|
109 | |
---|
110 | a += b; |
---|
111 | LOLUNIT_ASSERT_EQUAL(a[0], 0); |
---|
112 | LOLUNIT_ASSERT_EQUAL(a[1], 1); |
---|
113 | LOLUNIT_ASSERT_EQUAL(a[2], 2); |
---|
114 | LOLUNIT_ASSERT_EQUAL(a[3], 3); |
---|
115 | |
---|
116 | b += b; |
---|
117 | LOLUNIT_ASSERT_EQUAL(b[0], 2); |
---|
118 | LOLUNIT_ASSERT_EQUAL(b[1], 3); |
---|
119 | LOLUNIT_ASSERT_EQUAL(b[2], 2); |
---|
120 | LOLUNIT_ASSERT_EQUAL(b[3], 3); |
---|
121 | } |
---|
122 | }; |
---|
123 | |
---|
124 | } /* namespace lol */ |
---|
125 | |
---|