I'm pretty new to writing code and I am not the best, but I don't understand why my code isn't passing one of the JUnit tests I have set up.
public class PA3Test {
public static void main(String[] args) {
}
public static int countMajority(int count0, int count1, int count2) {
int allVotes = (count0 + count1 + count2);
int halfVotes = (allVotes / 2);
int winner = 999;
if (count0 >= halfVotes) {
winner = 0;
} else {
winner = -1;
}
if (count1 >= halfVotes) {
winner = 1;
} else {
winner = -1;
}
return winner;
}
The test looks like this:
import junit.framework.TestCase;
public class PA3TestTest extends TestCase {
public static void testCountMajority() {
assertEquals("0th param should win:", 0,
PA3Test.countMajority(100, 50, 40));
assertEquals("1st param should win:", 1,
PA3Test.countMajority(50, 100, 40));
}
It is supposed to be returning 0 but it is returning -1. Any help is appreciated.