I make a Pokemon.java class and a PokemeonTest. Need to pass all the junit test.
ID: 3743574 • Letter: I
Question
I make a Pokemon.java class and a PokemeonTest. Need to pass all the junit test. But I am fail the toStringTest1 , 2 and 3. Don't know why.
This is part of my Pokemon.java code.
public String toString(){
DecimalFormat decimal = new DecimalFormat("000");
String string = "";
string =string + "Species: " + this.species + " ";
if(this.species.compareTo(this.name) != 0){
string =string + "Name: " +this.name + " ";
}
string =string + "Number: " + decimal.format(this.number) + " ";
string =string + "Type: " + this.type1;
if(this.type2.length() > 0){
string = string + " | " + this.type2;
}
string =string + " ";
string =string + "HP: " + this.hitPnts + " ";
string =string + "CP: " +this.comPwr +" ";
return string;
}
And This is part of the PokemonTest.java code.
@Test
public void toStringTest1(){
Pokemon p = new Pokemon("Bulbasaur", 1, "Grass", "Poison");
int hP = p.getHitPnts();
int cP = p.getComPwr();
Assert.assertEquals("toString format is incorrect for Pokemon with no name",
"Species: Bulbasaur Number: 001 Type: Grass | Poison HP: "+hP+" CP: "+cP, p.toString());
}
/* testing toString method
* checks that toString is properly formatted with Name and empty type2.
*/
@Test
public void toStringTest2(){
Pokemon p = new Pokemon("Charmander", "Lisa's Charmander", 4, "Fire", "");
int hP = p.getHitPnts();
int cP = p.getComPwr();
Assert.assertEquals("toString format is incorrect for Pokemon with name, no type 2",
"Species: Charmander Name: Lisa's Charmander Number: 004 Type: Fire HP: "+hP+" CP: "+cP, p.toString());
}
/* testing toString method
* checks that toString is properly formatted with no Name and empty type2.
*/
@Test
public void toStringTest3(){
Pokemon p = new Pokemon("Caterpie", 10, "Bug", "");
int hP = p.getHitPnts();
int cP = p.getComPwr();
Assert.assertEquals("toString format is incorrect for Pokemon with no name, no type 2",
"Species: Caterpie Number: 010 Type: Bug HP: "+hP+" CP: "+cP, p.toString());
}
Explanation / Answer
In the results, It expects CP to end with a pipe character "|",(CP:140|), but your output is missing that .
That looks to be the source of mismatch
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.