package ch.hevs.aislab.magpie.test.java;


import org.junit.Test;

import alice.tuprolog.Term;
import ch.hevs.aislab.magpie.event.LogicTupleEvent;

import static junit.framework.TestCase.assertEquals;

public class LogicTupleTest {

    @Test
    public void createLogicTuple() {

        // This method tests if the following LogicTuple is created correctly using the different constructors
        final String logicTuple = "blood_pressure(Sys,Dias)";

        // Creation with multiple arguments
        LogicTupleEvent bp1 = new LogicTupleEvent("blood_pressure", "Sys", "Dias");
        String tupleFromArgs = bp1.toTuple();
        assertEquals(logicTuple, tupleFromArgs);

        // Creation from a tuProlog Term
        Term t = Term.createTerm(logicTuple);
        LogicTupleEvent bp2 = new LogicTupleEvent(t);
        String tupleFromTerm = bp2.toTuple();
        assertEquals(logicTuple, tupleFromTerm);

        // Creation from String
        LogicTupleEvent bp3 = new LogicTupleEvent(logicTuple);
        String tupleFromString = bp3.toTuple();
        assertEquals(logicTuple, tupleFromString);
    }

    @Test
    public void getNameAndArguments() {

        String name = "blood_pressure";
        String arg1 = "Sys";
        String arg2 = "Dias";
        LogicTupleEvent ev = new LogicTupleEvent(name, arg1, arg2);

        assertEquals(name, ev.getName());
        assertEquals(arg1, ev.getArguments().get(0));
        assertEquals(arg2, ev.getArguments().get(1));
    }
}

@@ -1484,11 +1484,539 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void getTimestampAsString() %7B%0A%0A        long timestamp = System.currentTimeMillis();%0A%0A        LogicTupleEvent ev1 = new LogicTupleEvent(timestamp, %22glucose%22, %225.5%22);%0A        LogicTupleEvent ev2 = new LogicTupleEvent(%22glucose%22, %225.5%22);%0A%0A        String dateEv1 = ev1.getStringTimestamp(%22dd.MM.yyyy%22);%0A        String dateEv2 = ev2.getStringTimestamp(%22dd.MM.yyyy%22);%0A%0A        // Checks that both dates are the same, so the test might fail if it runs around midnight%0A        assertEquals(dateEv1, dateEv2);%0A    %7D
 %0A%7D%0A

Test the new method in LogicTuple class