Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

org.opentest 4 j . AssertionFailedError: Something went wrong! best i can tell is null at org.junit.jupiter.api.AssertionUtils.fail ( AssertionUtils . java: 3 9 ) at org.junit.jupiter.api.Assertions.fail

org.opentest4j.AssertionFailedError: Something went wrong! best i can tell is null
at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:39)
at org.junit.jupiter.api.Assertions.fail(Assertions.java:109)
at MachineTests.testMachineCreationArray(MachineTests.java:326) org.opentest4j.AssertionFailedError: Something went wrong! best i can tell is null
at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:39)
at org.junit.jupiter.api.Assertions.fail(Assertions.java:109)
at MachineTests.testMachineTurnValid(MachineTests.java:469) How to fix these issues here is my code import java.util.List;
import java.util.ArrayList;
public class Machine {
private int[] ans;
private List verifierss;
public Machine(int[] ans, Verifier[] verifierss) throws IncorrectDataException {
correctAns(ans);
this.ans = ans;
this.verifierss = List.of(verifierss);
}
public Machine(int[] ans, List verifierss) throws IncorrectDataException {
correctAns(ans);
this.ans = ans;
this.verifierss = new ArrayList<>(verifierss);
}
private void correctAns(int[] ans) throws IncorrectDataException {
if (ans.length !=3){
throw new IncorrectDataException("Answer must consist of exactly 3 digits.");
}
for (int n : ans){
if (n <1|| n >5){
throw new IncorrectDataException("Digits must be within the range 1-5.");
}
}
}
public String toString(){
StringBuilder stringbuilder = new StringBuilder("Verifiers:
");
char verifierCh ='A';
for (Verifier verifier : verifierss){
stringbuilder.append(verifierCh).append(")").append(verifier.toString()).append("
");
verifierCh++;
}
return stringbuilder.toString().trim();
}
public String turn(int[] guess, char[] verifierChoice) throws IncorrectDataException {
correctGuess(guess);
if (verifierChoice.length !=3){
throw new IncorrectDataException("There must be exactly 3 selected verifiers.");
}
StringBuilder stringbuilder = new StringBuilder("Results for guess ");
for (int n : guess){
stringbuilder.append(n);
}
stringbuilder.append(":
");
List sortedChoice = new ArrayList<>();
for (char c : verifierChoice){
sortedChoice.add(Character.toUpperCase(c));
}
sortedChoice.sort(Character::compareTo);
for (char choicee : sortedChoice){
int i = choicee -'A';
if (i <0|| i >= verifierss.size()){
throw new IncorrectDataException("Selected verifier is out of bounds.");
}
Verifier verifier = verifierss.get(i);
stringbuilder.append(choicee).append(")").append(verifier.check(guess, ans)).append("
");
}
return stringbuilder.toString().trim();
}
public String turn(int[] guess, String verifierChoice) throws IncorrectDataException {
char[] choiceArray = verifierChoice.replace("","").toCharArray();
return turn(guess, choiceArray);
}
public boolean finalGuess(int[] guess) throws IncorrectDataException {
correctGuess(guess);
for (int i =0; i < guess.length; i++){
if (guess[i]!= ans[i]){
return false;
}
}
return true;
}
private void correctGuess(int[] guess) throws IncorrectDataException {
if (guess.length !=3){
throw new IncorrectDataException("Guess must consist of exactly 3 digits.");
}
for (int n : guess){
if (n <1|| n >5){
throw new IncorrectDataException("Digits must be within the range 1-5.");
}
}
}
}

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

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

A price reduction, or no charge at all, if this is appropriate?

Answered: 1 week ago