#include "../collections/List.hpp" #include "../collections/ForwardList.hpp" #include "gtest_helpers.hpp" #include <gtest/gtest.h> class ListTest : public testing::Test { protected: virtual void SetUp() override { testList.PushBack(3); testList.PushBack(5); testList.PushFront(2); testList.PushFront(1); } sprawl::collections::List<int> testList; }; TEST_F(ListTest, BasicSetupWorks) { EXPECT_EQ(size_t(4), testList.Size()); auto it = testList.begin(); EXPECT_EQ(1, it.Value()); ++it; EXPECT_EQ(2, it.Value()); ++it; EXPECT_EQ(3, it.Value()); ++it; EXPECT_EQ(5, it.Value()); } TEST_F(ListTest, FrontWorks) { ASSERT_EQ(1, testList.Front()); } TEST_F(ListTest, BackWorks) { ASSERT_EQ(5, testList.Back()); } TEST_F(ListTest, IterationAndInsertWorks) { for(auto it = testList.begin(); it != testList.end(); ++it) { if(it.Value() == 5) { testList.Insert(it, 4); break; } } int value = 0; for(auto it = testList.begin(); it != testList.end(); ++it) { EXPECT_EQ(value + 1, it.Value()); value = it.Value(); } } TEST_F(ListTest, PopFrontWorks) { testList.PopFront(); ASSERT_EQ(2, testList.Front()); } TEST_F(ListTest, PopBackWorks) { testList.PopBack(); ASSERT_EQ(3, testList.Back()); } TEST_F(ListTest, EraseWorks) { for(auto it = testList.begin(); it != testList.end(); ++it) { if(it.Value() == 3) { testList.Erase(it); break; } } for(auto it = testList.begin(); it != testList.end(); ++it) { ASSERT_NE(3, it.Value()); } } class ForwardListTest : public testing::Test { protected: virtual void SetUp() override { testList.PushFront(5); testList.PushFront(3); testList.PushFront(2); testList.PushFront(1); } sprawl::collections::ForwardList<int> testList; }; TEST_F(ForwardListTest, BasicSetupWorks) { EXPECT_EQ(size_t(4), testList.Size()); auto it = testList.begin(); EXPECT_EQ(1, it.Value()); ++it; EXPECT_EQ(2, it.Value()); ++it; EXPECT_EQ(3, it.Value()); ++it; EXPECT_EQ(5, it.Value()); } TEST_F(ForwardListTest, FrontWorks) { ASSERT_EQ(1, testList.Front()); } TEST_F(ForwardListTest, IterationAndInsertWorks) { for(auto it = testList.begin(); it != testList.end(); ++it) { if((it+1).Value() == 5) { testList.InsertAfter(it, 4); break; } } int value = 0; for(auto it = testList.begin(); it != testList.end(); ++it) { EXPECT_EQ(value + 1, it.Value()); value = it.Value(); } } TEST_F(ForwardListTest, PopFrontWorks) { testList.PopFront(); ASSERT_EQ(2, testList.Front()); } TEST_F(ForwardListTest, EraseWorks) { for(auto it = testList.begin(); it != testList.end(); ++it) { if((it+1).Value() == 3) { testList.EraseAfter(it); break; } } for(auto it = testList.begin(); it != testList.end(); ++it) { ASSERT_NE(3, it.Value()); } } TEST_F(ForwardListTest, CopyWorks) { sprawl::collections::ForwardList<int> forwardListCopyTest; forwardListCopyTest.PushFront(1); forwardListCopyTest.PushFront(2); forwardListCopyTest.PushFront(3); forwardListCopyTest.PushFront(4); forwardListCopyTest.PushFront(5); int lastItem = 6; for(auto& item : forwardListCopyTest) { EXPECT_EQ(lastItem - 1, item); lastItem = item; } lastItem = 6; sprawl::collections::ForwardList<int> listCopy(forwardListCopyTest); for(auto& item : listCopy) { EXPECT_EQ(lastItem - 1, item); lastItem = item; } EXPECT_EQ(1, lastItem); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 18645 | brandon_m_bare | Integrated latest version of libsprawl. | ||
#1 | 15089 | brandon_m_bare | First integration of sprawl. | ||
//guest/ShadauxCat/Sprawl/Mainline/UnitTests/UnitTests_List.cpp | |||||
#7 | 14163 | ShadauxCat |
-Renamed HashMap functions to follow coding style. Only begin, end, find, and variants are left lowercase, in keeping with C++ algorithm and range-based for support. -Fixed some accounting issues with list and forwardlist; size wasn't properly being maintained. -Made a small pedantic change to ThreadManager to ensure that m_numThreadsSynced got reset to 0 before the NotifyAll() to eliminate the miniscule potential for deadlock it would cause if it happened after another thread had already woken up. #review-14164 |
||
#6 | 14146 | ShadauxCat |
Moving a gtest-specific function out of String.hpp #review-14147 |
||
#5 | 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 |
||
#4 | 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 |
||
#3 | 14091 | ShadauxCat |
-Created Vector class, iterator, and unit test -Made list iterator a bidirectional iterator when created from a doubly-linked list. (It still has operator-- when created from singly-linked list, but it won't compile if it's used.) -Changed front() and back() in list classes to Front() and Back() #review-14083 |
||
#2 | 14081 | ShadauxCat |
-Switching order of keys and values in HashMap::insert(). Keys now come first - a number of parameters equal to the number of keys. (Simple case is simply insert(key, value)) -Added move constructors to AccessorGroup so things can be inserted into the map via rvalue references -Fixed ForwardList's copy constructor copying things in reverse and added a unit test to make sure it doesn't happen again. #review-14079 |
||
#1 | 11496 | ShadauxCat | Initial checkin: Current states for csbuild and libSprawl |