Advertisement
ItsTotallyRSX

Untitled

Mar 28th, 2022
1,186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.55 KB | None | 0 0
  1. /***
  2.     Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
  3.  
  4.     File: Main.cpp
  5.     Date: 2022-2-18
  6.     Author: Reece
  7. ***/
  8. #include <AuroraRuntime.hpp>
  9. #include <gtest/gtest.h>
  10.  
  11. TEST(Containers, HashMaps)
  12. {
  13.     struct HelloKey : public AuEnableHashCodeOnData<HelloKey>
  14.     {
  15.         AuUInt32 id {};
  16.         AuUInt8 task {};
  17.  
  18. /**
  19.  *         inline HelloKey(const AuRemoveConst_t<AuRemoveReference_t<decltype(id)>> &id ,const AuRemoveConst_t<AuRemoveReference_t<decltype(task)>> &task) : id(id) ,task(task) {}
  20.  *         inline HelloKey(AuRemoveConst_t<AuRemoveReference_t<decltype(id)>> &&id ,AuRemoveConst_t<AuRemoveReference_t<decltype(task)>> &&task) : id(id) ,task(task) {}
  21.  *         inline HelloKey(HelloKey &&cpy) noexcept : id(AuMove(cpy.id)) ,task(AuMove(cpy.task)) {} bool operator==(const HelloKey & ref) const noexcept { return this->id == ref.id && this->task == ref.task ; }
  22.  *         bool operator==(const HelloKey & ref) const noexcept { return this->id == ref.id && this->task == ref.task ; }
  23.  *         HelloKey& operator=( HelloKey && ref) noexcept { this->id = AuMove(ref.id); this->task = AuMove(ref.task); return *this; } HelloKey& operator=(const HelloKey & ref) { this->id = ref.id; this->task = ref.task; return *this; };
  24.  */
  25.         AU_DEFINE_FOR_VA(HelloKey,
  26.                          (AU_DEFINE_CTOR_VA, // initializer-list-like ctor (extending AuEnableHashCodeOnData will break lists)
  27.                          AU_DEFINE_THIS_MOVE_CTOR_VA, // add move HelloKey(HelloKey &&)
  28.                          AU_DEFINE_EQUALS_VA, // add equals operator
  29.                          AU_DEFINE_MOVE_VA, // add move assignment operator
  30.                          AU_DEFINE_COPY_VA), // add copy assignment operator
  31.                          (id, task));
  32.     };
  33.  
  34.     AuHashMap<HelloKey, AuString> a;
  35.     ASSERT_TRUE(AuTryInsert(a, HelloKey {0, 4}, "hello world"));
  36.     ASSERT_TRUE(AuTryInsert(a, HelloKey {0, 4}, "hello world"));
  37.     ASSERT_TRUE(!AuTryInsert(a, HelloKey {0, 4}, "hello world"));
  38. }
  39.  
  40. TEST(Containers, HashMaps2)
  41. {
  42.     struct HelloKey
  43.     {
  44.         AuUInt32 id {};
  45.         AuString name {};
  46.  
  47.         AU_DEFINE_CTOR_VA(HelloKey, (id, name))
  48.         AU_DEFINE_THIS_MOVE_CTOR_VA(HelloKey, (id, name))
  49.         AU_DEFINE_EQUALS_VA(HelloKey, (id, name))
  50.         AU_DEFINE_MOVE_VA(HelloKey, (id, name))
  51.         AU_DEFINE_COPY_VA(HelloKey, (id, name))
  52.         AU_DEFINE_HASHCODE_VA(HelloKey, (id, name))
  53. /*      AuUInt HashCode() const noexcept { return AuHashCode(this->id) ^ AuHashCode(this->task) ; } */
  54.     };
  55.  
  56.     AuHashMap<HelloKey, AuString> map;
  57.    
  58.     ASSERT_TRUE(AuTryInsert(map, HelloKey {0, "frog"}, "hello world"));
  59.     ASSERT_TRUE(!AuTryInsert(map, HelloKey {0, "frog"}, "hello world"));
  60.     ASSERT_TRUE(!AuTryInsert(&map, HelloKey {0, "frog"}, "hello world"));
  61.     ASSERT_TRUE(AuExists(map, HelloKey {0, "frog"}));
  62.     ASSERT_TRUE(AuExists(&map, HelloKey {0, "frog"}));
  63.     ASSERT_TRUE(AuTryRemove(map, HelloKey {0, "frog"}));
  64.     ASSERT_TRUE(!AuTryRemove(map, HelloKey {0, "frog"}));
  65.     ASSERT_TRUE(!AuExists(map, HelloKey {0, "frog"}));
  66. }
  67.  
  68. TEST(Containers, Lists)
  69. {
  70.     AuList<AuUInt8> test;
  71.  
  72.     ASSERT_TRUE(AuListFromArgs(test, 1, 2, 3, 4, 5, 6, 7, 8));
  73.  
  74.     for (AU_ITERATE_N_TO_X(i, 1, 9))
  75.     {
  76.         ASSERT_TRUE(AuExists(test, i));
  77.     }
  78.  
  79.     ASSERT_TRUE(!AuExists(test, 9));
  80.     ASSERT_TRUE(AuTryInsert(test, 9));
  81.     ASSERT_TRUE(AuExists(test, 9));
  82.     ASSERT_TRUE(AuTryRemove(test, 5));
  83.     ASSERT_TRUE(!AuTryRemove(test, 5));
  84.     ASSERT_TRUE(!AuExists(test, 5));
  85. }
  86.  
  87. static void StaticAsserts_Tuples()
  88. {
  89.     auto tuplePair  = AuMakeTuple(AuUInt32(1), AuUInt16(3));
  90.     auto popFront   = AuTuplePopFront(tuplePair);
  91.     auto popBack    = AuTuplePopBack(tuplePair);
  92.  
  93.     static_assert(AuIsSame_v<AuUInt16 &, decltype(AuGet<0>(popFront))>);
  94.     static_assert(AuIsSame_v<AuUInt32 &, decltype(AuGet<0>(popBack))>);
  95.  
  96.     // TODO:
  97.  
  98.     // AuTuplePushBack
  99.     // AuTuplePushFront
  100.  
  101.     // AuTupleTakeRange
  102.  
  103.     // AuTupleForEach
  104.     // AuTupleTransform
  105.  
  106.     // AuTupleTie
  107.     // AuTupleForward
  108. }
  109.  
  110.  
  111. TEST(Debug, NullPointersThrow)
  112. {
  113. #if !defined(AURORA_ROXTL_NULL_POINTER_CHECKS_DISABLED)
  114.     AuSPtr<AuUInt32> pGold;
  115.  
  116.     try
  117.     {
  118.         auto gVal = *pGold;
  119.         ASSERT_TRUE(false);
  120.         AuLogDbg("ERROR: {}", gVal);
  121.     }
  122.     catch (...)
  123.     {
  124.         ASSERT_TRUE(true);
  125.     }
  126.    
  127. #endif
  128. }
  129.  
  130. void RunTests()
  131. {
  132.     Aurora::RuntimeStartInfo info;
  133.     info.console.fio.enableLogging = false;
  134.     info.console.forceToolKitWindow = true;
  135.     Aurora::RuntimeStart(info);
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement