Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.55 KB | None | 0 0
  1. #include "gtest\gtest.h"
  2. #include "D:\bitbucket repos\for_big_brains\llist\llist.h"
  3.  
  4. TEST(LinkedListTest, pushbackTest) {
  5.     //testing push_back
  6.     llist<int> lst;
  7.     lst.push_back(5);
  8.     EXPECT_EQ(5, lst.back());
  9. }
  10.  
  11. TEST(iterTest, operators) {
  12.     //testing op!= op==
  13.     llist<int> lst;
  14.     for (int i = 0; i < 32; i++) lst.push_back(i * 8);
  15.     llist<int>::iterator it = lst.begin();
  16.     for (int i = 0; i < 4; ++i) ++it;
  17.     llist<int>::iterator it1 = lst.end();
  18.     for (int i = 0; i < 4; ++i) --it1;
  19.     EXPECT_TRUE(it != it1);
  20.     it1 = it;
  21.     EXPECT_EQ(it, it1);
  22.     EXPECT_TRUE(it == it1);
  23.  
  24.     //testing begin, end, op++ op--
  25.     it = lst.begin();
  26.     it1 = lst.end();
  27.     for (int i = 0; i < 16; i++) ++it;
  28.     for (int i = 0; i < 16; i++) --it1;
  29.  
  30.     EXPECT_EQ(it, it1);
  31.  
  32.     //testing one more op++ op--
  33.     it = --lst.end();
  34.     it1 = it++;
  35.     EXPECT_TRUE(++it1 == it);
  36.     EXPECT_EQ(it, lst.end());
  37. }
  38.  
  39. TEST(constIterTest, operators) {
  40.     //testing op!= op==
  41.     llist<int> lst;
  42.     for (int i = 0; i < 32; i++) lst.push_back(i * 8);
  43.     llist<int>::const_iterator it = lst.cbegin();
  44.     for (int i = 0; i < 4; ++i) ++it;
  45.     llist<int>::const_iterator it1 = lst.cend();
  46.     for (int i = 0; i < 4; ++i) --it1;
  47.     EXPECT_TRUE(it != it1);
  48.     it1 = it;
  49.     EXPECT_EQ(it, it1);
  50.     EXPECT_TRUE(it == it1);
  51.  
  52.     //testing cbegin, cend, op++ op--
  53.     it = lst.cbegin();
  54.     it1 = lst.cend();
  55.     for (int i = 0; i < 16; i++) ++it;
  56.     for (int i = 0; i < 16; i++) --it1;
  57.  
  58.     EXPECT_EQ(it, it1);
  59.  
  60.     //testing one more op++ op--
  61.     it = --lst.cend();
  62.     it1 = it++;
  63.     EXPECT_TRUE(++it1 == it);
  64.     EXPECT_EQ(it, lst.cend());
  65. }
  66.  
  67. TEST(LinkedListTest, operators) {
  68.     llist<int> lst;
  69.     for (int i = 0; i < 32; i++) lst.push_back(i * 8);
  70.     llist<int> second;
  71.  
  72.     second = lst;
  73.     llist<int>::iterator a, b;
  74.     a = lst.begin();
  75.     b = second.begin();
  76.     while (a != lst.end() && b != second.end()) {
  77.         EXPECT_EQ(*a, *b);
  78.         ++a;
  79.         ++b;
  80.     }
  81.     EXPECT_TRUE(a == lst.end() && b == second.end());
  82.  
  83. }
  84.  
  85. TEST(LinkedListTest, constructors) {
  86.     //mv constructor testing
  87.     auto x = []() -> llist<int> {
  88.         llist<int> a;
  89.         for (int i = 0; i < 16; i++) {
  90.             a.push_back(i);
  91.         }
  92.         return a;
  93.     };
  94.     llist<int> lst = x();
  95.     {
  96.         llist<int>::iterator it = lst.begin();
  97.         for (int i = 0; i < 16; i++) {
  98.             EXPECT_EQ(*it, i);
  99.             ++it;
  100.         }
  101.     }
  102.     //cpy constructor testing
  103.     llist<int> lst1 = lst;
  104.     EXPECT_TRUE(lst == lst1);
  105.    
  106.     lst1.clear();
  107.     //mv construct + mv op
  108.     lst1 = x();
  109.     {
  110.         llist<int>::iterator it = lst1.begin();
  111.         for (int i = 0; i < 16; i++) {
  112.             EXPECT_EQ(*it, i);
  113.             ++it;
  114.         }
  115.     }
  116.  
  117.     lst1.clear();
  118.     //eq op
  119.     lst1 = lst;
  120.     EXPECT_TRUE(lst1 == lst);
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement