Table of Contents ⇒ 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;
/**
Java unit test library-Artery/JUnit4-Array equivalence judgment
Int in Artery[] vs Integer[]And int[] vs long[]Can be judged by different types such as
JUnit uses assertArrayEquals for equality judgment(not assertEquals)
Int in JUnit[] vs Integer[]And int[] vs long[]Cannot be judged by different types such as
*/
public class Q02_01 {
////////Below is a sample of Artery
public static void main(String[] args) {
//Declare the start of the test case ⇒ Not required if aggregation is not required
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[]⇒ It can be judged, but it may be better not to use it?
{
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);
}
//End the test case ⇒ Not required if aggregation is not required
ArTest.endTestCase();
}
////////Below is a sample of JUnit4
// int[] vs int[] -If equal ⇒ but NG
//If you don't know "use assertArrayEquals" you may be wrong..
@Test
public void test00() {
assertEquals(new int[]{0,1,2},new int[]{0,1,2});
}
// int[] vs int[] -If they are equal ⇒ This is OK
@Test
public void test01() {
assertArrayEquals(new int[]{0,1,2},new int[]{0,1,2});
}
// int[] vs Integer[] -If equal ⇒ This is a compilation error
//I want you to do this much...
@Test
public void test02() {
// assertArrayEquals(new int[]{0,1,2},new Integer[]{0,1,2});
}
// int[] vs long[] -If they are equal ⇒ This is also a compilation error
//I want you to do this much...
@Test
public void test03() {
// assertArrayEquals(new int[]{0,1,2},new long[]{0,1,2});
}
// double[] vs double[],Judgment error must be specified ⇒ If equal
@Test
public void test04() {
assertArrayEquals(new double[]{0D,1D,2D},new double[]{0D,1D,2D},0.5D);
}
// double[] vs double[],Judgment error must be specified ⇒ If not equal
@Test
public void test05() {
assertArrayEquals(new double[]{0D,1D,2D},new double[]{10D,11D,12D},0.5D);
}
// String[] va String[] -If equal
@Test
public void test06() {
assertArrayEquals(new String[]{"a","b","c"},new String[]{"a","b","c"});
}
// String[] va String[] -If not equal
@Test
public void test07() {
assertArrayEquals(new String[]{"a","b","c"},new String[]{"x","y","z"});
}
}
The result is as follows
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