Skip to content

Commit

Permalink
Add tests for PowerSum (TheAlgorithms#3603)
Browse files Browse the repository at this point in the history
  • Loading branch information
laks-mi1099 authored Oct 22, 2022
1 parent 51f9596 commit ea05286
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
19 changes: 0 additions & 19 deletions src/main/java/com/thealgorithms/backtracking/PowerSum.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,6 @@
*/
public class PowerSum {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number and the power");
int N = sc.nextInt();
int X = sc.nextInt();
PowerSum ps = new PowerSum();
int count = ps.powSum(N, X);
//printing the answer.
System.out.println(
"Number of combinations of different natural number's raised to " +
X +
" having sum " +
N +
" are : "
);
System.out.println(count);
sc.close();
}

private int count = 0, sum = 0;

public int powSum(int N, int X) {
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/com/thealgorithms/backtracking/PowerSumTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.thealgorithms.backtracking;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

public class PowerSumTest {

@Test
void testNumberZeroAndPowerZero() {
PowerSum powerSum = new PowerSum();
int result = powerSum.powSum(0, 0);
assertEquals(1, result);
}

@Test
void testNumberHundredAndPowerTwo() {
PowerSum powerSum = new PowerSum();
int result = powerSum.powSum(100, 2);
assertEquals(3, result);
}

@Test
void testNumberHundredAndPowerThree() {
PowerSum powerSum = new PowerSum();
int result = powerSum.powSum(100, 3);
assertEquals(1, result);
}

}

0 comments on commit ea05286

Please sign in to comment.