Answered step by step
Verified Expert Solution
Link Copied!

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 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

Students also viewed these Databases questions

Question

=+a) Compute the EV for each alternative decision.

Answered: 1 week ago