forked from ISchwarz23/Algorithms-Part1---Assignments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPointTest.java
94 lines (76 loc) · 2.98 KB
/
PointTest.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
import org.junit.Assert;
import org.junit.Test;
import java.util.Comparator;
/**
* Test for the {@link Point} class.
* @author ISchwarz
*/
public class PointTest {
private static final double VALID_DELTA = 0;
@Test
public void shouldReturnNegativeInfinityWhenComparingIdenticalPoints() {
Point p1 = new Point(1, 1);
Point p2 = new Point(1, 1);
Assert.assertEquals(Double.NEGATIVE_INFINITY, p1.slopeTo(p2), VALID_DELTA);
}
@Test
public void shouldReturnPositiveInfinityWhenComparingVerticalPoints() {
Point p1 = new Point(1, 1);
Point p2 = new Point(1, 2);
Assert.assertEquals(Double.POSITIVE_INFINITY, p1.slopeTo(p2), VALID_DELTA);
}
@Test
public void shouldReturnPositiveZeroWhenComparingHorizontalPoints() {
Point p1 = new Point(1, 1);
Point p2 = new Point(2, 1);
Assert.assertEquals(+0, p1.slopeTo(p2), VALID_DELTA);
}
@Test
public void shouldCalculateCorrectSlope() {
Point p1 = new Point(1, 1);
Point p2 = new Point(2, 2);
Assert.assertEquals(1.0, p1.slopeTo(p2), VALID_DELTA);
}
@Test
public void shouldReturnZeroWhenComparingIdenticalPoints() {
Point p1 = new Point(1, 1);
Point p2 = new Point(1, 1);
Assert.assertEquals(0, p1.compareTo(p2));
}
@Test
public void shouldReturnPositiveOneWhenComparingWithSmallerPoint() {
Point p1 = new Point(1, 1);
Point p2 = new Point(0, 0);
Assert.assertEquals(+1, p1.compareTo(p2));
}
@Test
public void shouldReturnNegativeOneWhenComparingWithSmallerPoint() {
Point p1 = new Point(1, 1);
Point p2 = new Point(2, 2);
Assert.assertEquals(-1, p1.compareTo(p2));
}
@Test
public void comparatorShouldReturnZeroWhenComparingTwoPointsWithEqualSlopeRelativeToReferencePoint() {
Point referencePoint = new Point(0, 0);
Point p1 = new Point(1, 1);
Point p2 = new Point(2, 2);
Comparator<Point> comparator = referencePoint.slopeOrder();
Assert.assertEquals(0, comparator.compare(p1, p2));
}
@Test
public void comparatorShouldReturnPositiveOneWhenComparingPointWithBiggerSlopeAndPointWithSmallerSlopeRelativeToReferencePoint() {
Point referencePoint = new Point(0, 0);
Point p1 = new Point(1, 1);
Point p2 = new Point(2, 0);
Comparator<Point> comparator = referencePoint.slopeOrder();
Assert.assertEquals(1, comparator.compare(p1, p2));
}
@Test
public void comparatorShouldReturnNegativeOneWhenComparingPointWithSmallerSlopeAndPointWithBiggerSlopeRelativeToReferencePoint() {
Point referencePoint = new Point(0, 0);
Point p1 = new Point(1, 0);
Point p2 = new Point(2, 2);
Comparator<Point> comparator = referencePoint.slopeOrder();
Assert.assertEquals(-1, comparator.compare(p1, p2));
}
}