Search in sources :

Example 1 with SimpleCycleResult

use of io.engineblock.activityapi.cyclelog.outputs.SimpleCycleResult in project engineblock by engineblock.

the class ResultFilteringSieveTest method testBasicFilter.

@Test
public void testBasicFilter() {
    ResultFilteringSieve sieve = new ResultFilteringSieve.Builder().discardByDefault().include(3).build();
    assertThat(sieve.apply(new SimpleCycleResult(3L, 2))).isEqualTo(TristateFilter.Policy.Discard);
    assertThat(sieve.apply(new SimpleCycleResult(3L, 3))).isEqualTo(TristateFilter.Policy.Keep);
}
Also used : ResultFilteringSieve(io.engineblock.activityapi.cyclelog.filters.tristate.ResultFilteringSieve) SimpleCycleResult(io.engineblock.activityapi.cyclelog.outputs.SimpleCycleResult) Test(org.testng.annotations.Test)

Example 2 with SimpleCycleResult

use of io.engineblock.activityapi.cyclelog.outputs.SimpleCycleResult in project engineblock by engineblock.

the class ResultFilteringSieveTest method testDefaultPolicy.

@Test
public void testDefaultPolicy() {
    ResultFilteringSieve sieve = new ResultFilteringSieve.Builder().discardByDefault().build();
    assertThat(sieve.apply(new SimpleCycleResult(4, 5))).isEqualTo(TristateFilter.Policy.Discard);
}
Also used : ResultFilteringSieve(io.engineblock.activityapi.cyclelog.filters.tristate.ResultFilteringSieve) SimpleCycleResult(io.engineblock.activityapi.cyclelog.outputs.SimpleCycleResult) Test(org.testng.annotations.Test)

Example 3 with SimpleCycleResult

use of io.engineblock.activityapi.cyclelog.outputs.SimpleCycleResult in project engineblock by engineblock.

the class ResultFilteringSieveTest method testPredicateConversions.

public void testPredicateConversions() {
    SimpleCycleResult c1 = new SimpleCycleResult(1, 1);
    SimpleCycleResult c2 = new SimpleCycleResult(2, 2);
    SimpleCycleResult c3 = new SimpleCycleResult(3, 3);
    SimpleCycleResult c4 = new SimpleCycleResult(4, 4);
    SimpleCycleResult c5 = new SimpleCycleResult(5, 5);
    SimpleCycleResult c6 = new SimpleCycleResult(6, 6);
    SimpleCycleResult c7 = new SimpleCycleResult(7, 7);
    List<CycleResult> results = new ArrayList<CycleResult>() {

        {
            add(c1);
            add(c2);
            add(c3);
            add(c4);
            add(c5);
            add(c6);
            add(c7);
        }
    };
    Predicate<ResultReadable> includer = new ResultFilteringSieve.Builder().include(3).exclude(4).build().toInclusivePredicate();
    List<CycleResult> included = results.stream().filter(includer).collect(Collectors.toList());
    assertThat(included).containsExactly(c1, c2, c3, c5, c6, c7);
    Predicate<ResultReadable> excluder = new ResultFilteringSieve.Builder().include(3).exclude(4).build().toExclusivePredicate();
    List<CycleResult> excluded = results.stream().filter(excluder).collect(Collectors.toList());
    assertThat(excluded).containsExactly(c3);
}
Also used : SimpleCycleResult(io.engineblock.activityapi.cyclelog.outputs.SimpleCycleResult) ArrayList(java.util.ArrayList) ResultReadable(io.engineblock.activityapi.cyclelog.buffers.results.ResultReadable) SimpleCycleResult(io.engineblock.activityapi.cyclelog.outputs.SimpleCycleResult) CycleResult(io.engineblock.activityapi.cyclelog.buffers.results.CycleResult)

Example 4 with SimpleCycleResult

use of io.engineblock.activityapi.cyclelog.outputs.SimpleCycleResult in project engineblock by engineblock.

the class CoreResultFilterTest method testComponentLifecycle.

@Test
public void testComponentLifecycle() {
    ResultValueFilterType filterType = CoreResultValueFilter.FINDER.get("core").orElseThrow(() -> new RuntimeException("Unable to find " + ResultValueFilterType.class.getSimpleName() + " for 'core'"));
    ResultFilterDispenser fd = filterType.getDispenser("in:5,ex:6,in:7");
    Predicate<ResultReadable> cycleResultFilter = fd.getResultFilter();
    assertThat(cycleResultFilter.test(new SimpleCycleResult(3, 3))).isFalse();
    assertThat(cycleResultFilter.test(new SimpleCycleResult(3, 5))).isTrue();
    assertThat(cycleResultFilter.test(new SimpleCycleResult(3, 6))).isFalse();
    assertThat(cycleResultFilter.test(new SimpleCycleResult(3, 7))).isTrue();
    assertThat(cycleResultFilter.test(new SimpleCycleResult(3, 8))).isFalse();
}
Also used : ResultFilterDispenser(io.engineblock.activityapi.cyclelog.filters.ResultFilterDispenser) SimpleCycleResult(io.engineblock.activityapi.cyclelog.outputs.SimpleCycleResult) ResultValueFilterType(io.engineblock.activityapi.cyclelog.filters.ResultValueFilterType) ResultReadable(io.engineblock.activityapi.cyclelog.buffers.results.ResultReadable) Test(org.testng.annotations.Test)

Example 5 with SimpleCycleResult

use of io.engineblock.activityapi.cyclelog.outputs.SimpleCycleResult in project engineblock by engineblock.

the class ResultFilteringSieveTest method testRangeFilter.

@Test
public void testRangeFilter() {
    ResultFilteringSieve sieve = new ResultFilteringSieve.Builder().keepByDefault().exclude(3, 7).exclude(9).build();
    assertThat(sieve.apply(new SimpleCycleResult(3L, 2))).isEqualTo(TristateFilter.Policy.Keep);
    assertThat(sieve.apply(new SimpleCycleResult(3L, 3))).isEqualTo(TristateFilter.Policy.Discard);
    assertThat(sieve.apply(new SimpleCycleResult(3L, 7))).isEqualTo(TristateFilter.Policy.Discard);
    assertThat(sieve.apply(new SimpleCycleResult(3L, 8))).isEqualTo(TristateFilter.Policy.Keep);
    assertThat(sieve.apply(new SimpleCycleResult(3L, 9))).isEqualTo(TristateFilter.Policy.Discard);
    assertThat(sieve.apply(new SimpleCycleResult(3L, 10))).isEqualTo(TristateFilter.Policy.Keep);
}
Also used : ResultFilteringSieve(io.engineblock.activityapi.cyclelog.filters.tristate.ResultFilteringSieve) SimpleCycleResult(io.engineblock.activityapi.cyclelog.outputs.SimpleCycleResult) Test(org.testng.annotations.Test)

Aggregations

SimpleCycleResult (io.engineblock.activityapi.cyclelog.outputs.SimpleCycleResult)5 Test (org.testng.annotations.Test)4 ResultFilteringSieve (io.engineblock.activityapi.cyclelog.filters.tristate.ResultFilteringSieve)3 ResultReadable (io.engineblock.activityapi.cyclelog.buffers.results.ResultReadable)2 CycleResult (io.engineblock.activityapi.cyclelog.buffers.results.CycleResult)1 ResultFilterDispenser (io.engineblock.activityapi.cyclelog.filters.ResultFilterDispenser)1 ResultValueFilterType (io.engineblock.activityapi.cyclelog.filters.ResultValueFilterType)1 ArrayList (java.util.ArrayList)1