You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

81 regels
1.5 KiB

  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. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include "core.h"
  14. #include "lol/unit.h"
  15. namespace lol
  16. {
  17. LOLUNIT_FIXTURE(MapTest)
  18. {
  19. void SetUp() {}
  20. void TearDown() {}
  21. LOLUNIT_TEST(MapDeclare)
  22. {
  23. Map<uint8_t, uint8_t> m1;
  24. Map<int, int> m2;
  25. Map<float, float> m3;
  26. Map<char const *, char const *> m4;
  27. }
  28. LOLUNIT_TEST(MapSet)
  29. {
  30. Map<int, int> map;
  31. for (int i = 0; i < 1000; i++)
  32. map[i] = -1;
  33. for (int i = 0; i < 1000; i++)
  34. map[i] = i;
  35. for (int i = 0; i < 1000; i++)
  36. LOLUNIT_ASSERT_EQUAL(map[i], i);
  37. }
  38. LOLUNIT_TEST(MapHasKey)
  39. {
  40. Map<int, int> map;
  41. map[0] = 1;
  42. map[2] = 2;
  43. LOLUNIT_ASSERT(map.HasKey(0));
  44. LOLUNIT_ASSERT(!map.HasKey(1));
  45. LOLUNIT_ASSERT(map.HasKey(2));
  46. }
  47. LOLUNIT_TEST(StringMap)
  48. {
  49. Map<char const *, int> map;
  50. map["foo"] = 42;
  51. map["bar"] = 12;
  52. map["baz"] = 2;
  53. int foo = map["foo"];
  54. int bar = map["bar"];
  55. int baz = map["baz"];
  56. LOLUNIT_ASSERT_EQUAL(42, foo);
  57. LOLUNIT_ASSERT_EQUAL(12, bar);
  58. LOLUNIT_ASSERT_EQUAL(2, baz);
  59. }
  60. };
  61. } /* namespace lol */