use of il.ac.bgu.cs.bp.bpjs.model.BProgram in project BPjs by bThink-BGU.
the class ContinuationProgramStateTest method testLoopSameWhenNoVarChanges.
@Test
public void testLoopSameWhenNoVarChanges() throws Exception {
// Generate snapshot 1
BProgram bprog = new StringBProgram(SRC_LOOP);
BProgramSyncSnapshot cur = bprog.setup();
cur = cur.start(exSvc);
BThreadSyncSnapshot snapshot = cur.getBThreadSnapshots().iterator().next();
NativeContinuation nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sutPre = new ContinuationProgramState(nc);
cur = cur.triggerEvent(new BEvent("e"), exSvc, emptySet());
snapshot = cur.getBThreadSnapshots().iterator().next();
nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sutLoop1 = new ContinuationProgramState(nc);
// Generate more snapshots
for (int i = 0; i < 10; i++) {
cur = cur.triggerEvent(new BEvent("e"), exSvc, emptySet());
snapshot = cur.getBThreadSnapshots().iterator().next();
nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sutCurLoop = new ContinuationProgramState(nc);
assertEquals(sutLoop1, sutCurLoop);
assertNotEquals(sutPre, sutCurLoop);
}
}
use of il.ac.bgu.cs.bp.bpjs.model.BProgram in project BPjs by bThink-BGU.
the class ContinuationProgramStateTest method testStackHeight.
@Test
public void testStackHeight() throws Exception {
// Generate a continuation
BProgram bprog = new StringBProgram(SRC_SHORT);
BProgramSyncSnapshot cur = bprog.setup();
cur = cur.start(exSvc);
BThreadSyncSnapshot snapshot = cur.getBThreadSnapshots().iterator().next();
// Read frame data of P1
NativeContinuation nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sut1 = new ContinuationProgramState(nc);
assertEquals(0, sut1.getFrameIndex());
bprog = new StringBProgram(SRC_MORE_FUNC);
cur = bprog.setup();
cur = cur.start(exSvc);
snapshot = cur.getBThreadSnapshots().iterator().next();
// Read frame data of P1
nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sut2 = new ContinuationProgramState(nc);
assertEquals(1, sut2.getFrameIndex());
}
use of il.ac.bgu.cs.bp.bpjs.model.BProgram in project BPjs by bThink-BGU.
the class ContinuationProgramStateTest method testCorrectExtraction.
@Test
public void testCorrectExtraction() throws Exception {
// Generate a continuation
BProgram bprog = new StringBProgram(SRC);
BProgramSyncSnapshot cur = bprog.setup();
cur = cur.start(exSvc);
final BThreadSyncSnapshot snapshot = cur.getBThreadSnapshots().iterator().next();
// Read frame data
NativeContinuation nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sut = new ContinuationProgramState(nc);
assertEquals(0, sut.getFrameIndex());
assertEquals("gVar content", sut.getVisibleVariables().get("gVar"));
assertEquals("fVar content", sut.getVisibleVariables().get("fVar"));
assertEquals("updated content", sut.getVisibleVariables().get("shadowed"));
assertEquals(2.42, sut.getVisibleVariables().get("fDblVar2"));
}
use of il.ac.bgu.cs.bp.bpjs.model.BProgram in project BPjs by bThink-BGU.
the class NodeEqualsTest method basicsTest.
@Test
public void basicsTest() throws Exception {
// Create a program
final BProgram bprog = new StringBProgram(P1);
Node[] nodes = new Node[10];
BEvent eventX = new BEvent("X");
// Discard initial node, as it has no event, and so can't
// be used in the even/odd equalities later.
nodes[0] = Node.getInitialNode(bprog, exSvc).getNextNode(eventX, exSvc);
assertTrue(nodes[0].equals(nodes[0]));
assertFalse(nodes[0].equals(null));
assertFalse(nodes[0].equals("Not a Node"));
}
use of il.ac.bgu.cs.bp.bpjs.model.BProgram in project BPjs by bThink-BGU.
the class NodeEqualsTest method test2.
@Test
public void test2() throws Exception {
final BProgram bprog = new SingleResourceBProgram("BPJSDiningPhil.js");
bprog.putInGlobalScope("PHILOSOPHER_COUNT", 5);
String[] events = { "Pick1R", "Pick2R", "Pick3R", "Pick4R", "Pick5R" };
Node[] nodes = new Node[events.length + 1];
nodes[0] = Node.getInitialNode(bprog, exSvc);
for (int i = 0; i < events.length; i++) {
nodes[i + 1] = nodes[i].getNextNode(new BEvent(events[i]), exSvc);
}
for (int i = 0; i < nodes.length; i++) {
for (int j = 0; j < nodes.length; j++) {
if (i != j) {
assertFalse("node " + i + " should not equal node " + j, nodes[i].equals(nodes[j]));
}
}
}
}
Aggregations