Skip to content

Commit ea05286

Browse files
authored
Add tests for PowerSum (TheAlgorithms#3603)
1 parent 51f9596 commit ea05286

2 files changed

Lines changed: 28 additions & 19 deletions

File tree

src/main/java/com/thealgorithms/backtracking/PowerSum.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,6 @@
1010
*/
1111
public class PowerSum {
1212

13-
public static void main(String[] args) {
14-
Scanner sc = new Scanner(System.in);
15-
System.out.println("Enter the number and the power");
16-
int N = sc.nextInt();
17-
int X = sc.nextInt();
18-
PowerSum ps = new PowerSum();
19-
int count = ps.powSum(N, X);
20-
//printing the answer.
21-
System.out.println(
22-
"Number of combinations of different natural number's raised to " +
23-
X +
24-
" having sum " +
25-
N +
26-
" are : "
27-
);
28-
System.out.println(count);
29-
sc.close();
30-
}
31-
3213
private int count = 0, sum = 0;
3314

3415
public int powSum(int N, int X) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.thealgorithms.backtracking;
2+
import static org.junit.jupiter.api.Assertions.assertEquals;
3+
import org.junit.jupiter.api.Test;
4+
5+
public class PowerSumTest {
6+
7+
@Test
8+
void testNumberZeroAndPowerZero() {
9+
PowerSum powerSum = new PowerSum();
10+
int result = powerSum.powSum(0, 0);
11+
assertEquals(1, result);
12+
}
13+
14+
@Test
15+
void testNumberHundredAndPowerTwo() {
16+
PowerSum powerSum = new PowerSum();
17+
int result = powerSum.powSum(100, 2);
18+
assertEquals(3, result);
19+
}
20+
21+
@Test
22+
void testNumberHundredAndPowerThree() {
23+
PowerSum powerSum = new PowerSum();
24+
int result = powerSum.powSum(100, 3);
25+
assertEquals(1, result);
26+
}
27+
28+
}

0 commit comments

Comments
 (0)