#include "../collections/Deque.hpp" #include "gtest_helpers.hpp" #include <gtest/gtest.h> class DequeTest : public testing::Test { protected: virtual void SetUp() override { testDeque.PushBack(3); testDeque.PushBack(5); testDeque.PushFront(2); testDeque.PushFront(1); } sprawl::collections::Deque<int> testDeque; }; TEST_F(DequeTest, BasicSetupWorks) { EXPECT_EQ(1, testDeque[0]); EXPECT_EQ(2, testDeque[1]); EXPECT_EQ(3, testDeque[2]); EXPECT_EQ(5, testDeque[3]); } TEST_F(DequeTest, FillConstructorsWork) { sprawl::collections::Deque<int> testDeque2(sprawl::collections::Fill(5)); EXPECT_EQ(ssize_t(5), testDeque2.Size()); for(auto& value : testDeque2) { EXPECT_EQ(0, value); } sprawl::collections::Deque<int> testDeque3(sprawl::collections::Fill(5), 3); EXPECT_EQ(ssize_t(5), testDeque3.Size()); for(auto& value : testDeque3) { EXPECT_EQ(3, value); } } TEST_F(DequeTest, CopyConstructorsWork) { sprawl::collections::Deque<int> testDeque2(testDeque); EXPECT_EQ(ssize_t(4), testDeque2.Size()); EXPECT_EQ(1, testDeque2[0]); EXPECT_EQ(2, testDeque2[1]); EXPECT_EQ(3, testDeque2[2]); EXPECT_EQ(5, testDeque2[3]); } TEST_F(DequeTest, MoveConstructorsWork) { sprawl::collections::Deque<int> testDeque2(std::move(testDeque)); EXPECT_EQ(ssize_t(4), testDeque2.Size()); EXPECT_EQ(1, testDeque2[0]); EXPECT_EQ(2, testDeque2[1]); EXPECT_EQ(3, testDeque2[2]); EXPECT_EQ(5, testDeque2[3]); EXPECT_EQ(ssize_t(0), testDeque.Size()); testDeque.PushFront(20); testDeque.PushFront(10); testDeque.PushBack(30); testDeque.PushBack(50); //Make sure modifying one doesn't impact the other EXPECT_EQ(ssize_t(4), testDeque2.Size()); EXPECT_EQ(1, testDeque2[0]); EXPECT_EQ(2, testDeque2[1]); EXPECT_EQ(3, testDeque2[2]); EXPECT_EQ(5, testDeque2[3]); testDeque2.PushFront(40); testDeque2.PushFront(90); testDeque2.PushBack(20); testDeque2.PushBack(220); EXPECT_EQ(ssize_t(4), testDeque.Size()); EXPECT_EQ(10, testDeque[0]); EXPECT_EQ(20, testDeque[1]); EXPECT_EQ(30, testDeque[2]); EXPECT_EQ(50, testDeque[3]); } TEST_F(DequeTest, FrontWorks) { ASSERT_EQ(1, testDeque.Front()); } TEST_F(DequeTest, BackWorks) { ASSERT_EQ(5, testDeque.Back()); } TEST_F(DequeTest, IterationAndInsertWorks) { for(auto it = testDeque.begin(); it != testDeque.end(); ++it) { if(it.Value() == 5) { testDeque.Insert(it, 4); break; } } int value = 0; for(auto it = testDeque.begin(); it != testDeque.end(); ++it) { EXPECT_EQ(value + 1, it.Value()); value = it.Value(); } } TEST_F(DequeTest, PopFrontWorks) { testDeque.PopFront(); ASSERT_EQ(2, testDeque.Front()); } TEST_F(DequeTest, PopBackWorks) { testDeque.PopBack(); ASSERT_EQ(3, testDeque.Back()); } TEST_F(DequeTest, EraseWorks) { for(auto it = testDeque.begin(); it != testDeque.end(); ++it) { if(it.Value() == 3) { testDeque.Erase(it); break; } } for(auto it = testDeque.begin(); it != testDeque.end(); ++it) { ASSERT_NE(3, it.Value()); } } TEST_F(DequeTest, GrowWorks) { sprawl::collections::Deque<int> deque2(sprawl::collections::Capacity(5)); for(int i = 50; i < 75; ++i) { deque2.PushBack(i); } for(int i = 49; i > 0; --i) { deque2.PushFront(i); } for(int i = 75; i <= 100; ++i) { deque2.PushBack(i); } int value = 0; EXPECT_EQ(1, deque2.Front()); for(auto& num : deque2) { EXPECT_EQ(value + 1, num); value = num; } ASSERT_EQ(100, deque2.Back()); } TEST_F(DequeTest, NegativeIndexingWorks) { ASSERT_EQ(testDeque[-1], testDeque.Back()); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 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 |
||
#5 | 14168 | ShadauxCat |
-Implemented Array -Fixed compile error when calling Vector::Swap() -Fixed missing constness on functions called from const functions in Deque -Added fill, copy, and move constructor unit tests for Vector and Deque, and Swap() unit test for Vector #review-14169 |
||
#4 | 14146 | ShadauxCat |
Moving a gtest-specific function out of String.hpp #review-14147 |
||
#3 | 14144 | ShadauxCat |
Switching unit tests to gtest. 100 is a decent number of tests to start with, but it needs to be more like 400 to test the current codebase. #review-14145 |
||
#2 | 14121 | ShadauxCat |
-Fixed msvc compile errors (msvc sucks at decltype, btw...) -Fixed BitVector and BitSet being broken on msvc due to 1L being 32-bit rather than 64-bit -Fixed Deque being broken on 32-bit systems due to an errant int64_t -Changed types of deque indexes from size_t to ssize_t; since they have to be signed for a moment to handle circling the buffer, the sign bit is lost for capacity anyway, and using signed indexes means... -Deque and Vector now support negative indexing a la python list #review-14122 |
||
#1 | 14100 | ShadauxCat |
-Added Deque implementation using circular buffer. -Fixed List::Insert() and ForwardList::Insert() inserting after the iterator instead of before it. Adjusted the unit tests to compensate. -Fixed a couple of small vector bugs #review-14101 |