dimanche 10 septembre 2017

Am I missing something?

I'm tasked with creating a JUnit test for functional code. The JUnit test works on my system fine, but in auto-grader apparently it is wrong.

Classes without full coverage:
    ------------------------------
    Ran 0 out of 10 lines in edu.buffalo.cse116.UniqueSum (note: lines in failed JUnit tests count as not run)

I've looked all over and I can't find what I'm doing wrong. I was told the test should check every line in the code "100%" , and it does. When I myself put in errors in the code the junit test will notice it, atleast on my system.

Sample Code:

 /**
   * Normally, this method will compute the sum of the three parameters. BUT, if one of the parameters has the same
   * value as another parameter, then neither of the parameters should be included in the sum. If all three parameters
   * have the same value, then zero should be returned.
   *
   * @param a First parameter to use in the "unique sum" calculation
   * @param b Second parameter to use in the "unique sum" calculation
   * @param c Third parameter to use in the "unique sum" calculation
   * @return "Unique sum" which only sums values which appear once in the three parameters.
   */
  public int computeUniqueSum(int a, int b, int c) {
    if (a == b) {
      if (a == c) {
        return 0;
      } else {
        return c;
      }
    } else if (a == c) {
      return b;
    } else if (b == c) {
      return a;
    } else {
      return a + b + c;
    }
  }
}

My JUnit Test:

package testing;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class UniqueSumTest {


    @Test
    public void assert1() {

        UniqueSum computeTest = new UniqueSum();
        int actual = computeTest.computeUniqueSum(3, 3, 3);

        assertEquals("All paramters cannot have the same value.", 0, actual);

    }


    @Test
    public void assert2() {

        UniqueSum computeTest = new UniqueSum();
        int result = computeTest.computeUniqueSum(4, 3, 3);

        assertEquals("Any paramters cannot have the same value.", 4, result);
    }

    @Test
    public void assert3() {

        UniqueSum computeTest = new UniqueSum();
        int result = computeTest.computeUniqueSum(3, 4, 3);

        assertEquals("Any paramters cannot have the same value.:", 4, result);
    }

    @Test
    public void assert4() {

        UniqueSum computeTest = new UniqueSum();
        int result = computeTest.computeUniqueSum(3, 3, 4);

        assertEquals("Any paramters cannot have the same value.", 4, result);
    }

    @Test
    public void assert5() {

        UniqueSum computeTest = new UniqueSum();
        int result = computeTest.computeUniqueSum(5, 10, 15);

        assertEquals("All parameters are different.", 30, result);
    }
}

Aucun commentaire:

Enregistrer un commentaire