Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

77 lignes
1.8 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2014 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 <lol/main.h>
  14. #include "lol/unit.h"
  15. namespace lol
  16. {
  17. LOLUNIT_FIXTURE(Array2DTest)
  18. {
  19. void SetUp() {}
  20. void TearDown() {}
  21. LOLUNIT_TEST(Array2DCreate)
  22. {
  23. array2d<int> a(ivec2(10, 10));
  24. a[0][0] = 2;
  25. a[9][0] = 4;
  26. a[0][9] = 6;
  27. a[9][9] = 8;
  28. LOLUNIT_ASSERT_EQUAL(a[0][0], 2);
  29. LOLUNIT_ASSERT_EQUAL(a[9][0], 4);
  30. LOLUNIT_ASSERT_EQUAL(a[0][9], 6);
  31. LOLUNIT_ASSERT_EQUAL(a[9][9], 8);
  32. array2d<int> const &b = a;
  33. LOLUNIT_ASSERT_EQUAL(b[0][0], 2);
  34. LOLUNIT_ASSERT_EQUAL(b[9][0], 4);
  35. LOLUNIT_ASSERT_EQUAL(b[0][9], 6);
  36. LOLUNIT_ASSERT_EQUAL(b[9][9], 8);
  37. }
  38. LOLUNIT_TEST(Array2DInit)
  39. {
  40. array2d<int> a = { { 1, 2, 3, 4 },
  41. { 5, 6, 7, 8 },
  42. { 9, 8, 7, 6 } };
  43. LOLUNIT_ASSERT_EQUAL(a.GetSize().x, 4);
  44. LOLUNIT_ASSERT_EQUAL(a.GetSize().y, 3);
  45. LOLUNIT_ASSERT_EQUAL(a[0][0], 1);
  46. LOLUNIT_ASSERT_EQUAL(a[1][0], 2);
  47. LOLUNIT_ASSERT_EQUAL(a[2][0], 3);
  48. LOLUNIT_ASSERT_EQUAL(a[3][0], 4);
  49. LOLUNIT_ASSERT_EQUAL(a[0][1], 5);
  50. LOLUNIT_ASSERT_EQUAL(a[1][1], 6);
  51. LOLUNIT_ASSERT_EQUAL(a[2][1], 7);
  52. LOLUNIT_ASSERT_EQUAL(a[3][1], 8);
  53. LOLUNIT_ASSERT_EQUAL(a[0][2], 9);
  54. LOLUNIT_ASSERT_EQUAL(a[1][2], 8);
  55. LOLUNIT_ASSERT_EQUAL(a[2][2], 7);
  56. LOLUNIT_ASSERT_EQUAL(a[3][2], 6);
  57. }
  58. };
  59. } /* namespace lol */