-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
65 lines (57 loc) · 2.74 KB
/
main.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
#include <iomanip>
#include <iostream>
#include "ItemCollection.hpp"
// Helper Class Definitions
struct AssertEquals {
template <typename T, typename U>
void operator() (
const std::string & test_name,
const T & expected,
const U & actual,
bool equality_test = true
)
{
if( (actual == expected) == equality_test ) {
std::cout << "[PASSED] " << test_name << ": ";
std::cout << "Expected " << expected << " and received: " << actual << '\n';
}
else {
std::cout << "[FAILED] " << test_name << " - Expected: \"" << expected << "\" to "
<< ( equality_test ? "match " : "not match ")
<< "Actual: \"" << actual << "\"\n";
}
}
};
int main() {
AssertEquals assertEquals; // test hash functions
assertEquals( "hash_function1(1234567)", 1U, hash_function1(1234567U) );
assertEquals( "hash_function2(1234567)", 2U, hash_function2(1234567U) );
assertEquals( "hash_function3(1234567)", 3U, hash_function3(1234567U) );
assertEquals( "hash_function4(1234567)", 4U, hash_function4(1234567U) );
assertEquals( "hash_function5(1234567)", 5U, hash_function5(1234567U) );
assertEquals( "hash_function6(1234567)", 6U, hash_function6(1234567U) );
assertEquals( "hash_function7(1234567)", 7U, hash_function7(1234567U) );
assertEquals( "hash_function1(6789012)", 6U, hash_function1(6789012U) );
assertEquals( "hash_function2(6789012)", 7U, hash_function2(6789012U) );
assertEquals( "hash_function3(6789012)", 8U, hash_function3(6789012U) );
assertEquals( "hash_function4(6789012)", 9U, hash_function4(6789012U) );
assertEquals( "hash_function5(6789012)", 0U, hash_function5(6789012U) );
assertEquals( "hash_function6(6789012)", 1U, hash_function6(6789012U) );
assertEquals( "hash_function7(6789012)", 2U, hash_function7(6789012U) );
ItemCollection itemCollection;
itemCollection.addItem("red", "butterfly", "smooth", 1234567U);
itemCollection.addItem("pink", "butterfly", "smooth", 2345678U);
assertEquals( "size after adding two bows", 2U, itemCollection.size() );
ItemCollection pairs1;
pairs1.readTextfile("in1.txt");
assertEquals( "size after reading in1.txt", 18U, pairs1.size() );
assertEquals( "bestHashing() for in1.txt", 2U, pairs1.bestHashing() );
ItemCollection pairs2;
pairs2.readTextfile("in2.txt");
assertEquals( "size after reading in2.txt", 36U, pairs2.size() );
assertEquals( "bestHashing() for in2.txt", 3U, pairs2.bestHashing() );
pairs2.removeItem(8890123);
assertEquals( "size after removing 8890123", 35U, pairs2.size() );
assertEquals( "bestHashing() after removing 8890123", 4U, pairs2.bestHashing() );
return 1;
}