-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRectangleTest.java
More file actions
64 lines (54 loc) · 2.29 KB
/
RectangleTest.java
File metadata and controls
64 lines (54 loc) · 2.29 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
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* Test class for Box.
*
* @author Simon Larsén
* @version 2017-08-16
*/
public class RectangleTest {
private final int ALL_HEIGHT = 1;
private final int SMALL_WIDTH = 1;
private final int MEDIUM_WIDTH = 2;
private final int LARGE_WIDTH = 3;
private final Rectangle SMALL_Rectangle = new Rectangle(ALL_HEIGHT, SMALL_WIDTH);
private final Rectangle MEDIUM_Rectangle = new Rectangle(ALL_HEIGHT, MEDIUM_WIDTH);
private final Rectangle LARGE_Rectangle = new Rectangle(ALL_HEIGHT, LARGE_WIDTH);
@Test
public void compareToIsPositiveWhenArgumentIsSmallerThanCallee() {
// Act
int compareMediumToSmall = MEDIUM_Rectangle.compareTo(SMALL_Rectangle);
int compareLargeToSmall = LARGE_Rectangle.compareTo(SMALL_Rectangle);
int compareLargeToMedium = LARGE_Rectangle.compareTo(MEDIUM_Rectangle);
// Assert
assertTrue(0 < compareMediumToSmall);
assertTrue(0 < compareLargeToSmall);
assertTrue(0 < compareLargeToMedium);
}
@Test
public void compareToIsNegativeWhenArgumentIsLargerThanCallee() {
// Act
int compareSmallToMedium = SMALL_Rectangle.compareTo(MEDIUM_Rectangle);
int compareSmallToLarge = SMALL_Rectangle.compareTo(LARGE_Rectangle);
int compareMediumToLarge = MEDIUM_Rectangle.compareTo(LARGE_Rectangle);
// Assert
assertTrue(compareSmallToMedium < 0);
assertTrue(compareSmallToLarge < 0);
assertTrue(compareMediumToLarge < 0);
}
@Test
public void compareToIsZeroWhenArgumentIsSameSizeAsCallee() {
// Arrange
Rectangle smallRectangle = new Rectangle(ALL_HEIGHT, SMALL_WIDTH);
Rectangle mediumRectangle = new Rectangle(ALL_HEIGHT, MEDIUM_WIDTH);
Rectangle largeRectangle = new Rectangle(ALL_HEIGHT, LARGE_WIDTH);
// Act
int compareSmallToSmall = SMALL_Rectangle.compareTo(smallRectangle);
int compareMediumToMedium = MEDIUM_Rectangle.compareTo(mediumRectangle);
int compareLargeToLarge = LARGE_Rectangle.compareTo(largeRectangle);
// Assert
assertEquals(0, compareSmallToSmall);
assertEquals(0, compareMediumToMedium);
assertEquals(0, compareLargeToLarge);
}
}