forked from ucsb-cs24-mirza-s21/lab03_data
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.cpp
76 lines (62 loc) · 1.44 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "list.hpp"
#include <array>
#include <random>
#include <iostream>
#include <gtest/gtest.h>
constexpr auto TEST_SEEDER = 389248924;
template<>
size_t Node<int>::alloc_cnt=0;
#define ASSERT_SIZE(ls, expectedSize) \
ASSERT_EQ(ls.size(),expectedSize)
#define EXPECT_EMPTY(ls) \
EXPECT_TRUE(ls.empty())
#define ASSERT_EMPTY(ls) \
ASSERT_TRUE(ls.empty())
// test cases start from here.
TEST(Empty, Accessors){
List<int> ls;
EXPECT_EMPTY(ls);
}
TEST(Empty, CopyConstruct){
List<int> ls;
ASSERT_EMPTY(ls);
List<int> ls2(ls);
ASSERT_EMPTY(ls);
EXPECT_EMPTY(ls2);
}
TEST(Empty, Insert){
int testConst1 = 14;
List<int> ls;
ASSERT_EMPTY(ls);
ls.insert(0,testConst1);
ASSERT_SIZE(ls,1);
EXPECT_EQ(ls.front(),testConst1);
EXPECT_EQ(ls.back(),testConst1);
EXPECT_EQ(ls.at(0),testConst1);
}
TEST(Empty, PushFront){
int testConst1 = 31;
List<int> ls;
ASSERT_EMPTY(ls);
ls.push_front(testConst1);
ASSERT_SIZE(ls,1);
EXPECT_EQ(ls.front(),testConst1);
EXPECT_EQ(ls.back(),testConst1);
EXPECT_EQ(ls.at(0),testConst1);
}
TEST(Empty, PushBack){
int testConst1 = 42;
List<int> ls;
ASSERT_EMPTY(ls);
ls.push_back(testConst1);
ASSERT_SIZE(ls,1);
EXPECT_EQ(ls.front(),testConst1);
EXPECT_EQ(ls.back(),testConst1);
EXPECT_EQ(ls.at(0),testConst1);
}
TEST(Empty, Clear){
List<int> ls;
ASSERT_EMPTY(ls);
ls.clear();
EXPECT_EMPTY(ls);
}