forked from rampatra/Algorithms-and-Data-Structures-in-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRecursiveDigitSumTest.java
127 lines (102 loc) · 2.9 KB
/
RecursiveDigitSumTest.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package recursion;
import static org.junit.jupiter.api.Assertions.assertThrows;
import javax.annotation.processing.Generated;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@Generated(value = "org.junit-tools-1.1.0")
public class RecursiveDigitSumTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
System.out.println("BeforeClass");
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
System.out.println("AfterClass");
}
@Test
public void testSuperDigitWithNull() throws Exception {
// TC1
int k = 0;
String n = null;
String expected = "by input exception [" + n + "]";
Exception result = assertThrows(Exception.class,
() -> RecursiveDigitSum.superDigit(n, k));
Assert.assertEquals(expected, result.getMessage());
}
@Test
public void testSuperDigitWithEmpty() throws Exception {
// TC2
int k = 1;
String n = "";
int expected = 0;
int result = RecursiveDigitSum.superDigit(n, k);
Assert.assertEquals(expected, result);
}
@Test
public void testSuperDigitWithNegative1() throws Exception {
// TC3
int k = -1;
String n = "1";
String expected = "by input exception [" + k + "]";
Exception result = assertThrows(Exception.class,
() -> RecursiveDigitSum.superDigit(n, k));
Assert.assertEquals(expected, result.getMessage());
}
@Test
public void testSuperDigit1() throws Exception {
// TC4
int k = 0;
String n = "1";
int expected = 1;
int result = RecursiveDigitSum.superDigit(n, k);
Assert.assertEquals(expected, result);
}
@Test
public void testSuperDigitMax1() throws Exception {
// TC5
int k = 999999999;
String n = "1";
int expected = 9;
int result = RecursiveDigitSum.superDigit(n, k);
Assert.assertEquals(expected, result);
}
@Test
public void testSuperDigit3() throws Exception {
// TC6
int k = 0;
String n = "12";
int expected = 3;
int result = RecursiveDigitSum.superDigit(n, k);
Assert.assertEquals(expected, result);
}
@Test
public void testSuperDigit4() throws Exception {
// TC7
int k = 1;
String n = "12";
int expected = 3;
int result = RecursiveDigitSum.superDigit(n, k);
Assert.assertEquals(expected, result);
}
@Test
public void testSuperDigitMax2() throws Exception {
// TC8
int k = 1;
String n = "999999999";
int expected = 9;
int result = RecursiveDigitSum.superDigit(n, k);
Assert.assertEquals(expected, result);
}
@Test
public void testSuperDigitWithNegative2() throws Exception {
// TC9
int k = 1;
String n = "-a";
String expected = "by input exception [" + n + "]";
Exception result = assertThrows(Exception.class,
() -> RecursiveDigitSum.superDigit(n, k));
Assert.assertEquals(expected, result.getMessage());
}
}