/
GeographicalLogicProviderTest.java
100 lines (80 loc) · 2.96 KB
/
GeographicalLogicProviderTest.java
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
package business.logicalObjects;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.util.HashSet;
import java.util.Set;
import org.junit.Test;
import business.worldObjects.Resource;
/**
* Test for {@link GeographicalLogicProvider}.
*
* @author Steven Schwenke
*
*/
public class GeographicalLogicProviderTest {
@Test
public void findNearestResourceReturnsNullWhenThereIsNoResource() {
// TODO Think about what to return when there is absolutely no resource
// on the map. Null is bad.
assertNull(GeographicalLogicProvider.findNearestResource(
new CartesianCoordinate(10, 10), new HashSet<Resource>()));
}
@Test
public void findNearestResourceWhenResourceIsOnPosition() {
Set<Resource> resourceSet = new HashSet<Resource>();
Resource resourceOnPlace = new Resource(new CartesianCoordinate(10, 10));
resourceSet.add(resourceOnPlace);
Resource nearestResource = GeographicalLogicProvider
.findNearestResource(new CartesianCoordinate(10, 10),
resourceSet);
assertEquals(resourceOnPlace, nearestResource);
}
@Test
public void findNearestResourceWithTwoResources() {
Set<Resource> resourceSet = new HashSet<Resource>();
Resource r1 = new Resource(new CartesianCoordinate(0, 10));
Resource r2 = new Resource(new CartesianCoordinate(0, 20));
resourceSet.add(r1);
resourceSet.add(r2);
Resource nearestResource = GeographicalLogicProvider
.findNearestResource(new CartesianCoordinate(0, 0), resourceSet);
assertEquals(r1, nearestResource);
}
@Test
public void findNearestResourceWithThreeResources() {
Set<Resource> resourceSet = new HashSet<Resource>();
Resource r1 = new Resource(new CartesianCoordinate(0, 30));
Resource r2 = new Resource(new CartesianCoordinate(0, 20));
Resource r3 = new Resource(new CartesianCoordinate(0, 30));
resourceSet.add(r1);
resourceSet.add(r2);
resourceSet.add(r3);
Resource nearestResource = GeographicalLogicProvider
.findNearestResource(new CartesianCoordinate(0, 0), resourceSet);
assertEquals(r2, nearestResource);
}
@Test
public void calculateDistanceIsZeroGivenTwoEqualCoordinates() {
assertEquals(0, GeographicalLogicProvider.calculateDistance(
new CartesianCoordinate(10, 10),
new CartesianCoordinate(10, 10)), 0.0001);
}
@Test
public void calculateDistanceWorksAtXAxis() {
assertEquals(20, GeographicalLogicProvider.calculateDistance(
new CartesianCoordinate(0, 0), new CartesianCoordinate(20, 0)),
0.0001);
}
@Test
public void calculateDistanceWorksAtYAxis() {
assertEquals(20, GeographicalLogicProvider.calculateDistance(
new CartesianCoordinate(0, 0), new CartesianCoordinate(0, 20)),
0.0001);
}
@Test
public void calculateDistanceWorksAtBothAxis() {
assertEquals(5, GeographicalLogicProvider.calculateDistance(
new CartesianCoordinate(0, 0), new CartesianCoordinate(3, 4)),
0.0001);
}
}