uid_test.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SuperTux
  2. // Copyright (C) 2018 Ingo Ruhnke <grumbel@gmail.com>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #include <gtest/gtest.h>
  17. #include <unordered_set>
  18. #include "util/uid_generator.hpp"
  19. TEST(UIDTest, null)
  20. {
  21. UIDGenerator generator;
  22. UID null_uid;
  23. UID uid = generator.next();
  24. ASSERT_FALSE(null_uid);
  25. ASSERT_TRUE(uid);
  26. ASSERT_TRUE(uid != null_uid);
  27. }
  28. TEST(UIDTest, magic)
  29. {
  30. UIDGenerator generator1;
  31. UIDGenerator generator2;
  32. UID uid1 = generator1.next();
  33. UID uid2 = generator2.next();
  34. ASSERT_TRUE(uid1 != uid2);
  35. }
  36. TEST(UIDTest, copy)
  37. {
  38. UIDGenerator generator;
  39. UID uid = generator.next();
  40. UID other = uid;
  41. ASSERT_EQ(uid, other);
  42. }
  43. TEST(UIDTest, unique)
  44. {
  45. if ((false)) {
  46. UIDGenerator generator;
  47. std::unordered_set<UID> uids;
  48. for(int i = 0; i < 0xffffff; ++i)
  49. {
  50. UID uid = generator.next();
  51. ASSERT_TRUE(uids.find(uid) == uids.end());
  52. uids.insert(uid);
  53. }
  54. }
  55. }
  56. /* EOF */