package test.blog;

import static blog.BLOGUtil.parseEvidence_NE;
import static org.junit.Assert.assertEquals;

import java.util.Map;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import blog.BLOGUtil;
import blog.DBLOGUtil;
import blog.common.Util;
import blog.model.Evidence;
import blog.model.Model;
import blog.model.Queries;
import blog.type.Timestep;

/**
 * Unit tests for DBLOGUtil.
 */
@RunWith(JUnit4.class)
public class TestDBLOGUtil {
  @Test
  public void testSplitEvidenceInTime() {
    Model model = Model.fromString("random Boolean Weather(Timestep t) ~ true;"
        + "random Boolean Dummy ~ Bernoulli(0.5);");
    Evidence evidence;
    String evidenceDescription = "obs Weather(@15) = true;"
        + "obs Weather(@2) = true;" + "obs Dummy = true;";
    // TODO: test SymbolEvidenceStatements too.
    evidence = parseEvidence_NE(evidenceDescription, model);

    Map<Timestep, Evidence> splitEvidence = DBLOGUtil
        .splitEvidenceInTime(evidence);
    // System.out.println(splitEvidence);
    assertEquals(splitEvidence.size(), 3);
    // TODO: Make it easy to construct ValueEvidenceStatements, so that we
    // aren't forced to compare string representations here...
    assertEquals("[Dummy = true]", splitEvidence.get(null).toString());
    assertEquals("[Weather(@2) = true]", splitEvidence.get(Timestep.at(2))
        .toString());
    assertEquals("[Weather(@15) = true]", splitEvidence.get(Timestep.at(15))
        .toString());
  }

  @Test
  public void testSplitQueriesInTime() {
    Model model = Model.fromString("random Boolean Weather(Timestep t) ~ true;"
        + "random Boolean Dummy ~ Bernoulli(0.5);");
    Queries queries = new Queries(model);
    queries.add(BLOGUtil.parseQuery_NE("query Dummy;", model));
    queries.add(BLOGUtil.parseQuery_NE("query Weather(@3);", model));
    queries.add(BLOGUtil.parseQuery_NE("query Weather(@13);", model));

    Map<Timestep, Queries> splitQueries = DBLOGUtil.splitQueriesInTime(queries);
    // System.out.println(splitQueries);
    assertEquals(3, splitQueries.size());
    assertEquals(Util.list(queries.get(0)), splitQueries.get(null));
    assertEquals(Util.list(queries.get(1)), splitQueries.get(Timestep.at(3)));
    assertEquals(Util.list(queries.get(2)), splitQueries.get(Timestep.at(13)));
  }
}

@@ -17,54 +17,8 @@
 g;%0A%0A
-import static blog.BLOGUtil.parseEvidence_NE;%0A
 impo
@@ -176,30 +176,8 @@
 4;%0A%0A
-import blog.BLOGUtil;%0A
 impo
@@ -625,43 +625,59 @@
 ence
-;%0A    String evidenceDescription = 
+ = new Evidence(model);%0A    evidence.addFromString(
 %22obs
@@ -756,16 +756,17 @@
 = true;%22
+)
 ;%0A    //
@@ -810,69 +810,8 @@
 too.
-%0A    evidence = parseEvidence_NE(evidenceDescription, model);
 %0A%0A  
@@ -1641,166 +1641,67 @@
 .add
-(BLOGUtil.parseQuery_NE(%22query Dummy;%22, model));%0A    queries.add(BLOGUtil.parseQuery_NE(%22query Weather(@3);%22, model));%0A    queries.add(BLOGUtil.parseQuery_NE(
+FromString(%22query Dummy;%22 + %22query Weather(@3);%22%0A        + 
 %22que
@@ -1721,16 +1721,8 @@
 3);%22
-, model)
 );%0A%0A

change tests to parse evidence, queries without BLOGUtil