Question: jUnit Tests JAVA import java.util.LinkedList; import java.util.Arrays; import static org.junit.jupiter.api.Assertions. * ; import org.junit.jupiter.api.Test; class PermutationTest { PermutationVariation p 1 ; PermutationVariation p 2 ;

jUnit Tests JAVA
import java.util.LinkedList;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class PermutationTest {
PermutationVariation p1;
PermutationVariation p2;
public int n1;
public int n2;
int cases=1;
void initialize(){
n1=4;
n2=6;
Cases c= new Cases();
p1= c.switchforTesting(cases, n1);
p2= c.switchforTesting(cases, n2);
}
@Test
void testPermutation(){
initialize();
// TODO test the constructor of the permutation class, the variable original needs to be initialized in the constructor with the given length, and no number is allowed to be used twice. allDerangements needs to be initialized with an empty list
}
@Test
void testDerangements(){
initialize();
//in case there is something wrong with the constructor
fixConstructor();
// TODO needs to test the derangement method of the permutation class, this method developes all the fixed point free permutations and saves them in allDerangements. This test meeds tp determine whether the number of derangements is correct and if they're actually derangements (if its actually permutations in the next one)
}
@Test
void testsameElements(){
initialize();
//in case there is something wrong with the constructor
fixConstructor();
// TODO test whether all of the in the derangement method developed sequences are actually permutations of the original array "orriginal", if there were no permutations calculated, this test should not work
}
void setCases(int c){
this.cases=c;
}
public void fixConstructor(){
//in case there is something wrong with the constructor
p1.allDerangements=new LinkedList();
for(int i=0;i();
for(int i=0;i();
}
public void derangements(){
backtracking(new LinkedList());
}
public void backtracking(LinkedList candidate){
int[] o=this.original;
if (candidate.size()== o.length){
int[] finalist=new int[o.length];
for(int i=0;i allDerangements;
/**
* Builds the original permutation.
* @param N size of the permutation.
*/
public PermutationVariation(int N){
this.original = new int[N];
}
/**
* @param candidate list for the derangement backtracking.
*/
public abstract void backtracking(LinkedList candidate);
/**
* Calls the backtracking with an empty list.
*/
public abstract void derangements();
@Override
public String toString(){
String str ="";
for (int[] perm : allDerangements){
str += Arrays.toString(perm)+"
";
}
return str;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!