samedi 28 février 2015

Test Class not working right within my Java


Vote count:

0




OK, I am working with test methods. I am trying to figure this out. Hopefully I enter enough code in here to determine where my mistake is.


This is what I am testing...



@Test
public void testComputePercent()
{
// Create
GradeCalculator gradeCalc = new GradeCalculator();
// Set
gradeCalc.accrueTotalScore(50);
gradeCalc.accrueMaximumScore(100);
// Test
assertEquals(.5, gradeCalc.computePercent(), .01);
}


I already know the answer will not be .5, but I am trying to figure out what is going on.


Here is the code.



public double computePercent()
{
if (this.totalScore == 0 || this.maximumScore == 0)
{
System.out.println("OH NO. You had a 0 in your score somewhere.");
}
double myGrade = (this.totalScore / this.maximumScore) * 100;
return myGrade;
}


Basically, if I scored 50 on my test (out of 100), the program will display a grade for me. 50/100 = .5 * 100 = 50%


For whatever reason, when I test the test, it says that .5 was expected (which I already know) and that 0.0 was entered. Which I am not too sure why as I am passing the right ints.


Below are my setters and getters.



public void accrueTotalScore(int inScore)
{
this.totalScore = inScore;
}

public void accrueMaximumScore (int inScore)
{
this.maximumScore = inScore;
}

public int getTotalScore()
{
return this.totalScore;
}

public int getMaximumScore()
{
return this.maximumScore;
}


Any help will be awesome.



asked 27 secs ago







Test Class not working right within my Java

Aucun commentaire:

Enregistrer un commentaire