-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_scoop.cpp
More file actions
95 lines (82 loc) · 3.13 KB
/
test_scoop.cpp
File metadata and controls
95 lines (82 loc) · 3.13 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "test_scoop.h"
#include "scoop.h"
#include <iostream>
#include <sstream>
bool test_scoop() {
std::string expected = "";
bool passed = true; // Optimist!
//
// Test constructor
//
std::string x_name = "Fudge Ripple";
std::string x_description = "Chocolatey goodness in vanilla swirl";
double x_cost = 0.75;
double x_price = 1.50;
Mice::Scoop scoop{x_name, x_description, x_cost, x_price};
std::ostringstream os;
os << scoop;
if (os.str() != " Scoop: Fudge Ripple $1.50") {
std::cerr << "#### Scoop operator<< fail" << std::endl;
std::cerr << "Expected: Scoop: Fudge Ripple $1.50" << std::endl;
std::cerr << "Actual: " << os.str() << std::endl;
}
if (scoop.name() != x_name ||
scoop.description() != x_description ||
scoop.cost() != x_cost ||
scoop.price() != x_price ||
scoop.type() != "Scoop" ||
scoop.quantity() != 0) {
std::cerr << "#### Scoop constructor fail" << std::endl;
std::cerr << "Expected: " << x_name << ','
<< x_description << ','
<< x_cost << ','
<< x_price << ','
<< "Scoop" << ','
<< '0' << std::endl;
std::cerr << "Actual: " << scoop.name() << ','
<< scoop.description() << ','
<< scoop.cost() << ','
<< scoop.price() << ','
<< scoop.type() << ','
<< scoop.quantity() << std::endl;
passed = false;
}
// Test I/O
std::ostringstream ost;
scoop.save(ost);
std::istringstream ist{ost.str()};
std::string header1, header2;
getline(ist, header1);
getline(ist, header2);
if (header1 != "#" && header2 != "SCOOP") {
std::cerr << "#### Scoop I/O fail" << std::endl;
std::cerr << "Expected header: '#' and 'SCOOP'" << std::endl;
std::cerr << "Actual header: '" << header1 << "' and '" << header2 << "'" << std::endl;
}
Mice::Scoop clone{ist};
if (scoop.name() != clone.name() ||
scoop.description() != clone.description() ||
scoop.cost() != clone.cost() ||
scoop.price() != clone.price() ||
scoop.type() != clone.type() ||
scoop.quantity() != clone.quantity()) {
std::cerr << "#### Scoop constructor fail" << std::endl;
std::cerr << "Expected: " << scoop.name() << ','
<< scoop.description() << ','
<< scoop.cost() << ','
<< scoop.price() << ','
<< scoop.type() << ','
<< scoop.quantity() << std::endl;
std::cerr << "Actual: " << clone.name() << ','
<< clone.description() << ','
<< clone.cost() << ','
<< clone.price() << ','
<< clone.type() << ','
<< clone.quantity() << std::endl;
passed = false;
}
//
// Report results
//
return passed;
}