Java Unit Test Library-Artery / JUnit4-Numerical equality judgment

Table of Contents ⇒ Java Unit Test Library-Artery-Sample

package jp.avaj.lib.test;

import static org.junit.Assert.*;

import java.math.BigDecimal;

import org.junit.Test;

/**
Java unit test library-Artery/JUnit4-Numerical equality judgment

Artery allows equality judgment for different types of numbers
In double(at present)Judgment error cannot be specified.
Note that in JUnit4, even equal values will be NG in comparisons such as Integer vs Long..
 */
public class Q02_00 {
  ////////Below is a sample of Artery
  public static void main(String[] args) {
    ArTest.startTestCase("Q02_00");

    // int vs int
    {
      int value0 = 5;
      int value1 = 5;
      ArTest.equals("int vs int","value0",value0,"value1",value1);
      value1 = 10;
      ArTest.equals("int vs int (NG)","value0",value0,"value1",value1);
    }
    // int vs long
    {
      int value0 = 5;
      long value1 = 5L;
      ArTest.equals("int vs long","value0",value0,"value1",value1);
      value1 = 10L;
      ArTest.equals("int vs long (NG)","value0",value0,"value1",value1);
    }
    // int vs double
    {
      int value0 = 5;
      double value1 = 5D;
      ArTest.equals("int vs double","value0",value0,"value1",value1);
      value1 = 10D;
      ArTest.equals("int vs double (NG)","value0",value0,"value1",value1);
    }
    // int vs BigDecimal
    {
      int value0 = 5;
      BigDecimal value1 = new BigDecimal(5);
      ArTest.equals("int vs BigDecimal","value0",value0,"value1",value1);
      value1 = new BigDecimal(10);
      ArTest.equals("int vs BigDecimal (NG)","value0",value0,"value1",value1);
    }
    //int vs String ⇒ You can do it even if it is not a numerical value..⇒ It may be better not to use..
    {
      int value0 = 5;
      String value1 = "5";
      ArTest.equals("int vs String","value0",value0,"value1",value1);
      value1 = "10";
      ArTest.equals("int vs String (NG)","value0",value0,"value1",value1);
    }
    // Integer vs Long
    {
      Integer value0 = 5;
      Long value1 = 5L;
      ArTest.equals("Integer vs Long","value0",value0,"value1",value1);
      value1 = 10L;
      ArTest.equals("Integer vs Long (NG)","value0",value0,"value1",value1);
    }
    // Integer vs Double
    {
      Integer value0 = 5;
      Double value1 = 5D;
      ArTest.equals("Integer vs Double","value0",value0,"value1",value1);
      value1 = 10D;
      ArTest.equals("Integer vs Double (NG)","value0",value0,"value1",value1);
    }
    // Integer vs BigDecimal
    {
      Integer value0 = 5;
      BigDecimal value1 = new BigDecimal(5);
      ArTest.equals("Integer vs BigDecimal","value0",value0,"value1",value1);
      value1 = new BigDecimal(10);
      ArTest.equals("Integer vs BigDecimal (NG)","value0",value0,"value1",value1);
    }
    //Integer vs String ⇒ Can be done without numerical value..⇒ It may be better not to use..
    {
      Integer value0 = 5;
      String value1 = "5";
      ArTest.equals("Integer vs String","value0",value0,"value1",value1);
      value1 = "10";
      ArTest.equals("Integer vs String (NG)","value0",value0,"value1",value1);
    }
    //
    ArTest.endTestCase();
  }

  ////////Below is a sample of JUnit4

  //Equal value judgment between ints-If equal
  @Test
  public void test00() {
    assertEquals(5,5);
  }

  //Equal value judgment between ints-If not equal
  @Test
  public void test01() {
    assertEquals(5,10);
  }

  //Int vs long equality judgment-If equal
  @Test
  public void test02() {
    assertEquals(5,5L);
  }

  //Int vs long equality judgment-If not equal
  @Test
  public void test03() {
    assertEquals(5,10L);
  }

  //Int vs double equality judgment
  @Test
  public void test04() {
    //In case of double, specify the judgment error
    assertEquals(5,5D,0.01D);
  }

  //Equal value judgment of int vs Big Decimal ⇒ NG even with the same value
  //I want this to be OK...⇒ If not, I want you to make a compile error
  @Test
  public void test05() {
    assertEquals(5,new BigDecimal(5));
  }

  //Equal value judgment of Integer vs Long ⇒ NG even with the same value
  //I want this to be OK...⇒ If not, I want you to make a compile error
  @Test
  public void test06() {
    assertEquals(new Integer(5),new Long(5L));
  }

  //Serpentine int vs String ⇒(Naturally)Become NG
  @Test
  public void test07() {
    assertEquals(5,"5");
  }
}

The result is as follows

無題.png

result.txt


**** Q02_00 start ****
OK int vs int:value0=5:value1=5
NG int vs int (NG):value0=5:value1=10
jp.avaj.lib.test.Q02_00.main(Q02_00.java:27)
OK int vs long:value0=5:value1=5
NG int vs long (NG):value0=5:value1=10
jp.avaj.lib.test.Q02_00.main(Q02_00.java:35)
OK int vs double:value0=5:value1=5
NG int vs double (NG):value0=5:value1=10
jp.avaj.lib.test.Q02_00.main(Q02_00.java:43)
OK int vs BigDecimal:value0=5:value1=5
NG int vs BigDecimal (NG):value0=5:value1=10
jp.avaj.lib.test.Q02_00.main(Q02_00.java:51)
OK int vs String:value0=5:value1=5
NG int vs String (NG):value0=5:value1=10
jp.avaj.lib.test.Q02_00.main(Q02_00.java:59)
OK Integer vs Long:value0=5:value1=5
NG Integer vs Long (NG):value0=5:value1=10
jp.avaj.lib.test.Q02_00.main(Q02_00.java:67)
OK Integer vs Double:value0=5:value1=5
NG Integer vs Double (NG):value0=5:value1=10
jp.avaj.lib.test.Q02_00.main(Q02_00.java:75)
OK Integer vs BigDecimal:value0=5:value1=5
NG Integer vs BigDecimal (NG):value0=5:value1=10
jp.avaj.lib.test.Q02_00.main(Q02_00.java:83)
OK Integer vs String:value0=5:value1=5
NG Integer vs String (NG):value0=5:value1=10
jp.avaj.lib.test.Q02_00.main(Q02_00.java:91)
**** Q02_00 summary ****
test count = 18
success    = 9

Recommended Posts

Java Unit Test Library-Artery / JUnit4-Numerical equality judgment
Java Unit Test Library-Artery-Current Date Judgment
Java Unit Test Library-Artery / JUnit4-Array Equivalence
Java Unit Test Library-Artery-Sample
Java Unit Test Library-Artery-ArValidator Validates Objects
Java Artery-Easy to use unit test library
Primality test Java
Automatic creation of Java unit test result report
[Java] Holiday judgment sample
Unit test with Junit.