Search in sources :

Example 26 with SingleResourceBProgram

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);
}
Also used : PrintBProgramRunnerListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener) EventPattern(il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern) StringWriter(java.io.StringWriter) BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) InMemoryEventLoggingListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 27 with SingleResourceBProgram

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");
}
Also used : PrintBProgramRunnerListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener) BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) JFrame(javax.swing.JFrame) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) PrioritizedBSyncEventSelectionStrategy(il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)

Example 28 with SingleResourceBProgram

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]));
            }
        }
    }
}
Also used : SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) Test(org.junit.Test)

Example 29 with SingleResourceBProgram

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;
}
Also used : SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)

Example 30 with SingleResourceBProgram

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));
}
Also used : PrintBProgramRunnerListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener) BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)

Aggregations

SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)45 Test (org.junit.Test)38 BProgramRunner (il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner)29 PrintBProgramRunnerListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener)26 InMemoryEventLoggingListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener)22 BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)17 BEvent (il.ac.bgu.cs.bp.bpjs.model.BEvent)14 EventPattern (il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern)10 DfsBProgramVerifier (il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier)9 VerificationResult (il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult)9 StringBProgram (il.ac.bgu.cs.bp.bpjs.model.StringBProgram)7 BriefPrintDfsVerifierListener (il.ac.bgu.cs.bp.bpjs.analysis.listeners.BriefPrintDfsVerifierListener)4 PrioritizedBSyncEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)3 BProgramStateVisitedStateStore (il.ac.bgu.cs.bp.bpjs.analysis.BProgramStateVisitedStateStore)2 Node (il.ac.bgu.cs.bp.bpjs.analysis.Node)1 BProgramRunnerListenerAdapter (il.ac.bgu.cs.bp.bpjs.execution.listeners.BProgramRunnerListenerAdapter)1 ExecutorServiceMaker (il.ac.bgu.cs.bp.bpjs.internal.ExecutorServiceMaker)1 BProgramSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot)1 FailedAssertion (il.ac.bgu.cs.bp.bpjs.model.FailedAssertion)1 LoggingEventSelectionStrategyDecorator (il.ac.bgu.cs.bp.bpjs.model.eventselection.LoggingEventSelectionStrategyDecorator)1