Cnf { public static IConjunct convert( ICondition condition) { return new Converter().convert( condition); }  static IConjunct negate( IConjunct conjunct); static IConjunct either( IConjunct conjunct1, IConjunct conjunct2); static IConjunct refactor( IConjunct conjunct); static IConjunct remainder( IConjunct conjunct, IAssertion assertion); static IAssertion toAssertion( IDisjunct disjunct); static IConjunct simplify( IConjunct conjunct); static IDisjunct simplify( IDisjunct disjunct); static boolean isTautology( IDisjunct disjunct); static IConjunct convert( ICondition condition); static boolean satisfiesSome( IConjunct condition, PropertySet properties); static IConjunct getUnsatisfied( IConjunct condition, PropertySet properties);  }
@Test public void convertAnyOf() { ICondition condition = new AnyOf() .add( new AllOf().add( new ContainsAll( "A")).add( new ContainsAll( "B"))) .add( new ContainsAll( "C")); IConjunct conjunct = Cnf.convert( condition); IDisjunct[] disjuncts = IteratorUtils.toArray( conjunct.getDisjuncts(), IDisjunct.class); assertThat( "Disjuncts", disjuncts.length, is( 2)); assertThat( "Satisfied: A, B, C", conjunct.satisfied( new PropertySet( "A", "B", "C")), is( true)); assertThat( "Satisfied: A, B, !C", conjunct.satisfied( new PropertySet( "A", "B")), is( true)); assertThat( "Satisfied: A, !B, C", conjunct.satisfied( new PropertySet( "A", "C")), is( true)); assertThat( "Satisfied: A, !B, !C", conjunct.satisfied( new PropertySet( "A")), is( false)); assertThat( "Satisfied: !A, B, C", conjunct.satisfied( new PropertySet( "B", "C")), is( true)); assertThat( "Satisfied: !A, !B, C", conjunct.satisfied( new PropertySet( "C")), is( true)); assertThat( "Satisfied: !A, B, !C", conjunct.satisfied( new PropertySet( "B")), is( false)); assertThat( "Satisfied: !A, !B, !C", conjunct.satisfied( new PropertySet()), is( false)); condition = new Not( condition); conjunct = Cnf.convert( condition); disjuncts = IteratorUtils.toArray( conjunct.getDisjuncts(), IDisjunct.class); assertThat( "Disjuncts", disjuncts.length, is( 2)); assertThat( "Satisfied: A, B, C", conjunct.satisfied( new PropertySet( "A", "B", "C")), is( false)); assertThat( "Satisfied: A, B, !C", conjunct.satisfied( new PropertySet( "A", "B")), is( false)); assertThat( "Satisfied: A, !B, C", conjunct.satisfied( new PropertySet( "A", "C")), is( false)); assertThat( "Satisfied: A, !B, !C", conjunct.satisfied( new PropertySet( "A")), is( true)); assertThat( "Satisfied: !A, B, C", conjunct.satisfied( new PropertySet( "B", "C")), is( false)); assertThat( "Satisfied: !A, !B, C", conjunct.satisfied( new PropertySet( "C")), is( false)); assertThat( "Satisfied: !A, B, !C", conjunct.satisfied( new PropertySet( "B")), is( true)); assertThat( "Satisfied: !A, !B, !C", conjunct.satisfied( new PropertySet()), is( true)); }
@Test public void convertNot() { ICondition condition = new Not() .add( new AnyOf().add( new ContainsAny( "A", "B")).add( new ContainsAny( "C"))); IConjunct conjunct = Cnf.convert( condition); IDisjunct[] disjuncts = IteratorUtils.toArray( conjunct.getDisjuncts(), IDisjunct.class); assertThat( "Disjuncts", disjuncts.length, is( 3)); assertThat( "Satisfied: A, B, C", conjunct.satisfied( new PropertySet( "A", "B", "C")), is( false)); assertThat( "Satisfied: A, B, !C", conjunct.satisfied( new PropertySet( "A", "B")), is( false)); assertThat( "Satisfied: A, !B, C", conjunct.satisfied( new PropertySet( "A", "C")), is( false)); assertThat( "Satisfied: A, !B, !C", conjunct.satisfied( new PropertySet( "A")), is( false)); assertThat( "Satisfied: !A, B, C", conjunct.satisfied( new PropertySet( "B", "C")), is( false)); assertThat( "Satisfied: !A, !B, C", conjunct.satisfied( new PropertySet( "C")), is( false)); assertThat( "Satisfied: !A, B, !C", conjunct.satisfied( new PropertySet( "B")), is( false)); assertThat( "Satisfied: !A, !B, !C", conjunct.satisfied( new PropertySet()), is( true)); condition = new Not( condition); conjunct = Cnf.convert( condition); disjuncts = IteratorUtils.toArray( conjunct.getDisjuncts(), IDisjunct.class); assertThat( "Disjuncts", disjuncts.length, is( 1)); assertThat( "Satisfied: A, B, C", conjunct.satisfied( new PropertySet( "A", "B", "C")), is( true)); assertThat( "Satisfied: A, B, !C", conjunct.satisfied( new PropertySet( "A", "B")), is( true)); assertThat( "Satisfied: A, !B, C", conjunct.satisfied( new PropertySet( "A", "C")), is( true)); assertThat( "Satisfied: A, !B, !C", conjunct.satisfied( new PropertySet( "A")), is( true)); assertThat( "Satisfied: !A, B, C", conjunct.satisfied( new PropertySet( "B", "C")), is( true)); assertThat( "Satisfied: !A, !B, C", conjunct.satisfied( new PropertySet( "C")), is( true)); assertThat( "Satisfied: !A, B, !C", conjunct.satisfied( new PropertySet( "B")), is( true)); assertThat( "Satisfied: !A, !B, !C", conjunct.satisfied( new PropertySet()), is( false)); }
@Test public void convertTautology() { ICondition condition = new AnyOf() .add( new AllOf() .add( new ContainsAll( "A")) .add( new AnyOf() .add( new ContainsAny( "B")) .add( new Not().add( new ContainsAny( "C"))))) .add( new Not() .add( new AnyOf() .add( new ContainsAll( "A")) .add( new AllOf() .add( new Not().add( new ContainsAll( "B"))) .add( new ContainsAny( "C"))))); IConjunct conjunct = Cnf.convert( condition); assertThat( "Satisfied: A, B, C", conjunct.satisfied( new PropertySet( "A", "B", "C")), is( true)); assertThat( "Satisfied: A, B, !C", conjunct.satisfied( new PropertySet( "A", "B")), is( true)); assertThat( "Satisfied: A, !B, C", conjunct.satisfied( new PropertySet( "A", "C")), is( false)); assertThat( "Satisfied: A, !B, !C", conjunct.satisfied( new PropertySet( "A")), is( true)); assertThat( "Satisfied: !A, B, C", conjunct.satisfied( new PropertySet( "B", "C")), is( true)); assertThat( "Satisfied: !A, !B, C", conjunct.satisfied( new PropertySet( "C")), is( false)); assertThat( "Satisfied: !A, B, !C", conjunct.satisfied( new PropertySet( "B")), is( true)); assertThat( "Satisfied: !A, !B, !C", conjunct.satisfied( new PropertySet()), is( true)); condition = new Not( condition); conjunct = Cnf.convert( condition); assertThat( "Satisfied: A, B, C", conjunct.satisfied( new PropertySet( "A", "B", "C")), is( false)); assertThat( "Satisfied: A, B, !C", conjunct.satisfied( new PropertySet( "A", "B")), is( false)); assertThat( "Satisfied: A, !B, C", conjunct.satisfied( new PropertySet( "A", "C")), is( true)); assertThat( "Satisfied: A, !B, !C", conjunct.satisfied( new PropertySet( "A")), is( false)); assertThat( "Satisfied: !A, B, C", conjunct.satisfied( new PropertySet( "B", "C")), is( false)); assertThat( "Satisfied: !A, !B, C", conjunct.satisfied( new PropertySet( "C")), is( true)); assertThat( "Satisfied: !A, B, !C", conjunct.satisfied( new PropertySet( "B")), is( false)); assertThat( "Satisfied: !A, !B, !C", conjunct.satisfied( new PropertySet()), is( false)); }