-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocationTest.java
More file actions
83 lines (76 loc) · 2.27 KB
/
Copy pathLocationTest.java
File metadata and controls
83 lines (76 loc) · 2.27 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
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* Test implementation of the Location class.
*
* @author David J. Barnes and Michael Kölling
* @version 2016.02.29
* @version 2024.10.07 DP classes
*/
public class LocationTest
{
Location startLocation;
Location destination;
Location otherLocation;
/**
* Default constructor for test class LocationTest
*/
public LocationTest()
{
}
/**
* Sets up the test fixture.
*
* Called before every test case method.
*/
@Before
public void setUp()
{
startLocation = new Location(1, 2);
destination = new Location(2, 2);
otherLocation = new Location(3, 2);
}
/**
* Tears down the test fixture.
*
* Called after every test case method.
*/
@After
public void tearDown()
{
}
/**
* Test the distance method of the Location class.
*/
@Test
public void testDistance()
{
assertEquals(startLocation.distance(new Location(5, 7)), 5);
assertEquals(startLocation.distance(destination), 1);
//Misma prueba utilizando otra aserción:
assertTrue(startLocation.distance(destination) == 1);
}
/**
* Run tests of the nextLocation method of the Location class.
*/
@Test
public void testAdjacentLocations()
{
Location siguiente = startLocation.nextLocation(new Location(5, 7));
assertEquals(siguiente, new Location(2, 3));
siguiente = siguiente.nextLocation(new Location(5, 7));
assertEquals(siguiente, new Location(3, 4));
siguiente = siguiente.nextLocation(new Location(5, 7));
assertEquals(siguiente, new Location(4, 5));
siguiente = siguiente.nextLocation(new Location(5, 7));
assertEquals(siguiente, new Location(5, 6));
siguiente = siguiente.nextLocation(new Location(5, 7));
assertEquals(siguiente, new Location(5, 7));
Location otherSiguiente = otherLocation.nextLocation(new Location(2, 1));
assertEquals(otherSiguiente, new Location(2, 1));
otherSiguiente = otherSiguiente.nextLocation(new Location(2, 1));
assertEquals(otherSiguiente, new Location(2, 1));
}
}