vendredi 22 juin 2018

how to input an array via csv Source - JUnit-Tests

I wrote a method, which will return +1, if more elements of the int-array are >0, return -1 vice versa, and return 0, if it's balanced. Why can't the parameters be resolved? Is there an alternative way to test it?

static int[] a = {1, 2, 3, 4};       // 1
static int[] b = {1, -2, -3, 4};    // 0
static int[] c = {-1, -2, -3, 4};   // -1
static int[] d = {1, 2, 3, -4, 5};  // 1
static int[] e = {1, -2, 3, 4, -3, -5}; // 0        
static int[] f = {0, 0, -3, 0, 0};      // -1 
static int[] g = {};  // 0
static int[] h = {'a'};  // 1
static int[] i = {-1}; // -1
static int[] j = null; // IllegalArgumentException


@ParameterizedTest
@CsvSource({ "a, 1", "b, 0", "c, -1", "d, 1" })
void testBalance(int[] input, int output) { 
    assertThat(NumberAnalyse.balance(input), is(equalTo(output)));
}

Aucun commentaire:

Enregistrer un commentaire