diff --git a/README.md b/README.md index 27e88074..7b1e85d5 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,14 @@ a link to this page somewhere in the documentation/system about section. ### 2019-03-05 * :sparkles: Serious makeover for the composable event suite. Users can no compose event sets using `or`,`and`, and `not` (and even `xor`, `nor` and `nand`) and get semantically correct sets that support verification. + for example, this works: +```java +EventSet sutA = theEventSet(E_A).or(E_B).and( theEventSet(E_B).or(E_C) ); +EventSet sutB = theEventSet(E_C).or(E_B).and( theEventSet(E_B).or(E_A) ); +assertEquals( sutA, sutB ); +``` * :arrow_up: `ComposableEventSet` refactored to have `equals` and `hashCode` that can hold during verification. +* :arrow_up: More tests. ### 2019-02-10 * :arrow_up: Improved hash functions for `ContinuationProgramState` (affects b-thread sync snapshots as well). diff --git a/src/main/java/il/ac/bgu/cs/bp/bpjs/model/eventsets/ComposableEventSet.java b/src/main/java/il/ac/bgu/cs/bp/bpjs/model/eventsets/ComposableEventSet.java index 9a7bd6e2..e6ae0b72 100644 --- a/src/main/java/il/ac/bgu/cs/bp/bpjs/model/eventsets/ComposableEventSet.java +++ b/src/main/java/il/ac/bgu/cs/bp/bpjs/model/eventsets/ComposableEventSet.java @@ -171,7 +171,7 @@ public boolean contains(BEvent event) { public ComposableEventSet and( EventSet ifce ) { if ( ifce instanceof AllOf ) { return new AllOf( - Stream.concat(events.stream(), ((AnyOf)ifce).events.stream()) + Stream.concat(events.stream(), ((AllOf)ifce).events.stream()) .collect( toSet() )); } else if ( ifce instanceof EventSet ) { return new AllOf( @@ -251,7 +251,7 @@ public static ComposableEventSet theEventSet( final EventSet ifce ) { public static ComposableEventSet not( final EventSet ifce ) { if ( ifce==null ) throw new IllegalArgumentException("eventset cannot be null"); - return (ifce instanceof Not) ? theEventSet(((Not)ifce).negated) : new Not(ifce); + return (ifce instanceof Not) ? theEventSet(((Not)ifce).negated) : new Not(w(ifce)); } public static ComposableEventSet anyOf( final Collection ifces) { diff --git a/src/test/java/il/ac/bgu/cs/bp/bpjs/model/eventsets/ComposableEventSetTest.java b/src/test/java/il/ac/bgu/cs/bp/bpjs/model/eventsets/ComposableEventSetTest.java index 4110a552..a5a03f6f 100644 --- a/src/test/java/il/ac/bgu/cs/bp/bpjs/model/eventsets/ComposableEventSetTest.java +++ b/src/test/java/il/ac/bgu/cs/bp/bpjs/model/eventsets/ComposableEventSetTest.java @@ -94,9 +94,12 @@ public void testNot() { assertFalse( sut.contains(E_A) ); assertTrue( sut.contains(E_B) ); assertEquals( sut, not(not(sut)) ); + assertEquals( sut, not(E_A) ); assertTrue( sut.toString().contains( E_A.toString() )); assertTrue( sut.toString().contains( "not" )); + + assertFalse( sut.equals(new Object()) ); } /** @@ -212,6 +215,8 @@ public void testAnd() { same.add(theEventSet(E_C).and(E_A).and(E_B)); same.add(theEventSet(E_C).and(E_A).and(E_B).and(E_A)); assertEquals( 1, same.size() ); + + assertFalse( sut.equals(new Object()) ); } /** @@ -243,6 +248,15 @@ public void testXor() { assertTrue( sut.toString().contains("xor") ); assertTrue( sut.toString().contains(aOrB.toString()) ); assertTrue( sut.toString().contains(bOrC.toString()) ); + + HashSet sets = new HashSet<>(); + + sets.add( aOrB.xor(bOrC) ); + sets.add( bOrC.xor(aOrB) ); + sets.add( bOrC.xor(E_A) ); + assertEquals(2, sets.size() ); + + assertFalse( sut.equals(new Object()) ); } /** @@ -263,6 +277,8 @@ public void testNor() { assertTrue( sut.toString().contains("any") ); assertTrue( sut.toString().contains(aOrB.toString()) ); assertTrue( sut.toString().contains(bOrC.toString()) ); + + assertFalse( sut.equals(new Object()) ); } /** @@ -285,4 +301,21 @@ public void testNand() { assertTrue( sut.toString().contains(bOrC.toString()) ); } + @Test + public void testSemantics() { + EventSet sutA = theEventSet(E_A).or(E_B).and( theEventSet(E_B).or(E_C) ); + EventSet sutB = theEventSet(E_C).or(E_B).and( theEventSet(E_B).or(E_A) ); + assertEquals( sutA, sutB ); + + assertEquals( allOf(E_A, E_B, E_C, E_D), allOf(E_A, E_B).and(allOf(E_C, E_D)) ); + assertEquals( allOf(E_A, E_B, E_C, E_D), allOf(E_A, E_B, E_B, E_B).and(allOf(E_C, E_D)) ); + + assertEquals( anyOf(E_A, E_B, E_C, E_D), anyOf(E_A, E_B).or(anyOf(E_C, E_D)) ); + assertEquals( anyOf(E_A, E_B, E_C, E_D), anyOf(E_A, E_B, E_B, E_B).or(anyOf(E_C, E_D)) ); + + assertTrue( theEventSet(E_A).xor(E_B).or(E_C).contains(E_A) ); + assertTrue( theEventSet(E_A).xor(E_B).or(E_C).contains(E_B) ); + assertTrue( theEventSet(E_A).xor(E_B).or(E_C).contains(E_C) ); + } + }