File tree Expand file tree Collapse file tree 2 files changed +28
-19
lines changed
main/java/com/thealgorithms/backtracking
test/java/com/thealgorithms/backtracking Expand file tree Collapse file tree 2 files changed +28
-19
lines changed Original file line number Diff line number Diff line change 1010 */
1111public 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 ) {
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments