/** * */ package it.univr.di.labeledvalue; import org.junit.Test; import static org.junit.Assert.*; /** * @author posenato */ public class LiteralTest { /** * Test method for {@link it.univr.di.labeledvalue.Literal#parse(java.lang.String)}. */ @SuppressWarnings("static-method") @Test public final void testParse() { final Literal a = Literal.parse("a"); final Literal notA = Literal.parse("¬a"); final Literal unkA = Literal.parse("¿a"); assert a != null; assert notA != null; assert unkA != null; assertArrayEquals("Verifica del parser: ", new String[]{"a", "¬a", "¿a"}, new String[]{a.toString(), notA.toString(), unkA.toString()}); } /** * Test method for {@link it.univr.di.labeledvalue.Literal#compareTo(it.univr.di.labeledvalue.Literal)}. */ @SuppressWarnings({"static-method", "EqualsWithItself"}) @Test public final void testCompareTo() { final Literal a = Literal.parse("a"); final Literal notA = Literal.parse("¬a"); final Literal unkA = Literal.parse("¿a"); assert a != null; assert notA != null; assertTrue(a.compareTo(notA) < 0); assertEquals(0, a.compareTo(a)); assertTrue(notA.compareTo(a) > 0); // assertEquals(1, unkA.compareTo(a)); // assertEquals(2, unkA.compareTo(notA)); // assertEquals(0, unkA.compareTo(unkA)); assert unkA != null; assertTrue(unkA.compareTo(a) > 0); assertTrue(unkA.compareTo(notA) > 0); } /** * Test method for {@link it.univr.di.labeledvalue.Literal#equals(java.lang.Object)}. */ @SuppressWarnings("static-method") @Test public final void testEqualsObject() { final Literal a = Literal.parse("a"); final Literal notA = Literal.parse("¬a"); assertNotEquals(notA, a); } /** * Test method for {@link it.univr.di.labeledvalue.Literal#getComplement()}. */ @SuppressWarnings("static-method") @Test public final void testGetComplement() { final Literal a = Literal.parse("a"); assert a != null; final Literal notA = a.getComplement(); final Literal unA = Literal.valueOf('a', Literal.UNKNOWN); assertNotEquals(notA, a); assert unA != null; assertNull(unA.getComplement()); } /** * Test method for {@link it.univr.di.labeledvalue.Literal#toString()}. */ @SuppressWarnings("static-method") @Test public final void testToString() { final Literal a = Literal.parse("a"); final Literal notA = Literal.parse("¬a"); final Literal unkA = Literal.valueOf('a', Literal.UNKNOWN); assert a != null; assertEquals("a", a.toString()); assert notA != null; assertEquals("¬a", notA.toString()); assert unkA != null; assertEquals("¿a", unkA.toString()); // assertEquals(1, State.negated.ordinal()); // assertEquals(2, State.straight.ordinal()); // assertEquals(3, Literal.UNKNONW); } /** * Proposes only some execution time estimates about some class methods. * * @param args an array of {@link java.lang.String} objects. */ public static void main(final String[] args) { // final int nTest = 1000; // final double msNorm = 1.0 / (1000000.0 * nTest); int j = 0; for (char i = 'a'; i <= 'z'; i++) System.out.println((j++) + ": '" + (i) + "', "); for (char i = 'A'; i <= 'Z'; i++) System.out.println((j++) + ": '" + (i) + "', "); for (char i = 'α'; i <= 'μ'; i++) System.out.println((j++) + ": '" + (i) + "', "); //Proposition are only "a-zA-F" final Literal A = Literal.valueOf('A'), B = Literal.valueOf('B', Literal.STRAIGHT), b = Literal.valueOf('b'), a = Literal.valueOf('a'), z = Literal.valueOf('z'); System.out.println("A: " + A); System.out.println("a: " + a); System.out.println("z: " + z); System.out.println("Hashcode A: " + A.hashCode()); assert B != null; System.out.println("Hashcode B: " + B.hashCode()); System.out.println("Hashcode a: " + a.hashCode()); System.out.println("Hashcode b: " + b.hashCode()); System.out.println("Hashcode z: " + z.hashCode()); System.out.println("Index of 'A': " + Literal.index('A')); System.out.println("Index of 'B': " + Literal.index('B')); System.out.println("Index of 'Z': " + Literal.index('Z')); System.out.println("Index of 'a': " + Literal.index('a')); System.out.println("Index of 'b': " + Literal.index('b')); System.out.println("Index of 'z': " + Literal.index('z')); System.out.println("CharValue of 0: " + Literal.charValue(0)); System.out.println("CharValue of 1: " + Literal.charValue(1)); System.out.println("CharValue of 25: " + Literal.charValue(25)); System.out.println("CharValue of 26: " + Literal.charValue(26)); System.out.println("CharValue of 27: " + Literal.charValue(27)); } }