mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-08 18:32:56 +08:00
Add tests for PowerSum (#3603)
This commit is contained in:
@ -10,25 +10,6 @@ import java.util.Scanner;
|
|||||||
*/
|
*/
|
||||||
public class PowerSum {
|
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;
|
private int count = 0, sum = 0;
|
||||||
|
|
||||||
public int powSum(int N, int X) {
|
public int powSum(int N, int X) {
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user