-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathdatafile_test.cpp
More file actions
54 lines (43 loc) · 1.06 KB
/
datafile_test.cpp
File metadata and controls
54 lines (43 loc) · 1.06 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
51
52
53
54
#include "datafile.hpp"
#include <cassert>
#include <iostream>
using namespace std;
int main() {
cout << "==== datafile.hpp ====" << endl;
cout << "Missing file" << endl;
{
bool threw = false;
try {
load_products("not a filename");
} catch (runtime_error e) {
threw = true;
}
assert(threw);
}
cout << "Invalid file format" << endl;
{
bool threw = false;
try {
load_products("datafile.hpp");
} catch (runtime_error e) {
threw = true;
}
assert(threw);
}
cout << "Loading works" << endl;
Catalog* c = load_products("products.dat");
assert(c != nullptr);
cout << "Contents looks right" << endl;
{
const Product& p1 = c->findCode("00012000039287");
assert(p1.getName() == "BRISK JUICE DRINK LEMONADE");
assert(p1.getCode() == "00012000039287");
assert(p1.getPrice() == 4.44);
const Product& p2 = c->findCode("4440");
assert(p2.getName() == "PLUMS - TREE RIPENED");
assert(p2.getCode() == "4440");
assert(p2.getPrice() == 1.83);
}
delete c;
return 0;
}