public void StringPredicateShouldBeCalledAndReturnFalse() { _returnValue = false; var comparer = new PredicateComparer<string, string>(CallThisMethod); Assert.That(comparer.Compare("some input"), Is.False); Assert.That(_called, Is.True); Assert.That(_value, Is.EqualTo("some input")); }
public void StringPredicateShouldBeCalledAndReturnTrue() { _returnValue = true; var comparer = new PredicateComparer<string, string>(CallThisMethod); Assert.That(comparer.Compare("test value"), Is.True); Assert.That(_called, Is.True); Assert.That(_value, Is.EqualTo("test value")); }
public int CompareTo(ThreatenedLinkFlaw other) { if (other == null) { return(1); } if (threatener.ID == other.threatener.ID) { if (causallink.Predicate.Equals(other.causallink.Predicate)) { if (causallink.Head.ID != other.causallink.Head.ID) { if (causallink.Head.ID < other.causallink.Head.ID) { return(-1); } else { return(1); } } else if (causallink.Tail.ID != other.causallink.Tail.ID) { if (causallink.Tail.ID < other.causallink.Tail.ID) { return(-1); } else { return(1); } } // causal link is the same, and the threat is the same throw new System.Exception(); } else { return(PredicateComparer.CompareTo(causallink.Predicate, other.causallink.Predicate)); } } else if (threatener.ID < other.threatener.ID) { return(-1); } else { return(1); } }
public void ToStringShouldDescribeTheCondition() { var comparer = new PredicateComparer<string, string>(x => false); Assert.AreEqual("satisfies predicate", comparer.ToString()); }
public void ToStringShouldDescribeTheCondition() { var comparer = new PredicateComparer <string, string>(x => false); Assert.AreEqual("satisfies predicate", comparer.ToString()); }
public int CompareTo(OpenCondition other) { if (other == null) { return(1); } // check static if (isStatic && !other.isStatic) { return(-1); } else if (other.isStatic && !isStatic) { return(1); } if (step.Depth > other.step.Depth) { return(1); } else if (step.Depth < other.step.Depth) { return(-1); } // MW-Loc-Conf = {threats} LIFO / {unsafe} MW_add / {local} MW_add // if one is unsafe and the other is not. if (risks > 0 && other.risks == 0) { return(-1); } else if (other.risks > 0 && risks == 0) { return(1); } if (other.risks > 0 && risks == other.risks) { // if they are both unsafe, choose one with most work if (addReuseHeuristic > other.addReuseHeuristic) { return(-1); } else { return(1); } } // Local step's open conditions first. Lower planstep ID == added to plan earlier if (step.ID < other.step.ID) { return(-1); } else if (step.ID > other.step.ID) { return(1); } // If they are of the same step, only then do we select between mos work... if (addReuseHeuristic > other.addReuseHeuristic) { return(-1); } else if (addReuseHeuristic < other.addReuseHeuristic) { return(1); } // tiebreaker if they are the same work if (precondition.Equals(other.precondition)) { throw new System.Exception(); } else { return(PredicateComparer.CompareTo(precondition, other.precondition)); } }
public int CompareTo(OpenCondition other) { if (other == null) { return(1); } // check static if (isStatic && !other.isStatic) { return(-1); } else if (other.isStatic && !isStatic) { return(1); } // {dummyGoal} LIFO // take care of open conditions arising from substeps that are found in initial step. //if (isDummyGoal && !other.isDummyGoal) //{ // return -1; //} //else if (other.isDummyGoal && !isDummyGoal) //{ // return 1; //} //else if (other.isDummyGoal && isDummyGoal) //{ // if (addReuseHeuristic > other.addReuseHeuristic) // { // return -1; // } // else // { // return 1; // } //} ////take care of open conditions arising from substeps that are found in initial step. //if (hasDummyInit && !other.hasDummyInit) //{ // return -1; //} //else if (other.hasDummyInit && !hasDummyInit) //{ // return 1; //} //else if (other.hasDummyInit && hasDummyInit) //{ // if (addReuseHeuristic > other.addReuseHeuristic) // { // return -1; // } // else // { // return 1; // } //} if (step.Depth > other.step.Depth) { return(1); } else if (step.Depth < other.step.Depth) { return(-1); } if (precondition.Name.Equals("obss") || precondition.Name.Equals("obs-starts")) { if (other.precondition.Name.Equals("obss") || other.precondition.Name.Equals("obs-starts")) { if (risks > 0 && other.risks == 0) { return(-1); } else if (other.risks > 0 && risks == 0) { return(1); } if (other.risks > 0 && risks == other.risks) { // if they are both unsafe, choose one with most work if (addReuseHeuristic > other.addReuseHeuristic) { return(-1); } else { return(1); } } // Local step's open conditions first. Lower planstep ID == added to plan earlier if (step.ID < other.step.ID) { return(-1); } else if (step.ID > other.step.ID) { return(1); } // If they are of the same step, only then do we select between mos work... if (addReuseHeuristic > other.addReuseHeuristic) { return(-1); } else if (addReuseHeuristic < other.addReuseHeuristic) { return(1); } } else { return(-1); } } else if (other.precondition.Name.Equals("obs-starts") || other.precondition.Name.Equals("obss")) { return(1); } // MW-Loc-Conf = {threats} LIFO / {unsafe} MW_add / {local} MW_add // if one is unsafe and the other is not. if (risks > 0 && other.risks == 0) { return(-1); } else if (other.risks > 0 && risks == 0) { return(1); } if (other.risks > 0 && risks == other.risks) { // if they are both unsafe, choose one with most work if (addReuseHeuristic > other.addReuseHeuristic) { return(-1); } else { return(1); } } // Local step's open conditions first. Lower planstep ID == added to plan earlier if (step.ID < other.step.ID) { return(-1); } else if (step.ID > other.step.ID) { return(1); } // If they are of the same step, only then do we select between mos work... if (addReuseHeuristic > other.addReuseHeuristic) { return(-1); } else if (addReuseHeuristic < other.addReuseHeuristic) { return(1); } // tiebreaker if they are the same work if (precondition.Equals(other.precondition)) { throw new System.Exception(); } else { return(PredicateComparer.CompareTo(precondition, other.precondition)); } }
public void ComparerTest() { var comparer = new PredicateComparer(1, IterationType.Value); Assert.Throws <ArgumentNullException>(() => comparer.WriteData(null)); Assert.Throws <ArgumentNullException>(() => comparer.ReadData(null)); using var output = new ObjectDataOutput(1024, _serializationService, Endianness.BigEndian); comparer.WriteData(output); var c = new PredicateComparer(); using var input = new ObjectDataInput(output.Buffer, _serializationService, Endianness.BigEndian); c.ReadData(input); Assert.That(c.Type, Is.EqualTo(comparer.Type)); Assert.That(c.IterationType, Is.EqualTo(comparer.IterationType)); // entry Assert.That(new PredicateComparer(0, IterationType.Key).Compare(("key1", "value1"), ("key2", "value2")), Is.EqualTo("key1".CompareTo("key2"))); Assert.That(new PredicateComparer(1, IterationType.Key).Compare(("key1", "value1"), ("key2", "value2")), Is.EqualTo("key2".CompareTo("key1"))); Assert.That(new PredicateComparer(2, IterationType.Key).Compare(("key1", "value1"), ("key2", "value2")), Is.EqualTo(0)); Assert.That(new PredicateComparer(2, IterationType.Key).Compare(("key1", "value1"), ("key2x", "value2")), Is.EqualTo("key1".Length.CompareTo("key2x".Length))); Assert.That(new PredicateComparer(3, IterationType.Key).Compare(("key1", "value1"), ("key2", "value2")), Is.EqualTo(0)); Assert.That(new PredicateComparer(3, IterationType.Key).Compare(("key1", "value1"), ("key2x", "value2")), Is.EqualTo(0)); // uh? Assert.That(new PredicateComparer(0, (IterationType)666).Compare(("key1", "value1"), ("key2", "value2")), Is.EqualTo("key1".CompareTo("key2"))); Assert.That(new PredicateComparer(1, (IterationType)666).Compare(("key1", "value1"), ("key2", "value2")), Is.EqualTo("key2".CompareTo("key1"))); Assert.That(new PredicateComparer(2, (IterationType)666).Compare(("key1", "value1"), ("key2", "value2")), Is.EqualTo(0)); Assert.That(new PredicateComparer(2, (IterationType)666).Compare(("key1", "value1"), ("key2x", "value2")), Is.EqualTo("key1".Length.CompareTo("key2x".Length))); Assert.That(new PredicateComparer(3, (IterationType)666).Compare(("key1", "value1"), ("key2", "value2")), Is.EqualTo(0)); Assert.That(new PredicateComparer(3, (IterationType)666).Compare(("key1", "value1"), ("key2x", "value2")), Is.EqualTo(0)); // value Assert.That(new PredicateComparer(0, IterationType.Value).Compare(("key1", "value1"), ("key2", "value2")), Is.EqualTo("value1".CompareTo("value2"))); Assert.That(new PredicateComparer(1, IterationType.Value).Compare(("key1", "value1"), ("key2", "value2")), Is.EqualTo("value2".CompareTo("value1"))); Assert.That(new PredicateComparer(2, IterationType.Value).Compare(("key1", "value1"), ("key2", "value2")), Is.EqualTo(0)); Assert.That(new PredicateComparer(2, IterationType.Value).Compare(("key1", "value1"), ("key2", "value2x")), Is.EqualTo("value1".Length.CompareTo("value2x".Length))); Assert.That(new PredicateComparer(3, IterationType.Value).Compare(("key1", "value1"), ("key2", "value2")), Is.EqualTo(0)); Assert.That(new PredicateComparer(3, IterationType.Value).Compare(("key1", "value1"), ("key2", "value2x")), Is.EqualTo(0)); // entry Assert.That(new PredicateComparer(0, IterationType.Entry).Compare(("key1", "value1"), ("key2", "value2")), Is.EqualTo("key1:::value1".CompareTo("key2:::value2"))); Assert.That(new PredicateComparer(1, IterationType.Entry).Compare(("key1", "value1"), ("key2", "value2")), Is.EqualTo("key2:::value2".CompareTo("key1:::value1"))); Assert.That(new PredicateComparer(2, IterationType.Entry).Compare(("key1", "value1"), ("key2", "value2")), Is.EqualTo(0)); Assert.That(new PredicateComparer(2, IterationType.Entry).Compare(("key1", "value1"), ("key2", "value2x")), Is.EqualTo("key1:::value1".Length.CompareTo("key2:::value2x".Length))); Assert.That(new PredicateComparer(3, IterationType.Entry).Compare(("key1", "value1"), ("key2", "value2")), Is.EqualTo(0)); Assert.That(new PredicateComparer(3, IterationType.Entry).Compare(("key1", "value1"), ("key2", "value2x")), Is.EqualTo(0)); Assert.That(new PredicateComparer(0, IterationType.Entry).Compare(("abc", "defghi"), ("abcdef", "ghi")), Is.EqualTo("abc:::defghi".CompareTo("abcdef:::ghi"))); // NOTE // the behavior for non-supported types and iteration types is ... weird }
public int CompareTo(OpenCondition other) { if (other == null) { return(1); } // check static if (isStatic && !other.isStatic) { return(-1); } else if (other.isStatic && !isStatic) { return(1); } // check init if (isInit && !other.isInit) { return(-1); } else if (other.isInit && !isInit) { return(1); } // check risks if (risks > 0 || other.risks > 0) { if (risks > other.risks) { return(-1); } else if (risks < other.risks) { return(1); } } // check cndts if (cndts > other.cndts) { return(-1); } else if (cndts < other.cndts) { return(1); } // resort to tiebreak criteria if (step.ID == other.step.ID) { if (precondition.Equals(other.precondition)) { throw new System.Exception(); } else { return(PredicateComparer.CompareTo(precondition, other.precondition)); } } else if (step.ID < other.step.ID) { return(-1); } else { return(1); } }