source: trunk/src/t/base/map.cpp @ 3834

Last change on this file since 3834 was 3834, checked in by touky, 7 years ago

MemTracker is a new thing, better than the shitty previous thing.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
File size: 6.9 KB
Line 
1//
2//  Lol Engine
3//
4//  Copyright © 2010-2015 Sam Hocevar <sam@hocevar.net>
5//
6//  This program is free software. It comes without any warranty, to
7//  the extent permitted by applicable law. You can redistribute it
8//  and/or modify it under the terms of the Do What the Fuck You Want
9//  to Public License, Version 2, as published by the WTFPL Task Force.
10//  See http://www.wtfpl.net/ for more details.
11//
12
13#include <lol/engine-internal.h>
14
15#include <lolunit.h>
16
17namespace lol
18{
19
20lolunit_declare_fixture(MapTest)
21{
22    void SetUp() {}
23
24    void TearDown() {}
25
26    lolunit_declare_test(MapDeclare)
27    {
28        map<uint8_t, uint8_t> m1;
29        map<int, int> m2;
30        map<float, float> m3;
31        map<char const *, char const *> m4;
32    }
33
34    lolunit_declare_test(MapSet)
35    {
36        map<int, int> m;
37
38        for (int i = 0; i < 1000; i++)
39            m[i] = -1;
40
41        for (int i = 0; i < 1000; i++)
42            m[i] = i;
43
44        for (int i = 0; i < 1000; i++)
45            lolunit_assert_equal(m[i], i);
46    }
47
48    lolunit_declare_test(MapHasKey)
49    {
50        map<int, int> m;
51
52        m[0] = 1;
53        m[2] = 2;
54
55        lolunit_assert(m.has_key(0));
56        lolunit_assert(!m.has_key(1));
57        lolunit_assert(m.has_key(2));
58    }
59
60    lolunit_declare_test(MapRemove)
61    {
62        map<uint64_t, uint64_t> m;
63        array<uint64_t> a;
64
65        for (int i = 0; i < 20; i++)
66        {
67            a << i;
68            m[i] = -1;
69        }
70        for (int i = 0; i < a.Count(); i++)
71            m[i] = i;
72        a.Shuffle();
73        for (int i = 0; i < a.Count(); i++)
74            m.remove(a[i]);
75    }
76
77    lolunit_declare_test(MapRemoveString)
78    {
79        map<String, uint64_t> m;
80        array<String> a;
81
82        for (int i = 0; i < 20; i++)
83        {
84            a << String::Printf("test_str_%i", i);
85            m[a.Last()] = -1;
86        }
87        for (int i = 0; i < a.Count(); i++)
88            m[a[i]] = i;
89        a.Shuffle();
90        for (int i = 0; i < a.Count(); i++)
91            m.remove(a[i]);
92    }
93
94    lolunit_declare_test(MapRemoveBug)
95    {
96        map<uint64_t, uint64_t> m;
97
98        for (int i = 0; i < 20; i++)
99            m[i] = i;
100
101        m.remove(12);
102        m.remove(0);
103        m.remove(17);
104        m.remove(2);
105        m.remove(9);
106        m.remove(4);
107        m.remove(15);
108        m.remove(10);
109        lolunit_assert_equal(m[8], 8);
110    }
111
112    lolunit_declare_test(StringMap)
113    {
114        map<char const *, int> m;
115
116        m["foo"] = 42;
117        m["bar"] = 12;
118        m["baz"] = 2;
119
120        int foo = m["foo"];
121        int bar = m["bar"];
122        int baz = m["baz"];
123
124        lolunit_assert_equal(42, foo);
125        lolunit_assert_equal(12, bar);
126        lolunit_assert_equal(2, baz);
127
128        //Big stress test
129        array<String> bones = { "RootNode",
130        "Cyberano_Ns:Root_$AssimpFbx$_Translation",
131        "Cyberano_Ns:Box004_$AssimpFbx$_PreRotation",
132        "Cyberano_Ns:Root_$AssimpFbx$_PreRotation",
133        "Cyberano_Ns:Box004",
134        "Cyberano_Ns:Root_$AssimpFbx$_Rotation",
135        "Cyberano_Ns:Root",
136        "Cyberano_Ns:Hips",
137        "Cyberano_Ns:Spine",
138        "Cyberano_Ns:RightUpLeg",
139        "Cyberano_Ns:LeftUpLeg",
140        "Cyberano_Ns:BeltSheath1",
141        "Cyberano_Ns:RightCoat",
142        "Cyberano_Ns:LeftCoat",
143        "Cyberano_Ns:Spine1",
144        "Cyberano_Ns:RightLeg",
145        "Cyberano_Ns:RightUpLegRoll",
146        "Cyberano_Ns:LeftUpLegRoll",
147        "Cyberano_Ns:LeftLeg",
148        "Cyberano_Ns:Sheath",
149        "Cyberano_Ns:BeltSheath2",
150        "Cyberano_Ns:BeltSheath3",
151        "Cyberano_Ns:Spine2",
152        "Cyberano_Ns:FrontBelt1",
153        "Cyberano_Ns:BackBelt1",
154        "Cyberano_Ns:RightFoot",
155        "Cyberano_Ns:RightLegRoll",
156        "Cyberano_Ns:LeftLegRoll",
157        "Cyberano_Ns:LeftFoot",
158        "Cyberano_Ns:Sword",
159        "Cyberano_Ns:Neck",
160        "Cyberano_Ns:RightShoulder",
161        "Cyberano_Ns:LeftShoulder",
162        "Cyberano_Ns:Cloth",
163        "Cyberano_Ns:FrontBelt2",
164        "Cyberano_Ns:RightToeBase",
165        "Cyberano_Ns:LeftToeBase",
166        "Cyberano_Ns:Head",
167        "Cyberano_Ns:RightArm",
168        "Cyberano_Ns:RightSpaulder1",
169        "Cyberano_Ns:RightSpaulder2",
170        "Cyberano_Ns:LeftArm",
171        "Cyberano_Ns:LeftSpaulder1",
172        "Cyberano_Ns:LeftCloth01",
173        "Cyberano_Ns:MiddleCloth01",
174        "Cyberano_Ns:RightCloth01",
175        "Cyberano_Ns:FrontBelt3",
176        "Cyberano_Ns:RightoeEnd",
177        "Cyberano_Ns:LeftoeEnd",
178        "Cyberano_Ns:HeadEnd",
179        "Cyberano_Ns:Cap",
180        "Cyberano_Ns:RightForeArm",
181        "Cyberano_Ns:RightArmRoll",
182        "Cyberano_Ns:LeftForeArm",
183        "Cyberano_Ns:LeftArmRoll",
184        "Cyberano_Ns:LeftCloth02",
185        "Cyberano_Ns:MiddleCloth02",
186        "Cyberano_Ns:RightCloth02",
187        "Cyberano_Ns:Feather01",
188        "Cyberano_Ns:RightHand",
189        "Cyberano_Ns:RightForeArmRoll",
190        "Cyberano_Ns:LeftHand",
191        "Cyberano_Ns:LeftForeArmRoll",
192        "Cyberano_Ns:LeftCloth03",
193        "Cyberano_Ns:MiddleCloth03",
194        "Cyberano_Ns:RightCloth03",
195        "Cyberano_Ns:Feather02",
196        "Cyberano_Ns:RightThumb1",
197        "Cyberano_Ns:RightIndex1",
198        "Cyberano_Ns:RightMiddle1",
199        "Cyberano_Ns:RightRing1",
200        "Cyberano_Ns:RightCuff",
201        "Cyberano_Ns:LeftThumb1",
202        "Cyberano_Ns:LeftIndex1",
203        "Cyberano_Ns:LeftMiddle1",
204        "Cyberano_Ns:LeftRing1",
205        "Cyberano_Ns:LeftCloth04",
206        "Cyberano_Ns:MiddleCloth04",
207        "Cyberano_Ns:RightCloth04",
208        "Cyberano_Ns:Feather03",
209        "Cyberano_Ns:RightThumb2",
210        "Cyberano_Ns:RightIndex2",
211        "Cyberano_Ns:RightMiddle2",
212        "Cyberano_Ns:RightRing2",
213        "Cyberano_Ns:LeftThumb2",
214        "Cyberano_Ns:LeftIndex2",
215        "Cyberano_Ns:LeftMiddle2",
216        "Cyberano_Ns:LeftRing2",
217        "Cyberano_Ns:Feather04",
218        "Cyberano_Ns:RightThumb3",
219        "Cyberano_Ns:RightIndex3",
220        "Cyberano_Ns:RightMiddle3",
221        "Cyberano_Ns:RightRing3",
222        "Cyberano_Ns:LeftThumb3",
223        "Cyberano_Ns:LeftIndex3",
224        "Cyberano_Ns:LeftMiddle3",
225        "Cyberano_Ns:LeftRing3",
226        "Cyberano_Ns:Feather05",
227        "Cyberano_Ns:RightThumb4",
228        "Cyberano_Ns:RightIndex4",
229        "Cyberano_Ns:RightMiddle4",
230        "Cyberano_Ns:RightRing4",
231        "Cyberano_Ns:LeftThumb4",
232        "Cyberano_Ns:LeftIndex4",
233        "Cyberano_Ns:LeftMiddle4",
234        "Cyberano_Ns:LeftRing4",
235        "Cyberano_Ns:Feather06",
236        "Cyberano_Ns:Feather07",
237        "Cyberano_Ns:Feather08",
238        "Cyberano_Ns:Feather09",
239        "Cyberano_Ns:Feather10",
240        "Cyberano_Ns:Feather11",
241        "Cyberano_Ns:Feather12",
242        "Cyberano_Ns:Feather13",
243        "Cyberano_Ns:Feather14",
244        "Cyberano_Ns:Feather15",
245        "Cyberano_Ns:Feather16",
246        "Cyberano_Ns:Feather17" };
247
248        map<String, int> bones_map;
249        for (int i = 0; i < bones.Count(); ++i)
250            bones_map[bones[i]] = i;
251
252        for (int i = 0; i < bones.Count(); ++i)
253            lolunit_assert_equal(bones_map[bones[i]], i);
254    }
255};
256
257} /* namespace lol */
258
Note: See TracBrowser for help on using the repository browser.