#include "../collections/Array.hpp" #include <stdio.h> #include "gtest_helpers.hpp" #include <gtest/gtest.h> class ArrayTest : public testing::Test { protected: virtual void SetUp() override { testArray[0] = 1; testArray[1] = 2; testArray[2] = 3; testArray[3] = 5; } sprawl::collections::Array<int, 5> testArray; }; TEST_F(ArrayTest, BasicSetupWorks) { EXPECT_EQ(ssize_t(5), testArray.Size()); EXPECT_EQ(1, testArray[0]); EXPECT_EQ(2, testArray[1]); EXPECT_EQ(3, testArray[2]); EXPECT_EQ(5, testArray[3]); } TEST_F(ArrayTest, FillWorks) { testArray.Fill(5); for(auto& value : testArray) { EXPECT_EQ(5, value); } } TEST_F(ArrayTest, CopyConstructorsWork) { sprawl::collections::Array<int, 5> testArray2(testArray); EXPECT_EQ(ssize_t(5), testArray2.Size()); EXPECT_EQ(1, testArray2[0]); EXPECT_EQ(2, testArray2[1]); EXPECT_EQ(3, testArray2[2]); EXPECT_EQ(5, testArray2[3]); EXPECT_EQ(1, testArray[0]); EXPECT_EQ(2, testArray[1]); EXPECT_EQ(3, testArray[2]); EXPECT_EQ(5, testArray[3]); } TEST_F(ArrayTest, MoveConstructorsWork) { sprawl::collections::Array<int, 5> testArray2(std::move(testArray)); EXPECT_EQ(ssize_t(5), testArray2.Size()); EXPECT_EQ(1, testArray2[0]); EXPECT_EQ(2, testArray2[1]); EXPECT_EQ(3, testArray2[2]); EXPECT_EQ(5, testArray2[3]); EXPECT_EQ(1, testArray[0]); EXPECT_EQ(2, testArray[1]); EXPECT_EQ(3, testArray[2]); EXPECT_EQ(5, testArray[3]); } TEST_F(ArrayTest, FrontWorks) { ASSERT_EQ(1, testArray.Front()); } TEST_F(ArrayTest, BackWorks) { testArray[4] = 6; ASSERT_EQ(6, testArray.Back()); } TEST_F(ArrayTest, IterationWorks) { testArray[3] = 4; testArray[4] = 5; int value = 0; for(auto it = testArray.begin(); it != testArray.end(); ++it) { EXPECT_EQ(value + 1, it.Value()); value = it.Value(); } } TEST_F(ArrayTest, NegativeIndexingWorks) { ASSERT_EQ(testArray[-1], testArray.Back()); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 23398 | ququlala | "Forking branch Mainline of shadauxcat-libsprawl to ququlala-libsprawl." | ||
//guest/ShadauxCat/Sprawl/Mainline/UnitTests/UnitTests_Array.cpp | |||||
#3 | 16768 | ShadauxCat |
Improvements to error handling in builds with exceptions disabled: - In debug builds or with SPRAWL_ERRORSTATE_STRICT enabled, ErrorState will output a message to stderr and terminate if Get() is called when an error flag is set. (In release buils or with SPRAWL_ERRORSTATE_PERMISSIVE defined, Get() will return junk memory in this case.) - In debug builds or with SPRAWL_ERRORSTATE_STRICT enabled, ErrorState will output a message to stderr and terminate if its destructor is called without checking the errorstate if an error is present (equivalent to an exception terminating the application if no catch() block is present for it). - On linux builds and when running "Analyze" through visual studio, a warning will be issued if any function returning ErrorState has its return value ignored. (This only applies to builds with exceptions not enabled; when exceptions are enabled no warning is issued) - Many functions that could return ErrorState were having their return values silently ignored in internal sprawl code so the user would not find out about errors if exceptions are disabled; now anything in sprawl code that calls a function returning ErrorState will either handle the error, or (in most cases) surface it back up to the user. - As a positive side-effect of the warnings for ignoring ErrorState, several constructors that were capable of throwing exceptions are no longer capable of doing so. #review-16769 |
||
#2 | 14761 | ShadauxCat |
First drop of code for sprawl::filesystem and sprawl::path. Library will continue to grow. Also fixed a warning on linux. #review-14762 |
||
#1 | 14220 | ShadauxCat |
-Added binary tree implementation (red/black tree) with same multi-key interface as hashmap -Renamed AccessorGroup to MapAccessorGroup to make room for TreeAccessorGroup, which is a lot of duplicated code but had to meet some specific requirements that couldn't be easily fit into the existing AccessorGroup -Fixed HashMap::Clear() not resetting size to 0 -Fixed HashMap::Erase() neither decrementing size nor freeing memory -Changed HashMap to grow before insert instead of after (delaying needed growth until the next insert instead of growing when it detects the next insert will need it) -Fixed a style issue for private function HashMap_Impl::insertHere_() -Fully removed support for Visual Studio 2012 as I have neither the need nor the desire to continue supporting it. The doubled maintenance cost is too high. -Included array unit test that got missed before #review-14221 |