Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "gtest\gtest.h"
- #include "D:\bitbucket repos\for_big_brains\llist\llist.h"
- TEST(LinkedListTest, pushbackTest) {
- //testing push_back
- llist<int> lst;
- lst.push_back(5);
- EXPECT_EQ(5, lst.back());
- }
- TEST(iterTest, operators) {
- //testing op!= op==
- llist<int> lst;
- for (int i = 0; i < 32; i++) lst.push_back(i * 8);
- llist<int>::iterator it = lst.begin();
- for (int i = 0; i < 4; ++i) ++it;
- llist<int>::iterator it1 = lst.end();
- for (int i = 0; i < 4; ++i) --it1;
- EXPECT_TRUE(it != it1);
- it1 = it;
- EXPECT_EQ(it, it1);
- EXPECT_TRUE(it == it1);
- //testing begin, end, op++ op--
- it = lst.begin();
- it1 = lst.end();
- for (int i = 0; i < 16; i++) ++it;
- for (int i = 0; i < 16; i++) --it1;
- EXPECT_EQ(it, it1);
- //testing one more op++ op--
- it = --lst.end();
- it1 = it++;
- EXPECT_TRUE(++it1 == it);
- EXPECT_EQ(it, lst.end());
- }
- TEST(constIterTest, operators) {
- //testing op!= op==
- llist<int> lst;
- for (int i = 0; i < 32; i++) lst.push_back(i * 8);
- llist<int>::const_iterator it = lst.cbegin();
- for (int i = 0; i < 4; ++i) ++it;
- llist<int>::const_iterator it1 = lst.cend();
- for (int i = 0; i < 4; ++i) --it1;
- EXPECT_TRUE(it != it1);
- it1 = it;
- EXPECT_EQ(it, it1);
- EXPECT_TRUE(it == it1);
- //testing cbegin, cend, op++ op--
- it = lst.cbegin();
- it1 = lst.cend();
- for (int i = 0; i < 16; i++) ++it;
- for (int i = 0; i < 16; i++) --it1;
- EXPECT_EQ(it, it1);
- //testing one more op++ op--
- it = --lst.cend();
- it1 = it++;
- EXPECT_TRUE(++it1 == it);
- EXPECT_EQ(it, lst.cend());
- }
- TEST(LinkedListTest, operators) {
- llist<int> lst;
- for (int i = 0; i < 32; i++) lst.push_back(i * 8);
- llist<int> second;
- second = lst;
- llist<int>::iterator a, b;
- a = lst.begin();
- b = second.begin();
- while (a != lst.end() && b != second.end()) {
- EXPECT_EQ(*a, *b);
- ++a;
- ++b;
- }
- EXPECT_TRUE(a == lst.end() && b == second.end());
- }
- TEST(LinkedListTest, constructors) {
- //mv constructor testing
- auto x = []() -> llist<int> {
- llist<int> a;
- for (int i = 0; i < 16; i++) {
- a.push_back(i);
- }
- return a;
- };
- llist<int> lst = x();
- {
- llist<int>::iterator it = lst.begin();
- for (int i = 0; i < 16; i++) {
- EXPECT_EQ(*it, i);
- ++it;
- }
- }
- //cpy constructor testing
- llist<int> lst1 = lst;
- EXPECT_TRUE(lst == lst1);
- lst1.clear();
- //mv construct + mv op
- lst1 = x();
- {
- llist<int>::iterator it = lst1.begin();
- for (int i = 0; i < 16; i++) {
- EXPECT_EQ(*it, i);
- ++it;
- }
- }
- lst1.clear();
- //eq op
- lst1 = lst;
- EXPECT_TRUE(lst1 == lst);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement