-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_solution.cpp
More file actions
50 lines (39 loc) · 1.19 KB
/
test_solution.cpp
File metadata and controls
50 lines (39 loc) · 1.19 KB
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
#include <vector>
#include <preloaded.h>
#include <catch2/catch_test_macros.hpp>
TEST_CASE( "vectors can be sized and resized" ) {
// For each section, vector v is anew:
std::vector<int> v( 5 );
REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 5 );
SECTION( "resizing bigger changes size and capacity" ) {
v.resize( 10 );
REQUIRE( v.size() == 10 );
REQUIRE( v.capacity() >= 10 );
}
SECTION( "resizing smaller changes size but not capacity" ) {
v.resize( 0 );
REQUIRE( v.size() == 0 );
REQUIRE( v.capacity() >= 5 );
}
SECTION( "reserving bigger changes capacity but not size" ) {
v.reserve( 10 );
REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 10 );
}
SECTION( "reserving smaller does not change size or capacity" ) {
v.reserve( 0 );
REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 5 );
}
}
TEST_CASE("Counter") {
SECTION("Decrement") {
Counter c;
REQUIRE(c.Decrement() == 0);
REQUIRE(c.Increment() == 0);
REQUIRE(c.Increment() == 1);
REQUIRE(c.Increment() == 2);
REQUIRE(c.Decrement() == 3);
}
}