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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
package design.model.statistics;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import design.model.Course;
import design.model.Golfer;
import design.model.Hole;
import design.model.Round;
import design.model.Club.ClubType;
import design.model.Play;
import design.model.Club;
import design.model.Swing;
/** Unit Tests for the Statistics Subsystem
* @author Willem Dalton
**/
@Tag("Model-tier")
public class StatisticsTest {
/* base stats wrapper for testing purposes */
private static class StubStatistics implements Statistics {
private final Golfer golfer;
public StubStatistics(Golfer golfer) {
this.golfer = golfer;
}
@Override
public Round[] getRounds() {
return golfer.getRounds();
}
@Override
public int get_score() {
return Arrays.stream(getRounds())
.mapToInt(Round::getTotalSwings)
.sum();
}
@Override
public double get_distance() {
return Arrays.stream(getRounds())
.mapToDouble(Round::getTotalDistance)
.sum();
}
}
@Test
void testLifeTime()
{
Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback");
Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>());
Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10));
Swing testSwing = new Swing(100, new Club("John Doe Inc", "The Slammer", ClubType.DRIVER));
LifetimeStats stats = new LifetimeStats(testGolfer);
assertNotNull(stats);
assertEquals(0, stats.get_score());
assertEquals(0, stats.get_distance());
ArrayList<Swing> testSwings = new ArrayList<Swing>();
testSwings.add(testSwing);
Play testPlay = new Play(0, testSwings);
testRound.addPlay(testPlay);
testGolfer.addRound(testRound);
assertEquals(1, stats.get_score());
assertEquals(100, stats.get_distance());
}
@Test
void testYearly()
{
Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback");
Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>());
Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10));
Swing testSwing = new Swing(100, new Club("John Doe Inc", "The Slammer", ClubType.DRIVER));
Statistics wrapper = new StubStatistics(testGolfer);
YearlyStats stats = new YearlyStats(wrapper, 2025);
assertNotNull(stats);
assertEquals(0, stats.get_score());
assertEquals(0, stats.get_distance());
ArrayList<Swing> testSwings = new ArrayList<Swing>();
testSwings.add(testSwing);
Play testPlay = new Play(0, testSwings);
testRound.addPlay(testPlay);
testGolfer.addRound(testRound);
assertEquals(1, stats.get_score());
assertEquals(100, stats.get_distance());
}
@Test
void testCourse()
{
Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback");
Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>());
Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10));
Swing testSwing = new Swing(100, new Club("John Doe Inc", "The Slammer", ClubType.DRIVER));
Statistics wrapper = new StubStatistics(testGolfer);
CourseStats stats = new CourseStats(wrapper, testCourse);
assertNotNull(stats);
assertEquals(0, stats.get_score());
assertEquals(0, stats.get_distance());
ArrayList<Swing> testSwings = new ArrayList<Swing>();
testSwings.add(testSwing);
Play testPlay = new Play(0, testSwings);
testRound.addPlay(testPlay);
testGolfer.addRound(testRound);
assertEquals(1, stats.get_score());
assertEquals(100, stats.get_distance());
}
@Test
void testRound()
{
Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback");
Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>());
Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10));
Swing testSwing = new Swing(100, new Club("John Doe Inc", "The Slammer", ClubType.DRIVER));
Statistics wrapper = new StubStatistics(testGolfer);
RoundStats stats = new RoundStats(wrapper, testRound);
assertNotNull(stats);
assertEquals(0, stats.get_score());
assertEquals(0, stats.get_distance());
ArrayList<Swing> testSwings = new ArrayList<Swing>();
testSwings.add(testSwing);
Play testPlay = new Play(0, testSwings);
testRound.addPlay(testPlay);
testGolfer.addRound(testRound);
assertEquals(1, stats.get_score());
assertEquals(100, stats.get_distance());
}
@Test
void testHole()
{
Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback");
Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>());
Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10));
Swing testSwing = new Swing(100, new Club("John Doe Inc", "The Slammer", ClubType.DRIVER));
Hole testHole = new Hole(0, 10);
Statistics wrapper = new StubStatistics(testGolfer);
HoleStats stats = new HoleStats(wrapper, testHole);
assertNotNull(stats);
assertEquals(0, stats.get_score());
assertEquals(0, stats.get_distance());
ArrayList<Swing> testSwings = new ArrayList<Swing>();
testSwings.add(testSwing);
Play testPlay = new Play(0, testSwings);
testRound.addPlay(testPlay);
testGolfer.addRound(testRound);
assertEquals(1, stats.get_score());
assertEquals(100, stats.get_distance());
assertEquals(0, stats.getRounds().length);
}
}
|