Last change
on this file since 2109 was
2109,
checked in by sam, 8 years ago
|
core: we can now set Map elements using simply map[foo] = bar, no need for
a Set() method. Also, new HasKey() method.
|
File size:
1.2 KB
|
Line | |
---|
1 | // |
---|
2 | // Lol Engine |
---|
3 | // |
---|
4 | // Copyright: (c) 2010-2012 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://sam.zoy.org/projects/COPYING.WTFPL 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(MapTest) |
---|
22 | { |
---|
23 | void SetUp() {} |
---|
24 | |
---|
25 | void TearDown() {} |
---|
26 | |
---|
27 | LOLUNIT_TEST(MapDeclare) |
---|
28 | { |
---|
29 | Map<uint8_t, uint8_t> m1; |
---|
30 | Map<int, int> m2; |
---|
31 | Map<float, float> m3; |
---|
32 | Map<char const *, char const *> m4; |
---|
33 | } |
---|
34 | |
---|
35 | LOLUNIT_TEST(MapSet) |
---|
36 | { |
---|
37 | Map<int, int> map; |
---|
38 | |
---|
39 | for (int i = 0; i < 100000; i++) |
---|
40 | map[i] = -1; |
---|
41 | |
---|
42 | for (int i = 0; i < 100000; i++) |
---|
43 | map[i] = i; |
---|
44 | |
---|
45 | for (int i = 0; i < 100000; i++) |
---|
46 | LOLUNIT_ASSERT_EQUAL(map[i], i); |
---|
47 | } |
---|
48 | |
---|
49 | LOLUNIT_TEST(MapHasKey) |
---|
50 | { |
---|
51 | Map<int, int> map; |
---|
52 | |
---|
53 | map[0] = 1; |
---|
54 | map[2] = 2; |
---|
55 | |
---|
56 | LOLUNIT_ASSERT(map.HasKey(0)); |
---|
57 | LOLUNIT_ASSERT(!map.HasKey(1)); |
---|
58 | LOLUNIT_ASSERT(map.HasKey(2)); |
---|
59 | } |
---|
60 | }; |
---|
61 | |
---|
62 | } /* namespace lol */ |
---|
63 | |
---|
Note: See
TracBrowser
for help on using the repository browser.