-
Notifications
You must be signed in to change notification settings - Fork 6
/
int_array_list_test.cpp
47 lines (42 loc) · 1.24 KB
/
int_array_list_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
//
// Created by qiuzhenxuan on 2023/11/27.
//
#include "../int_array_list.h"
#include "gtest/gtest.h"
#include <random>
// Demonstrate some basic assertions.
TEST(IntArrayListTest, Features) {
int min = INT_MIN, max = INT_MAX;
std::random_device seed;
std::ranlux48 engine(seed());
std::uniform_int_distribution<> distrib(min, max);
auto v = new std::vector<int>();
auto list = new int_array_list();
for (int i = 0; i < (1 << 8); i++) {
int value = distrib(engine);
v->push_back(value);
list->add(value);
}
EXPECT_EQ(v->size(), list->get_size());
for (int i = 0; i < v->size(); i++) {
EXPECT_EQ(v->at(i), list->get(i));
}
for (int i = 0; i < (1 << 6); ++i) {
int index = abs(distrib(engine)) % (int)v->size();
v->erase(v->begin() + index);
list->removeAt(index);
}
EXPECT_EQ(v->size(), list->get_size());
for (int i = 0; i < v->size(); i++) {
EXPECT_EQ(v->at(i), list->get(i));
}
for (int i = 0; i < (1 << 6); ++i) {
int index = abs(distrib(engine)) % (int)v->size();
v->erase(std::remove(v->begin(), v->end(), v->at(index)));
list->remove(list->get(index));
}
EXPECT_EQ(v->size(), list->get_size());
for (int i = 0; i < v->size(); i++) {
EXPECT_EQ(v->at(i), list->get(i));
}
}