Commit 82556f34 authored by Florian Klemme's avatar Florian Klemme
Browse files

Tests korregiert und erweitert.

parent 16f2dcad
Pipeline #73 passed with stages
in 2 minutes
......@@ -19,8 +19,8 @@ TEST(CppKlausur, Beispiel1) {
std::string target, actual;
while (std::getline(target_output, target)) {
ASSERT_TRUE(std::getline(output, actual));
ASSERT_EQ(target, actual);
ASSERT_EQ(actual, target);
}
ASSERT_FALSE(std::getline(output, actual));
ASSERT_FALSE(std::getline(output, actual)); // output leer
}
\ No newline at end of file
......@@ -4,19 +4,19 @@
TEST(Map, access) {
Map<char, int> m1;
ASSERT_EQ(0, m1.size());
ASSERT_EQ(m1.size(), 0);
m1['a'] = 5;
ASSERT_EQ(1, m1.size());
ASSERT_EQ(5, m1['a']);
ASSERT_EQ(1, m1.count('a'));
ASSERT_EQ(0, m1.count('b'));
ASSERT_EQ(m1.size(), 1);
ASSERT_EQ(m1['a'], 5);
ASSERT_TRUE(m1.contains('a'));
ASSERT_FALSE(m1.contains('b'));
m1['b'] = 3;
ASSERT_EQ(2, m1.size());
ASSERT_EQ(3, m1['b']);
ASSERT_EQ(1, m1.count('a'));
ASSERT_EQ(1, m1.count('b'));
ASSERT_EQ(m1.size(), 2);
ASSERT_EQ(m1['b'], 3);
ASSERT_TRUE(m1.contains('a'));
ASSERT_TRUE(m1.contains('b'));
}
TEST(Map, erase) {
......@@ -24,28 +24,30 @@ TEST(Map, erase) {
m1['a'] = 5;
m1['b'] = 3;
m1['c'] = 7;
ASSERT_EQ(3, m1.size());
ASSERT_EQ(m1.size(), 3);
ASSERT_TRUE(m1.contains('b'));
m1.erase('b');
ASSERT_FALSE(m1.contains('b'));
ASSERT_EQ(2, m1.size());
ASSERT_EQ(m1.size(), 2);
ASSERT_TRUE(m1.contains('a'));
m1.erase('a');
ASSERT_FALSE(m1.contains('a'));
ASSERT_EQ(1, m1.size());
ASSERT_EQ(m1.size(), 1);
m1['a'] = 13;
ASSERT_EQ(2, m1.size());
ASSERT_EQ(m1.size(), 2);
ASSERT_TRUE(m1.contains('c'));
m1.erase('c');
ASSERT_FALSE(m1.contains('c'));
ASSERT_EQ(1, m1.size());
ASSERT_EQ(m1.size(), 1);
ASSERT_TRUE(m1.contains('a'));
m1.erase('a');
ASSERT_FALSE(m1.contains('a'));
ASSERT_EQ(0, m1.size());
ASSERT_EQ(m1.size(), 0);
ASSERT_ANY_THROW(m1.erase('z')); // out of range
}
\ No newline at end of file
......@@ -6,36 +6,36 @@
TEST(String, Create) {
String s1;
ASSERT_EQ(0, s1.size());
ASSERT_GE(0, s1.capacitance());
ASSERT_EQ(s1.size(), 0);
ASSERT_EQ(s1.capacitance(), 0);
auto cstring = "test";
String s2(cstring);
ASSERT_EQ(4, s2.size());
ASSERT_GE(4, s2.capacitance());
ASSERT_EQ('t', s2[0]);
ASSERT_EQ('e', s2[1]);
ASSERT_EQ('s', s2[2]);
ASSERT_EQ('t', s2[3]);
ASSERT_EQ(s2.size(), 4);
ASSERT_GE(s2.capacitance(), 4);
ASSERT_EQ(s2[0], 't');
ASSERT_EQ(s2[1], 'e');
ASSERT_EQ(s2[2], 's');
ASSERT_EQ(s2[3], 't');
}
TEST(String, Copy) {
auto cstring = "test";
String s1(cstring);
ASSERT_EQ(4, s1.size());
ASSERT_GE(4, s1.capacitance());
ASSERT_EQ('t', s1[0]);
ASSERT_EQ('e', s1[1]);
ASSERT_EQ('s', s1[2]);
ASSERT_EQ('t', s1[3]);
ASSERT_EQ(s1.size(), 4);
ASSERT_GE(s1.capacitance(), 4);
ASSERT_EQ(s1[0], 't');
ASSERT_EQ(s1[1], 'e');
ASSERT_EQ(s1[2], 's');
ASSERT_EQ(s1[3], 't');
String s2 = s1;
ASSERT_EQ(4, s2.size());
ASSERT_GE(4, s2.capacitance());
ASSERT_EQ('t', s2[0]);
ASSERT_EQ('e', s2[1]);
ASSERT_EQ('s', s2[2]);
ASSERT_EQ('t', s2[3]);
ASSERT_EQ(s2.size(), 4);
ASSERT_GE(s2.capacitance(), 4);
ASSERT_EQ(s2[0], 't');
ASSERT_EQ(s2[1], 'e');
ASSERT_EQ(s2[2], 's');
ASSERT_EQ(s2[3], 't');
}
TEST(String, Output) {
......
......@@ -4,12 +4,12 @@
TEST(Vector, Create) {
Vector<int> v1;
ASSERT_EQ(0, v1.capacitance());
ASSERT_EQ(0, v1.size());
ASSERT_EQ(v1.capacitance(), 0);
ASSERT_EQ(v1.size(), 0);
Vector<int> v2(5);
ASSERT_EQ(5, v2.capacitance());
ASSERT_EQ(0, v2.size());
ASSERT_EQ(v2.capacitance(), 5);
ASSERT_EQ(v2.size(), 0);
}
TEST(Vector, Copy) {
......@@ -17,31 +17,64 @@ TEST(Vector, Copy) {
v1.push_back(4);
v1.push_back(2);
v1.push_back(0);
ASSERT_EQ(3, v1.size());
ASSERT_GE(3, v1.capacitance());
ASSERT_EQ(v1.size(), 3);
ASSERT_GE(v1.capacitance(), 3);
auto v2 = v1;
ASSERT_EQ(v1.size(), v2.size());
ASSERT_GE(v2.size(), v2.capacitance());
ASSERT_GE(v2.capacitance(), v2.size());
for (int i = 0; i < v1.size(); ++i) ASSERT_EQ(v1[i], v2[i]);
}
TEST(Vector, push_back) {
Vector<int> v1;
ASSERT_EQ(0, v1.size());
ASSERT_EQ(v1.size(), 0);
v1.push_back(4);
ASSERT_EQ(1, v1.size());
ASSERT_EQ(4, v1[0]);
ASSERT_EQ(v1.size(), 1);
ASSERT_EQ(v1[0], 4);
v1.push_back(2);
ASSERT_EQ(2, v1.size());
ASSERT_EQ(2, v1[1]);
ASSERT_EQ(v1.size(), 2);
ASSERT_EQ(v1[1], 2);
v1.push_back(0);
ASSERT_EQ(3, v1.size());
ASSERT_EQ(0, v1[2]);
ASSERT_GE(3, v1.capacitance());
ASSERT_EQ(v1.size(), 3);
ASSERT_EQ(v1[2], 0);
ASSERT_GE(v1.capacitance(), 3);
}
TEST(Vector, insert) {
Vector<int> v1;
v1.push_back(4);
v1.push_back(2);
v1.push_back(0);
ASSERT_EQ(v1.size(), 3);
ASSERT_GE(v1.capacitance(), 3);
ASSERT_EQ(v1[0], 4);
ASSERT_EQ(v1[1], 2);
ASSERT_EQ(v1[2], 0);
v1.insert(1, 5);
ASSERT_EQ(v1.size(), 4);
ASSERT_GE(v1.capacitance(), 4);
ASSERT_EQ(v1[0], 4);
ASSERT_EQ(v1[1], 5);
ASSERT_EQ(v1[2], 2);
ASSERT_EQ(v1[3], 0);
// Am Ende einfuegen geht auch (index == size)
v1.insert(4, 42);
ASSERT_EQ(v1.size(), 5);
ASSERT_GE(v1.capacitance(), 5);
ASSERT_EQ(v1[0], 4);
ASSERT_EQ(v1[1], 5);
ASSERT_EQ(v1[2], 2);
ASSERT_EQ(v1[3], 0);
ASSERT_EQ(v1[4], 42);
ASSERT_ANY_THROW(v1.insert(10, 5)); // out of range
}
TEST(Vector, erase) {
......@@ -49,24 +82,26 @@ TEST(Vector, erase) {
v1.push_back(4);
v1.push_back(2);
v1.push_back(0);
ASSERT_EQ(3, v1.size());
ASSERT_GE(3, v1.capacitance());
ASSERT_EQ(4, v1[0]);
ASSERT_EQ(2, v1[1]);
ASSERT_EQ(0, v1[2]);
ASSERT_EQ(v1.size(), 3);
ASSERT_GE(v1.capacitance(), 3);
ASSERT_EQ(v1[0], 4);
ASSERT_EQ(v1[1], 2);
ASSERT_EQ(v1[2], 0);
v1.erase(1);
ASSERT_EQ(2, v1.size());
ASSERT_EQ(4, v1[0]);
ASSERT_EQ(0, v1[1]);
ASSERT_EQ(v1.size(), 2);
ASSERT_EQ(v1[0], 4);
ASSERT_EQ(v1[1], 0);
v1.push_back(12);
v1.erase(0);
ASSERT_EQ(2, v1.size());
ASSERT_EQ(0, v1[0]);
ASSERT_EQ(12, v1[1]);
ASSERT_EQ(v1.size(), 2);
ASSERT_EQ(v1[0], 0);
ASSERT_EQ(v1[1], 12);
v1.erase(1);
v1.erase(0);
ASSERT_EQ(0, v1.size());
ASSERT_EQ(v1.size(), 0);
ASSERT_ANY_THROW(v1.erase(2)); // out of range
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment