Table des matières ⇒ Java Unit Test Library-Artery-Sample
package jp.avaj.lib.test;
import static org.junit.Assert.*;
import java.math.BigDecimal;
import java.util.List;
import org.junit.Test;
import jp.avaj.lib.algo.ArList;
/**
Bibliothèque de tests unitaires Java-Artery/JUnit4-Jugement d'équivalence du tableau
Int dans l'artère[] vs Integer[]Et int[] vs long[]Peut être jugé par différents types tels que
JUnit utilise assertArrayEquals pour la détermination de l'égalité(ne pas affirmer)
Int dans JUnit[] vs Integer[]Et int[] vs long[]Ne peut pas être jugé par différents types tels que
*/
public class Q02_01 {
////////Ci-dessous un échantillon d'artère
public static void main(String[] args) {
//Déclarer le début d'un cas de test ⇒ Non requis si l'agrégation n'est pas requise
ArTest.startTestCase("Q02_01");
// int[] vs int[]
{
int[] value0 = new int[]{0,1,2};
int[] value1 = new int[]{0,1,2};
ArTest.equals("int[] vs int[]","value0",value0,"value1",value1);
value1 = new int[]{10,11,12};
ArTest.equals("int[] vs int[](NG)","value0",value0,"value1",value1);
}
// int[] vs Integer[]
{
int[] value0 = new int[]{0,1,2};
Integer[] value1 = new Integer[]{0,1,2};
ArTest.equals("int[] vs Integer[]","value0",value0,"value1",value1);
value1 = new Integer[]{10,11,12};
ArTest.equals("int[] vs Integer[](NG)","value0",value0,"value1",value1);
}
// int[] vs Long[]
{
int[] value0 = new int[]{0,1,2};
Long[] value1 = new Long[]{0L,1L,2L};
ArTest.equals("int[] vs Long[]","value0",value0,"value1",value1);
value1 = new Long[]{10L,11L,12L};
ArTest.equals("int[] vs Long[](NG)","value0",value0,"value1",value1);
}
// int[] vs Double[]
{
int[] value0 = new int[]{0,1,2};
Double[] value1 = new Double[]{0D,1D,2D};
ArTest.equals("int[] vs Double[]","value0",value0,"value1",value1);
value1 = new Double[]{10D,11D,12D};
ArTest.equals("int[] vs Double[](NG)","value0",value0,"value1",value1);
}
// int[] vs BigDecimal[]
{
int[] value0 = new int[]{0,1,2};
BigDecimal[] value1 = new BigDecimal[]{new BigDecimal(0),new BigDecimal(1),new BigDecimal(2)};
ArTest.equals("int[] vs BigDecimal[]","value0",value0,"value1",value1);
value1 = new BigDecimal[]{new BigDecimal(10),new BigDecimal(11),new BigDecimal(12)};
ArTest.equals("int[] vs BigDecimal[](NG)","value0",value0,"value1",value1);
}
// int[] vs List<Integer>
{
int[] value0 = new int[]{0,1,2};
List<Integer> value1 = ArList.construct(new Integer[]{0,1,2});
ArTest.equals("int[] vs List<Integer>","value0",value0,"value1",value1);
value1 = ArList.construct(new Integer[]{10,11,12});
ArTest.equals("int[] vs List<Integer> (NG)","value0",value0,"value1",value1);
}
// int[] vs String[]⇒ Il peut être jugé, mais il vaut peut-être mieux ne pas l'utiliser?
{
int[] value0 = new int[]{0,1,2};
String[] value1 = new String[]{"0","1","2"};
ArTest.equals("int[] vs String[]","value0",value0,"value1",value1);
value1 = new String[]{"10","11","12"};
ArTest.equals("int[] vs String[](NG)","value0",value0,"value1",value1);
}
// String[] vs String[]
{
String[] value0 = new String[]{"0","1","2"};
String[] value1 = new String[]{"0","1","2"};
ArTest.equals("String[] vs String[]","value0",value0,"value1",value1);
value1 = new String[]{"10","11","12"};
ArTest.equals("String[] vs String[](NG)","value0",value0,"value1",value1);
}
// String[] vs List<String>[]
{
String[] value0 = new String[]{"0","1","2"};
List<String> value1 = ArList.construct(new String[]{"0","1","2"});
ArTest.equals("String[] vs List<String>[]","value0",value0,"value1",value1);
value1 = ArList.construct(new String[]{"10","11","12"});
ArTest.equals("String[] vs List<String>[](NG)","value0",value0,"value1",value1);
}
//Terminer le cas de test ⇒ Non requis si l'agrégation n'est pas requise
ArTest.endTestCase();
}
////////Ci-dessous un exemple de JUnit4
// int[] vs int[] -Si égal ⇒ mais NG
//Si vous ne savez pas "utiliser assertArrayEquals", vous vous trompez peut-être..
@Test
public void test00() {
assertEquals(new int[]{0,1,2},new int[]{0,1,2});
}
// int[] vs int[] -S'ils sont égaux ⇒ C'est OK
@Test
public void test01() {
assertArrayEquals(new int[]{0,1,2},new int[]{0,1,2});
}
// int[] vs Integer[] -Si égal ⇒ Il s'agit d'une erreur de compilation
//Je veux que tu fasses autant...
@Test
public void test02() {
// assertArrayEquals(new int[]{0,1,2},new Integer[]{0,1,2});
}
// int[] vs long[] -S'ils sont égaux ⇒ C'est aussi une erreur de compilation
//Je veux que tu fasses autant...
@Test
public void test03() {
// assertArrayEquals(new int[]{0,1,2},new long[]{0,1,2});
}
// double[] vs double[],L'erreur de jugement doit être spécifiée ⇒ Si égal
@Test
public void test04() {
assertArrayEquals(new double[]{0D,1D,2D},new double[]{0D,1D,2D},0.5D);
}
// double[] vs double[],L'erreur de jugement doit être spécifiée ⇒ Si elle n'est pas égale
@Test
public void test05() {
assertArrayEquals(new double[]{0D,1D,2D},new double[]{10D,11D,12D},0.5D);
}
// String[] va String[] -Si égal
@Test
public void test06() {
assertArrayEquals(new String[]{"a","b","c"},new String[]{"a","b","c"});
}
// String[] va String[] -Si ce n'est pas égal
@Test
public void test07() {
assertArrayEquals(new String[]{"a","b","c"},new String[]{"x","y","z"});
}
}
Le résultat est le suivant
result.txt
**** Q02_01 start ****
OK int[] vs int[]:value0=[0, 1, 2]:value1=[0, 1, 2]
NG int[] vs int[](NG):value0=[0, 1, 2]:value1=[10, 11, 12]
jp.avaj.lib.test.Q02_01.main(Q02_01.java:32)
OK int[] vs Integer[]:value0=[0, 1, 2]:value1=[0, 1, 2]
NG int[] vs Integer[](NG):value0=[0, 1, 2]:value1=[10, 11, 12]
jp.avaj.lib.test.Q02_01.main(Q02_01.java:40)
OK int[] vs Long[]:value0=[0, 1, 2]:value1=[0, 1, 2]
NG int[] vs Long[](NG):value0=[0, 1, 2]:value1=[10, 11, 12]
jp.avaj.lib.test.Q02_01.main(Q02_01.java:48)
OK int[] vs Double[]:value0=[0, 1, 2]:value1=[0, 1, 2]
NG int[] vs Double[](NG):value0=[0, 1, 2]:value1=[10, 11, 12]
jp.avaj.lib.test.Q02_01.main(Q02_01.java:56)
OK int[] vs BigDecimal[]:value0=[0, 1, 2]:value1=[0, 1, 2]
NG int[] vs BigDecimal[](NG):value0=[0, 1, 2]:value1=[10, 11, 12]
jp.avaj.lib.test.Q02_01.main(Q02_01.java:64)
OK int[] vs List<Integer>:value0=[0, 1, 2]:value1=[0, 1, 2]
NG int[] vs List<Integer> (NG):value0=[0, 1, 2]:value1=[10, 11, 12]
jp.avaj.lib.test.Q02_01.main(Q02_01.java:72)
OK int[] vs String[]:value0=[0, 1, 2]:value1=[0, 1, 2]
NG int[] vs String[](NG):value0=[0, 1, 2]:value1=[10, 11, 12]
jp.avaj.lib.test.Q02_01.main(Q02_01.java:80)
OK String[] vs String[]:value0=[0, 1, 2]:value1=[0, 1, 2]
NG String[] vs String[](NG):value0=[0, 1, 2]:value1=[10, 11, 12]
jp.avaj.lib.test.Q02_01.main(Q02_01.java:88)
OK String[] vs List<String>[]:value0=[0, 1, 2]:value1=[0, 1, 2]
NG String[] vs List<String>[](NG):value0=[0, 1, 2]:value1=[10, 11, 12]
jp.avaj.lib.test.Q02_01.main(Q02_01.java:96)
**** Q02_01 summary ****
test count = 18
success = 9
Recommended Posts