use of il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram in project BPjs by bThink-BGU.
the class LoggingEventSelectionStrategyDecoratorTest method superStepTest.
@Test
public void superStepTest() throws InterruptedException, IOException {
StringWriter strOut = new StringWriter();
try (PrintWriter outWriter = new PrintWriter(strOut)) {
LoggingEventSelectionStrategyDecorator sut = new LoggingEventSelectionStrategyDecorator(new SimpleEventSelectionStrategy(), outWriter);
SingleResourceBProgram bp = new SingleResourceBProgram("HotNCold.js");
bp.setEventSelectionStrategy(sut);
BProgramRunner runner = new BProgramRunner(bp);
runner.addListener(new PrintBProgramRunnerListener());
InMemoryEventLoggingListener eventLogger = runner.addListener(new InMemoryEventLoggingListener());
runner.run();
EventPattern expected = new EventPattern().append(coldEvent).append(hotEvent).append(coldEvent).append(hotEvent).append(coldEvent).append(hotEvent).append(allDoneEvent);
assertTrue(expected.matches(eventLogger.getEvents()));
outWriter.flush();
}
strOut.flush();
strOut.close();
String output = strOut.toString();
System.out.println("output = " + output);
int selectableEventsLogs = Arrays.stream(output.split("\n")).filter(s -> s.contains("== Choosing Selectable Events ==")).collect(toList()).size();
assertEquals(7, selectableEventsLogs);
int eventSelections = Arrays.stream(output.split("\n")).filter(s -> s.contains("== Actual Event Selection ======")).collect(toList()).size();
assertEquals(7, eventSelections);
}
use of il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram in project BPjs by bThink-BGU.
the class TTTButton method main.
public static void main(String[] args) throws InterruptedException {
// Create a program
BProgram bprog = new SingleResourceBProgram("BPJSTicTacToe.js");
bprog.setEventSelectionStrategy(new PrioritizedBSyncEventSelectionStrategy());
bprog.setDaemonMode(true);
JFrame f = new TicTacToeGameMain();
BProgramRunner rnr = new BProgramRunner(bprog);
rnr.addListener(new PrintBProgramRunnerListener());
TTTdisplayGame = new TTTDisplayGame(bprog, rnr);
rnr.run();
System.out.println("end of run");
}
use of il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram 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]));
}
}
}
}
use of il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram in project BPjs by bThink-BGU.
the class Mazes method prepareProgram.
private SingleResourceBProgram prepareProgram() {
// Create a program
final SingleResourceBProgram bprog = new SingleResourceBProgram(implementation);
bprog.putInGlobalScope("MAZE_NAME", mazeName);
bprog.putInGlobalScope("TARGET_FOUND_EVENT", targetFoundEvent);
return bprog;
}
use of il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram in project BPjs by bThink-BGU.
the class Mazes method run.
public void run() throws InterruptedException {
SingleResourceBProgram bprog = prepareProgram();
BProgramRunner rnr = new BProgramRunner(bprog);
rnr.addListener(new PrintBProgramRunnerListener());
rnr.run();
printMaze(getMaze(bprog));
}
Aggregations