Проверить тесты

 
 
 
Сообщения:43
Сама решила, вот тесты,
если кому нужно:
@Test
public void countPositivesSumNegatives_BasicTest() {
int[] expectedResult = new int[] {10, -65};
assertArrayEquals(expectedResult, Main.sum(new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15}));
}

@Test
public void countPositivesSumNegatives_InputWithZeroes() {
int[] expectedResult = new int[] {8, -50};
assertArrayEquals(expectedResult, Main.sum(new int[] {0, 2, 3, 0, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14}));
}

}


Получаю вот такие ошибки:
STDERR:
./src/test/java/KataTests.java:9: error: cannot find symbol
assertArrayEquals(expectedResult, Kata.countPositivesSumNegatives(new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15}));
^
symbol: method countPositivesSumNegatives(int[])
location: class Kata
./src/test/java/KataTests.java:15: error: cannot find symbol
assertArrayEquals(expectedResult, Kata.countPositivesSumNegatives(new int[] {0, 2, 3, 0, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14}));
^
symbol: method countPositivesSumNegatives(int[])
location: class Kata
./src/test/java/KataTests.java:21: error: cannot find symbol
assertArrayEquals(expectedResult, Kata.countPositivesSumNegatives(null));
^
symbol: method countPositivesSumNegatives(<null>)
location: class Kata
./src/test/java/KataTests.java:27: error: cannot find symbol
assertArrayEquals(expectedResult, Kata.countPositivesSumNegatives(new int[] {}));
^
symbol: method countPositivesSumNegatives(int[])
location: class Kata
./src/test/java/KataTests.java:60: error: cannot find symbol
assertArrayEquals(expected, Kata.countPositivesSumNegatives(input));
^
symbol: method countPositivesSumNegatives(int[])
location: class Kata
5 errors

Вот еа такие тесты:
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.runners.JUnit4;

public class KataTests {
@Test
public void countPositivesSumNegatives_BasicTest() {
int[] expectedResult = new int[] {10, -65};
assertArrayEquals(expectedResult, Kata.countPositivesSumNegatives(new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15}));
}

@Test
public void countPositivesSumNegatives_InputWithZeroes() {
int[] expectedResult = new int[] {8, -50};
assertArrayEquals(expectedResult, Kata.countPositivesSumNegatives(new int[] {0, 2, 3, 0, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14}));
}
}

Вот на такой метод (считаем число положительных чисел и сумму отрицательных):
public class Kata
{
public static int[] countPositivesSumNegatives(int[] input)
import java.util.Arrays;

public class Main {

public static void main (String[] args) {

int[] arr = {0,1,2,-15,-31};

System.out.println(Arrays.toString(sum(arr)));



}

public static int[] sum(int[] arr) {
int sum = 0;
int count = 0;
boolean allNull = true;

for (int i : arr) {
if (i < 0) {
sum += i;
}
else if (i>0) {
count++;
}
if( i != 0 )
allNull = false;
}
if(allNull)
return new int[0];

return new int[] {count, sum};
}

}

Кто-нибудь знает, в чем дело?
Изменен:25 мар 2019 19:28
 
Модераторы:Нет
Сейчас эту тему просматривают:Нет