-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPositionJUnitTest.java
115 lines (104 loc) · 2.93 KB
/
PositionJUnitTest.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
/**
* Created by KaninJaevel on 16/04/2016.
*/
public class PositionJUnitTest {
/**
* Tests if we able to create a new Position.
* @throws Exception
*/
@Test
public void shouldBeAbleToCreate() throws Exception {
new Position(1,2);
}
/**
* Tests if getX works as intended.
* @throws Exception
*/
@Test
public void shouldBeAbleToGetX() throws Exception {
Position p = new Position(1,2);
assertEquals(p.getX(),1);
}
/**
* Tests if getY works as intended.
* @throws Exception
*/
@Test
public void shouldBeAbleToGetY() throws Exception {
Position p = new Position(1,2);
assertEquals(p.getY(),2);
}
/**
* Tests if getPosToNorth works as intended
* @throws Exception
*/
@Test
public void shouldBeAbleToGetNorth() throws Exception {
Position p = new Position(1,2);
assertEquals(p.getPosToNorth().getX(),1);
assertEquals(p.getPosToNorth().getY(),1);
}
/**
* Tests if getPosToEast works as intended
* @throws Exception
*/
@Test
public void shouldBeAbleToGetEast() throws Exception {
Position p = new Position(1,2);
assertEquals(p.getPosToEast().getX(),2);
assertEquals(p.getPosToEast().getY(),2);
}
/**
* Tests if getPosToSouth works as intended
* @throws Exception
*/
@Test
public void shouldBeAbleToGetSouth() throws Exception {
Position p = new Position(1,2);
assertEquals(p.getPosToSouth().getX(),1);
assertEquals(p.getPosToSouth().getY(),3);
}
/**
* Tests if getPosToWest works as intended
* @throws Exception
*/
@Test
public void shouldBeAbleToGetWest() throws Exception {
Position p = new Position(1,2);
assertEquals(p.getPosToWest().getX(),0);
assertEquals(p.getPosToWest().getY(),2);
}
/**
* Tests if isEqual works as intended
* @throws Exception
*/
@Test
public void shouldBeEquals() throws Exception {
Position p = new Position(1,2);
Position q = new Position(1,2);
p.equals(q);
}
/**
* Tests if isEquals works as intended when
* trying to compare two different Positions.
* @throws Exception
*/
@Test
public void shouldNotBeEquals() throws Exception {
Position p = new Position(1,2);
Position q = new Position(12,22);
if(p.equals(q))
throw new Exception("returned true when expected false");
}
/**
* Tests if hashCode works as intended
* @throws Exception
*/
@Test
public void hashCodeTest(){
Position p = new Position(2,2);
assertEquals(p.hashCode(),37169);
}
}