From 0e4478817d43b7e2071de5917f85686356c3399b Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Sun, 16 Nov 2014 01:31:16 +0100 Subject: [PATCH] Written IdListTest --- src/test/fspp/MyTest2.cpp | 10 ---- src/test/fspp/impl/IdListTest.cpp | 81 +++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 10 deletions(-) delete mode 100644 src/test/fspp/MyTest2.cpp create mode 100644 src/test/fspp/impl/IdListTest.cpp diff --git a/src/test/fspp/MyTest2.cpp b/src/test/fspp/MyTest2.cpp deleted file mode 100644 index 1dae9103..00000000 --- a/src/test/fspp/MyTest2.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "gtest/gtest.h" - -TEST(MyTest2, testfunc) { - EXPECT_EQ(1,1); -} - -TEST(MyTest2, testfunc2) { - EXPECT_EQ(1,1); -} - diff --git a/src/test/fspp/impl/IdListTest.cpp b/src/test/fspp/impl/IdListTest.cpp new file mode 100644 index 00000000..513593f5 --- /dev/null +++ b/src/test/fspp/impl/IdListTest.cpp @@ -0,0 +1,81 @@ +#include "gtest/gtest.h" + +#include "fspp/impl/IdList.h" +#include + +using std::make_unique; + +using namespace fspp; + +class MyObj { +public: + MyObj(int val_): val(val_) {} + int val; +}; + +TEST(IdListTest, EmptyList1) { + IdList list; + ASSERT_THROW(list.get(0), std::out_of_range); +} + +TEST(IdListTest, EmptyList2) { + IdList list; + ASSERT_THROW(list.get(3), std::out_of_range); +} + +TEST(IdListTest, InvalidId) { + IdList list; + int valid_id = list.add(make_unique(6)); + int invalid_id = valid_id + 1; + ASSERT_THROW(list.get(invalid_id), std::out_of_range); +} + +TEST(IdListTest, GetRemovedItemOnEmptyList) { + IdList list; + int id = list.add(make_unique(6)); + list.remove(id); + ASSERT_THROW(list.get(id), std::out_of_range); +} + +TEST(IdListTest, GetRemovedItemOnNonEmptyList) { + IdList list; + int id = list.add(make_unique(6)); + list.add(make_unique(5)); + list.remove(id); + ASSERT_THROW(list.get(id), std::out_of_range); +} + +TEST(IdListTest, Add1AndGet) { + IdList list; + int id6 = list.add(make_unique(6)); + EXPECT_EQ(6, list.get(id6)->val); +} + +TEST(IdListTest, Add2AndGet) { + IdList list; + int id4 = list.add(make_unique(4)); + int id5 = list.add(make_unique(5)); + EXPECT_EQ(4, list.get(id4)->val); + EXPECT_EQ(5, list.get(id5)->val); +} + +TEST(IdListTest, Add3AndGet) { + IdList list; + int id4 = list.add(make_unique(4)); + int id10 = list.add(make_unique(10)); + int id1 = list.add(make_unique(1)); + EXPECT_EQ(10, list.get(id10)->val); + EXPECT_EQ(4, list.get(id4)->val); + EXPECT_EQ(1, list.get(id1)->val); +} + +TEST(IdListTest, Add3AndConstGet) { + IdList list; + int id4 = list.add(make_unique(4)); + int id10 = list.add(make_unique(10)); + int id1 = list.add(make_unique(1)); + const IdList &const_list = list; + EXPECT_EQ(10, const_list.get(id10)->val); + EXPECT_EQ(4, const_list.get(id4)->val); + EXPECT_EQ(1, const_list.get(id1)->val); +}