-
Notifications
You must be signed in to change notification settings - Fork 21.2k
Expand file tree
/
Copy pathSociableNumberTest.java
More file actions
56 lines (47 loc) · 1.73 KB
/
Copy pathSociableNumberTest.java
File metadata and controls
56 lines (47 loc) · 1.73 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
package com.thealgorithms.maths;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
/**
* Tests for {@link SociableNumber}.
*
* @author Vraj Prajapati (@Rosander0)
*/
public class SociableNumberTest {
@Test
public void testSumOfProperDivisorsEdgeCases() {
assertEquals(0, SociableNumber.sumOfProperDivisors(0));
assertEquals(0, SociableNumber.sumOfProperDivisors(-5));
assertEquals(0, SociableNumber.sumOfProperDivisors(1));
assertEquals(1, SociableNumber.sumOfProperDivisors(2));
}
@Test
public void testSociableCycleOfLengthFive() {
assertTrue(SociableNumber.isSociable(12496, 5));
}
@Test
public void testAmicableNumbersAreSociableOfLengthTwo() {
assertTrue(SociableNumber.isSociable(220, 2));
assertTrue(SociableNumber.isSociable(284, 2));
}
@Test
public void testNonSociableNumbers() {
assertFalse(SociableNumber.isSociable(12, 5));
assertFalse(SociableNumber.isSociable(10, 3));
}
@Test
public void testEarlyCycleReturn() {
// 220 has cycle length 2; requesting a different length should return
// false because it returns to the start too early.
assertFalse(SociableNumber.isSociable(220, 3));
assertFalse(SociableNumber.isSociable(284, 4));
assertFalse(SociableNumber.isSociable(12496, 3));
}
@Test
public void testInvalidInputs() {
assertFalse(SociableNumber.isSociable(0, 5));
assertFalse(SociableNumber.isSociable(-1, 5));
assertFalse(SociableNumber.isSociable(220, 1));
}
}