Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 p;
PermutationVariation p;
public int n;
public int n;
int cases;
void initialize
n;
n;
Cases c new Cases;
p cswitchforTestingcases n;
p cswitchforTestingcases n;
@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 setCasesint c
this.casesc;
public void fixConstructor
in case there is something wrong with the constructor
pallDerangementsnew LinkedList;
forint i;i;
forint i;i;
public void derangements
backtrackingnew LinkedList;
public void backtrackingLinkedList candidate
int othis.original;
if candidatesize olength
int finalistnew intolength;
forint i;i allDerangements;
Builds the original permutation.
@param N size of the permutation.
public PermutationVariationint N
this.original new intN;
@param candidate list for the derangement backtracking.
public abstract void backtrackingLinkedList candidate;
Calls the backtracking with an empty list.
public abstract void derangements;
@Override
public String toString
String str ;
for int perm : allDerangements
str Arrays.toStringperm
;
return str;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started