Ensure that the two values given are equal, if not fail the test - Java java.lang

Java examples for java.lang:int

Description

Ensure that the two values given are equal, if not fail the test

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        float a1 = 2.45678f;
        float a2 = 2.45678f;
        assertEquals(a1, a2);/*from   w  w  w .  j  av a2s. c o  m*/
    }

    /**
     * Ensure that the two values given are equal, if not fail the test
     * 
     * @param a1
     *            The first value to compare
     * @param a2
     *            The second value to compare
     */
    public static void assertEquals(float a1, float a2) {
        if (a1 != a2) {
            throw new RuntimeException("TEST FAILS: " + a1 + " should be "
                    + a2);
        }
    }

    /**
     * Ensure that the two values given are equal, if not fail the test
     * 
     * @param a1
     *            The first value to compare
     * @param a2
     *            The second value to compare
     */
    public static void assertEquals(int a1, int a2) {
        if (a1 != a2) {
            throw new RuntimeException("TEST FAILS: " + a1 + " should be "
                    + a2);
        }
    }

    /**
     * Ensure that the two values given are equal, if not fail the test
     * 
     * @param a1
     *            The first value to compare
     * @param a2
     *            The second value to compare
     */
    public static void assertEquals(Object a1, Object a2) {
        if (!a1.equals(a2)) {
            throw new RuntimeException("TEST FAILS: " + a1 + " should be "
                    + a2);
        }
    }
}

Related Tutorials