forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestVector.cpp
45 lines (38 loc) 路 1 KB
/
TestVector.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
#include "TestHelpers.h"
#include <AK/AKString.h>
#include <AK/Vector.h>
int main()
{
EXPECT(Vector<int>().is_empty());
EXPECT(Vector<int>().size() == 0);
Vector<int> ints;
ints.append(1);
ints.append(2);
ints.append(3);
EXPECT_EQ(ints.size(), 3);
EXPECT_EQ(ints.take_last(), 3);
EXPECT_EQ(ints.size(), 2);
EXPECT_EQ(ints.take_last(), 2);
EXPECT_EQ(ints.size(), 1);
EXPECT_EQ(ints.take_last(), 1);
EXPECT_EQ(ints.size(), 0);
ints.clear();
EXPECT_EQ(ints.size(), 0);
Vector<String> strings;
strings.append("ABC");
strings.append("DEF");
int loop_counter = 0;
for (const String& string : strings) {
EXPECT(!string.is_null());
EXPECT(!string.is_empty());
++loop_counter;
}
loop_counter = 0;
for (auto& string : (const_cast<const Vector<String>&>(strings))) {
EXPECT(!string.is_null());
EXPECT(!string.is_empty());
++loop_counter;
}
EXPECT_EQ(loop_counter, 2);
return 0;
}