/** * */ package it.univr.di.labeledvalue; import it.unimi.dsi.fastutil.objects.ObjectRBTreeSet; import it.unimi.dsi.fastutil.objects.ObjectSortedSet; import org.junit.Test; import java.util.Objects; import static org.junit.Assert.*; /** * @author posenato */ @SuppressWarnings("MethodMayBeStatic") public class LabelTest { /** * Proposes only some execution time estimates about some class methods. * * @param args an array of {@link java.lang.String} objects. */ @SuppressWarnings("ResultOfMethodCallIgnored") public static void main(final String[] args) { final int nTest = 1000; final double msNorm = 1.0 / (1000000.0 * nTest); final Literal d = Literal.valueOf('d'), z = Literal.valueOf('z'); final Label empty = Label.emptyLabel; System.out.println("Empty: " + empty); Label result; // System.out.println("Empty: " + result); result = Label.valueOf('a', Literal.STRAIGHT); System.out.println("a: " + result); result = Label.valueOf('b', Literal.NEGATED); System.out.println("¬b: " + result); result = Label.valueOf('a', Literal.ABSENT); System.out.println("Null: " + result); Label l1 = Label.parse(Constants.NOT + "abcd"); Label l2 = Label.parse(Constants.NOT + "aejfsd"); System.out.println("l1: " + l1 + "\nl2: " + l2); long startTime = System.nanoTime(); assert l1 != null; for (int i = 0; i < nTest; i++) { result = l1.conjunction(l2); } long endTime = System.nanoTime(); System.out.println( "Execution time for a simple conjunction of '" + l1 + "' with '" + l2 + "'='" + result + "' (ms): " + ((endTime - startTime) * msNorm)); l1 = Label.parse(Constants.NOT + "abcd"); l2 = Label.parse("a¬d¬cejfs"); startTime = System.nanoTime(); assert l1 != null; assert l2 != null; for (int i = 0; i < nTest; i++) { result = l1.conjunctionExtended(l2); } endTime = System.nanoTime(); System.out.println( "Execution time for an extended conjunction of '" + l1 + "' with '" + l2 + "'='" + result + "' (ms): " + ((endTime - startTime) * msNorm)); startTime = System.nanoTime(); for (int i = 0; i < nTest; i++) { l1.isConsistentWith(l2); } endTime = System.nanoTime(); System.out.println("Execution time for checking if two (inconsistent) labels are consistent. Details '" + l1 + "' with '" + l2 + "' (ms): " + ((endTime - startTime) * msNorm)); startTime = System.nanoTime(); for (int i = 0; i < nTest; i++) { l1.isConsistentWith(l1); } endTime = System.nanoTime(); System.out.println("Execution time for checking if two (consistent) labels are consistent. Details '" + l1 + "' with '" + l1 + "' (ms): " + ((endTime - startTime) * msNorm)); startTime = System.nanoTime(); for (int i = 0; i < nTest; i++) { l1.contains(d); } endTime = System.nanoTime(); System.out.println( "Execution time for checking if a literal is present in a label (the literal is the last inserted) (ms): " + ((endTime - startTime) * msNorm)); startTime = System.nanoTime(); for (int i = 0; i < nTest; i++) { l1.contains('d'); } endTime = System.nanoTime(); System.out.println("Execution time for checking if a literal is present in a label (given the name) (ms): " + ((endTime - startTime) * msNorm)); startTime = System.nanoTime(); for (int i = 0; i < nTest; i++) { l1.contains(z); } endTime = System.nanoTime(); System.out.println( "Execution time for checking if a literal is present in a label (the literal is not present) (ms): " + ((endTime - startTime) * msNorm)); startTime = System.nanoTime(); for (int i = 0; i < nTest; i++) { l1.contains('d'); } endTime = System.nanoTime(); System.out.println("Execution time for get the literal in the label with the same proposition letter (the literal is present) (ms): " + ((endTime - startTime) * msNorm)); startTime = System.nanoTime(); for (int i = 0; i < nTest; i++) { l1.contains('z'); } endTime = System.nanoTime(); System.out.println("Execution time for get the literal in the label with the same proposition letter (the literal is not present) (ms): " + ((endTime - startTime) * msNorm)); } /** * */ @SuppressWarnings("static-method") @Test public final void caso20141128() { final Label bgp = Label.parse("bgp"); final Label cp = Label.parse("cp"); assert bgp != null; assertFalse(bgp.subsumes(cp)); } /** * */ @SuppressWarnings({"static-method", "UnnecessaryLocalVariable"}) @Test public final void cloneEmptyLabel() { final Label a = Label.emptyLabel; final Label b = a; // for(char c='A'; c< 'ù'; c++) // System.out.println("Char "+c+" to int:"+Character.hashCode(c)); assertEquals(a, b); assertEquals(0, b.size()); } /** * */ @SuppressWarnings("static-method") @Test public final void comparatorOrder() { final ObjectSortedSet