Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 21.3k
Expand file tree
/
Copy pathADTFractionTest.java
More file actions
Latest commit
52 lines (41 loc) · 1.51 KB
/
Copy pathADTFractionTest.java
File metadata and controls
52 lines (41 loc) · 1.51 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
packagecom.thealgorithms.maths;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importstaticorg.junit.jupiter.api.Assertions.assertThrows;
importstaticorg.junit.jupiter.api.Assertions.assertTrue;
importorg.junit.jupiter.api.Test;
publicclassADTFractionTest {
privatefinalADTFractionfraction1 = newADTFraction(3, 5);
privatefinalADTFractionfraction2 = newADTFraction(7, 8);
@Test
voidtestConstructorWithDenominatorEqualToZero() {
Exceptionexception = assertThrows(IllegalArgumentException.class, () -> newADTFraction(1, 0));
assertEquals("Denominator cannot be 0", exception.getMessage());
}
@Test
publicvoidtestPlus() {
assertEquals(newADTFraction(59, 40), fraction1.plus(fraction2));
}
@Test
publicvoidtestTimes() {
assertEquals(newADTFraction(12, 5), fraction1.times(4));
assertEquals(newADTFraction(21, 40), fraction1.times(fraction2));
}
@Test
publicvoidtestReciprocal() {
assertEquals(newADTFraction(5, 3), fraction1.reciprocal());
}
@Test
publicvoidtestValue() {
assertEquals(0.6F, fraction1.value());
}
@Test
publicvoidtestEqualsAndHashCode() {
ADTFractionfraction3 = newADTFraction(3, 5);
assertTrue(fraction1.equals(fraction3) && fraction3.equals(fraction1));
assertEquals(fraction1.hashCode(), fraction3.hashCode());
}
@Test
publicvoidtestToString() {
assertEquals("3/5", fraction1.toString());
}
}