Skip to content

Commit

Permalink
More tests for ComposableEventSet
Browse files Browse the repository at this point in the history
  • Loading branch information
michbarsinai committed Mar 5, 2019
1 parent f2833c0 commit 0fc1374
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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<EventSet> ifces) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) );
}

/**
Expand Down Expand Up @@ -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()) );
}

/**
Expand Down Expand Up @@ -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<EventSet> 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()) );
}

/**
Expand All @@ -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()) );
}

/**
Expand All @@ -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) );
}

}

0 comments on commit 0fc1374

Please sign in to comment.