Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
- File: Main.cpp
- Date: 2022-2-18
- Author: Reece
- ***/
- #include <AuroraRuntime.hpp>
- #include <gtest/gtest.h>
- TEST(Containers, HashMaps)
- {
- struct HelloKey : public AuEnableHashCodeOnData<HelloKey>
- {
- AuUInt32 id {};
- AuUInt8 task {};
- /**
- * inline HelloKey(const AuRemoveConst_t<AuRemoveReference_t<decltype(id)>> &id ,const AuRemoveConst_t<AuRemoveReference_t<decltype(task)>> &task) : id(id) ,task(task) {}
- * inline HelloKey(AuRemoveConst_t<AuRemoveReference_t<decltype(id)>> &&id ,AuRemoveConst_t<AuRemoveReference_t<decltype(task)>> &&task) : id(id) ,task(task) {}
- * 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 ; }
- * bool operator==(const HelloKey & ref) const noexcept { return this->id == ref.id && this->task == ref.task ; }
- * 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; };
- */
- AU_DEFINE_FOR_VA(HelloKey,
- (AU_DEFINE_CTOR_VA, // initializer-list-like ctor (extending AuEnableHashCodeOnData will break lists)
- AU_DEFINE_THIS_MOVE_CTOR_VA, // add move HelloKey(HelloKey &&)
- AU_DEFINE_EQUALS_VA, // add equals operator
- AU_DEFINE_MOVE_VA, // add move assignment operator
- AU_DEFINE_COPY_VA), // add copy assignment operator
- (id, task));
- };
- AuHashMap<HelloKey, AuString> a;
- ASSERT_TRUE(AuTryInsert(a, HelloKey {0, 4}, "hello world"));
- ASSERT_TRUE(AuTryInsert(a, HelloKey {0, 4}, "hello world"));
- ASSERT_TRUE(!AuTryInsert(a, HelloKey {0, 4}, "hello world"));
- }
- TEST(Containers, HashMaps2)
- {
- struct HelloKey
- {
- AuUInt32 id {};
- AuString name {};
- AU_DEFINE_CTOR_VA(HelloKey, (id, name))
- AU_DEFINE_THIS_MOVE_CTOR_VA(HelloKey, (id, name))
- AU_DEFINE_EQUALS_VA(HelloKey, (id, name))
- AU_DEFINE_MOVE_VA(HelloKey, (id, name))
- AU_DEFINE_COPY_VA(HelloKey, (id, name))
- AU_DEFINE_HASHCODE_VA(HelloKey, (id, name))
- /* AuUInt HashCode() const noexcept { return AuHashCode(this->id) ^ AuHashCode(this->task) ; } */
- };
- AuHashMap<HelloKey, AuString> map;
- ASSERT_TRUE(AuTryInsert(map, HelloKey {0, "frog"}, "hello world"));
- ASSERT_TRUE(!AuTryInsert(map, HelloKey {0, "frog"}, "hello world"));
- ASSERT_TRUE(!AuTryInsert(&map, HelloKey {0, "frog"}, "hello world"));
- ASSERT_TRUE(AuExists(map, HelloKey {0, "frog"}));
- ASSERT_TRUE(AuExists(&map, HelloKey {0, "frog"}));
- ASSERT_TRUE(AuTryRemove(map, HelloKey {0, "frog"}));
- ASSERT_TRUE(!AuTryRemove(map, HelloKey {0, "frog"}));
- ASSERT_TRUE(!AuExists(map, HelloKey {0, "frog"}));
- }
- TEST(Containers, Lists)
- {
- AuList<AuUInt8> test;
- ASSERT_TRUE(AuListFromArgs(test, 1, 2, 3, 4, 5, 6, 7, 8));
- for (AU_ITERATE_N_TO_X(i, 1, 9))
- {
- ASSERT_TRUE(AuExists(test, i));
- }
- ASSERT_TRUE(!AuExists(test, 9));
- ASSERT_TRUE(AuTryInsert(test, 9));
- ASSERT_TRUE(AuExists(test, 9));
- ASSERT_TRUE(AuTryRemove(test, 5));
- ASSERT_TRUE(!AuTryRemove(test, 5));
- ASSERT_TRUE(!AuExists(test, 5));
- }
- static void StaticAsserts_Tuples()
- {
- auto tuplePair = AuMakeTuple(AuUInt32(1), AuUInt16(3));
- auto popFront = AuTuplePopFront(tuplePair);
- auto popBack = AuTuplePopBack(tuplePair);
- static_assert(AuIsSame_v<AuUInt16 &, decltype(AuGet<0>(popFront))>);
- static_assert(AuIsSame_v<AuUInt32 &, decltype(AuGet<0>(popBack))>);
- // TODO:
- // AuTuplePushBack
- // AuTuplePushFront
- // AuTupleTakeRange
- // AuTupleForEach
- // AuTupleTransform
- // AuTupleTie
- // AuTupleForward
- }
- TEST(Debug, NullPointersThrow)
- {
- #if !defined(AURORA_ROXTL_NULL_POINTER_CHECKS_DISABLED)
- AuSPtr<AuUInt32> pGold;
- try
- {
- auto gVal = *pGold;
- ASSERT_TRUE(false);
- AuLogDbg("ERROR: {}", gVal);
- }
- catch (...)
- {
- ASSERT_TRUE(true);
- }
- #endif
- }
- void RunTests()
- {
- Aurora::RuntimeStartInfo info;
- info.console.fio.enableLogging = false;
- info.console.forceToolKitWindow = true;
- Aurora::RuntimeStart(info);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement