Mam problem z testowaniem dwóch funkcji. testy są na 0% przy czym nie wyświetla mi żadnej informacji na temat jakich kol wiek błędów z pierwszej funkcji
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package app;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author Adrian
*/
public class NewClassTest {
public NewClassTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Test
public void testSomeMethod() {
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of czyPelnoletni method, of class NewClass.
*/
@Test
public void testCzyPelnoletni() {
System.out.println("czyPelnoletni");
int wiek = 0;
NewClass instance = new NewClass();
boolean result;
try{
result = instance.czyPelnoletni(wiek);
fail("nie ma wyjatku");
}catch(IllegalArgumentException e){
}
wiek = 32;
try{
result = instance.czyPelnoletni(wiek);
fail("nie ma wyjatku");
}catch(IllegalArgumentException e){
}
wiek = 23;
try{
result = instance.czyPelnoletni(wiek);
fail("nie ma wyjatku");
}catch(IllegalArgumentException e){
}
wiek = 1;
boolean expResult = false;
result = instance.czyPelnoletni(wiek);
assertEquals(expResult, result);
wiek =20;
expResult = true;
result = instance.czyPelnoletni(wiek);
assertEquals(expResult, result);
assertTrue(instance.czyPelnoletni(25));
assertTrue(instance.czyPelnoletni(31));
assertFalse(instance.czyPelnoletni(4));
assertFalse(instance.czyPelnoletni(5));
}
/**
* Test of IlePelnoletnich method, of class NewClass.
*/
@Test
public void testIlePelnoletnich() {
System.out.println("IlePelnoletnich");
int[] tab = null;
NewClass instance = new NewClass();
int result;
try{
result = instance.IlePelnoletnich(tab);
fail("nie ma wyjatku");
}catch(IllegalArgumentException e){
}
tab = new int[0];
try{
result = instance.IlePelnoletnich(tab);
fail("nie ma wyjatku");
}catch(IllegalArgumentException e){
}
tab = new int[]{0};
try{
result = instance.IlePelnoletnich(tab);
fail("nie ma wyjatku");
}catch(IllegalArgumentException e){
}
tab = new int[]{-1};
try{
result = instance.IlePelnoletnich(tab);
fail("nie ma wyjatku");
}catch(IllegalArgumentException e){
}
tab = new int[]{1};
int expResult =-1;
result = instance.IlePelnoletnich(tab);
assertEquals(expResult, result);
tab = new int[]{17,33,46,120,360};
expResult =17;
result = instance.IlePelnoletnich(tab);
assertEquals(expResult, result);
tab = new int[]{175,33,46,120,11};
expResult =11;
result = instance.IlePelnoletnich(tab);
assertEquals(expResult, result);
tab = new int[]{11};
expResult =11;
result = instance.IlePelnoletnich(tab);
assertEquals(expResult, result);
result = instance.IlePelnoletnich(tab);
assertEquals(expResult, result);
}
}
public class NewClass {
public boolean czyPelnoletni(int wiek){
if(wiek < 5){
throw new IllegalArgumentException("wyjatek");}
if(wiek>130){
throw new IllegalArgumentException("wyjatek");
}
if(wiek >= 18){
return true;
}
return true;
}
public int IlePelnoletnich(int tab[]){
int ilosc = 0;
for (int i = 0; i < tab.length; i++) {
if(czyPelnoletni(tab[i]))
ilosc++;
}
return ilosc;
}