public void FilterOutTest() { // Start with 4-9. Filter out 3-5. Return 4-5 Possible target = new Possible() { 4, 5, 6, 7, 8, 9 }; Possible filter = new Possible() { 3, 4, 5 }; Possible expected = new Possible() { 6, 7, 8, 9 }; bool returnValue = target.FilterOut(filter); Assert.IsTrue(returnValue, "Filter Return value is false"); Assert.AreEqual(4, target.Values.Count, "Filter Count is not 4"); Assert.IsTrue(((HashSet <int>)target.Values).SetEquals(expected), "Filter operation failed expected output"); }
/// <summary> /// This elimination works out if there is an intersection between mutually exclusive sets /// that contains any values that are in the intersection and not in the outersection of one set. /// If this is so, (and both sets must contain that value) then the values can be eliminated from /// the other set also. Only need - in addition to above, used when intersecting points > 1. /// </summary> static public int CreateCompleteIntersectActions(Keys <TKey> group1, Keys <TKey> group2, IPuzzleEngine <TKey> engine) { int added = 0; Keys <TKey> keysIntersection = new Keys <TKey>(group1); keysIntersection.IntersectWith(group2); if (keysIntersection.Count > 1) { Keys <TKey> keysOuter1 = new Keys <TKey>(group1); keysOuter1.ExceptWith(keysIntersection); Keys <TKey> keysOuter2 = new Keys <TKey>(group2); keysOuter2.ExceptWith(keysIntersection); IPossible valuesIntersect = engine.Puzzle.Space.AllValuesAt(keysIntersection); IPossible valuesOuter1 = engine.Puzzle.Space.AllValuesAt(keysOuter1); IPossible valuesOuter2 = engine.Puzzle.Space.AllValuesAt(keysOuter2); Possible filter2 = new Possible(valuesIntersect); filter2.FilterOut(valuesOuter1); if (filter2.Count > 0) { engine.Add(new JobFilter <TKey>("Intersection", keysOuter2, filter2)); added++; } // find each value that is present in the intersection (and not in outer1) // and eliminate it from the set2 // find each value that is present in the intersection (and not in outer) // and eliminate it from the set1 Possible filter1 = new Possible(valuesIntersect); filter1.FilterOut(valuesOuter2); if (filter1.Count > 0) { engine.Add(new JobFilter <TKey>("Intersection", keysOuter1, filter1)); added++; } } return(added); }