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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
// filename: testPlatypus.cpp
// summary: print out the paltypus
#include "platypus.h"
#include <iostream>
using namespace std;
// The testing suite is pretty much 50-50 between us. (Ricky and Zoltan)
int main() {
// Test `Platypus` constructors, setters, getters, `eat`ing, aging, and
// `print`ing
{
// Test constructors
Platypus p1;
Platypus p2(23.5, 5, "Perry", "m");
Platypus p3(2, 3, "Pearl", "f");
std::cout << "Platypus #1 after birth(default constructor):\n" << std::endl;
// Test `print`
p1.print();
std::cout << "\nPlatypus #3 after birth(established constructor):\n"
<< std::endl;
p3.print();
// Test setters
p1.setWeight(25.7f);
p1.setAge(4);
p1.setName("Optimus");
p1.setGender("m");
p1.setAlive(true);
p1.setMutant(false);
std::cout << "\nPlatypus #1 after changes to weight, age, name, gender, "
"alive, mutant:\n"
<< std::endl;
p1.print();
// Test getters
cout << "\nPlatypus #1 weight before eating: " << p1.getWeight() << endl;
// Test `eat`ing
p1.eat();
cout << "Platypus #1 weight after eating: " << p1.getWeight()
<< "\n\nPlatypus #1 before aging: " << p1.getAge()
<< ", old mutant status: " << p1.getMutant()
<< ", old alive status: " << p1.getAlive()
<< "\nPlatypus #3 before aging: " << p3.getAge()
<< ", old mutant status: " << p3.getMutant()
<< ", old alive status: " << p3.getAlive() << endl;
// Test aging
p1.ageMe();
p3.ageMe();
cout << "\nPlatypus #1 after aging: " << p1.getAge()
<< ", new mutant status: " << p1.getMutant()
<< ", new alive status: " << p1.getAlive() << '\n'
<< "Platypus #3 after aging: " << p3.getAge()
<< ", new mutant status: " << p3.getMutant()
<< ", new alive status: " << p3.getAlive() << endl
<< endl;
}
// Test `Platypus` `fight`ing and `hatch`ing
{
Platypus p1(22.8f, 4, "John", "m");
Platypus p2(23.5, 5, "Perry", "m");
std::cout << "New platypus #1 before fight:\n" << std::endl;
p1.print();
std::cout << "\nPlatypus #2 before fight:\n" << std::endl;
p2.print();
// Test `fight`
p1.fight(p2);
std::cout << "\nNew platypus #1 after fight:\n" << std::endl;
p1.print();
std::cout << "\nPlatypus #2 after fight:\n" << std::endl;
p2.print();
std::cout << "\nPlatypus #3 hatched a platypus:\n" << endl;
// Test hatch
Platypus p3(1, 2, "Becky", "f");
Platypus hatched = p3.hatch();
hatched.print();
if (hatched.getWeight() < 1e-8f) {
std::cout << "\nThe hatched platypus looks to be dead, since the "
"platypus birthing it was dead too."
<< std::endl;
}
std::cout << "\nJust to test `getName` and `getGender`, here's the name "
"and gender of the hatched platypus: "
<< hatched.getName() << ", " << hatched.getGender() << std::endl;
}
return 0;
}
|