public void GetSubsetWithGreatestValue_ReturnsLastThreeElements()
 {
     TestHelper.AssertSequence(
         Set.GetSubsetWithGreatestValue(new[] { 100, 200, 1, 50, 70, 188 }, 3,
                                        IntegerAggregator, Comparer <int> .Default),
         100, 188, 200);
 }
 public void GetSubsetWithGreatestValue_ReturnsAllElements_ForCountOfThree()
 {
     TestHelper.AssertSequence(
         Set.GetSubsetWithGreatestValue(new[] { 3, 2, 1 }, 3, IntegerAggregator,
                                        Comparer <int> .Default),
         1, 2, 3);
 }
예제 #3
0
 public void EnumerateSubsetCombinations_ReturnsFourCombinations_ForTwoElementAndTwoSubsets()
 {
     TestHelper.AssertSequence(
         Set.EnumerateSubsetCombinations(new[] { 11, 19 }, 2),
         new[]
     {
         new[] { 11, 19 },
         new int[] { }
     },
         new[]
     {
         new[] { 11 },
         new[] { 19 }
     },
         new[]
     {
         new[] { 19 },
         new[] { 11 }
     },
         new[]
     {
         new int[] { },
         new[] { 11, 19 }
     });
 }
예제 #4
0
 public void EnumerateSubsetCombinations_ReturnsTwoCombinations_ForOneElementAndTwoSubsets()
 {
     TestHelper.AssertSequence(
         Set.EnumerateSubsetCombinations(new[] { 10 }, 2),
         new[] { new[] { 10 }, new int[] { } },
         new[] { new int[] { }, new[] { 10 } });
 }
 public void GetSubsetWithGreatestValue_ReturnsBiggestElement_ForCountOfOne()
 {
     TestHelper.AssertSequence(
         Set.GetSubsetWithGreatestValue(new[] { 1, 2, 3 }, 1, IntegerAggregator,
                                        Comparer <int> .Default),
         3);
 }
예제 #6
0
 public void EnumerateSubsetCombinations_DoesNotCareIfDuplicates()
 {
     TestHelper.AssertSequence(
         Set.EnumerateSubsetCombinations(new[] { 1, 1 }, 2),
         new[]
     {
         new[] { 1, 1 },
         new int[] { }
     },
         new[]
     {
         new[] { 1 },
         new[] { 1 }
     },
         new[]
     {
         new[] { 1 },
         new[] { 1 }
     },
         new[]
     {
         new int[] { },
         new[] { 1, 1 }
     });
 }
예제 #7
0
        public void SplitIntoSubsetsOfEqualValue_ReturnsNothing_IfThreePartitionsNotPossible()
        {
            var array = new[] { 2, 1, 3, 2, 5 };

            TestHelper.AssertSequence(
                Set.SplitIntoSubsetsOfEqualValue(array, IntegerAggregator, Comparer <int> .Default, 3)
                );
        }
예제 #8
0
        public void SplitIntoSubsetsOfEqualValue_ReturnsNothing_ForEmptySequence()
        {
            var array = new int[] { };

            TestHelper.AssertSequence(
                Set.SplitIntoSubsetsOfEqualValue(array, IntegerAggregator, Comparer <int> .Default, 1)
                );
        }
예제 #9
0
        public void SplitIntoSubsetsOfEqualValue_ReturnsEverything_IfOnlyOnePartition()
        {
            var array = new[] { 1, 2, 3, 4, 5 };

            TestHelper.AssertSequence(
                Set.SplitIntoSubsetsOfEqualValue(array, IntegerAggregator, Comparer <int> .Default, 1),
                new[] { 1, 2, 3, 4, 5 });
        }
예제 #10
0
        public void GetSubsetWithNearValue_ReturnsOneAndTwo_ForASumOfThree()
        {
            var array = new[] { 1, 2, 3, 4, 5 };

            TestHelper.AssertSequence(
                Set.GetSubsetWithNearValue(array, 3),
                2, 1);
        }
예제 #11
0
        public void GetSubsetWithNearValue_ReturnsTen_ForASumOfEleven_ExcludingFive()
        {
            var array = new[] { 5, 10 };

            TestHelper.AssertSequence(
                Set.GetSubsetWithNearValue(array, 11),
                10);
        }
예제 #12
0
        public void GetSubsetWithNearValue_ReturnsTenOne_ForASumOfEleven_ExcludingOneTwoThree()
        {
            var array = new[] { 1, 2, 3, 10 };

            TestHelper.AssertSequence(
                Set.GetSubsetWithNearValue(array, 11),
                10, 1);
        }
예제 #13
0
        public void GetSubsetWithNearValue_ReturnsOne_WhenSkippingZeroes()
        {
            var array = new[] { 0, 0, 1 };

            TestHelper.AssertSequence(
                Set.GetSubsetWithNearValue(array, 1),
                1);
        }
예제 #14
0
        public void GetSubsetWithNearValue_ReturnsOneTwoThree_ForASumOfTen()
        {
            var array = new[] { 1, 2, 3 };

            TestHelper.AssertSequence(
                Set.GetSubsetWithNearValue(array, 10),
                3, 2, 1);
        }
예제 #15
0
        public void GetSubsetWithNearValue_ReturnsOne_ForPerfectMatchingSumOfOne()
        {
            var array = new[] { 1 };

            TestHelper.AssertSequence(
                Set.GetSubsetWithNearValue(array, 1),
                1);
        }
예제 #16
0
        public void GetSubsetWithNearValue_ReturnsTwo_ForPerfectFullyCompletedSumOfTwo()
        {
            var array = new[] { 1, 2 };

            TestHelper.AssertSequence(
                Set.GetSubsetWithNearValue(array, 2),
                2);
        }
예제 #17
0
        public void GetOptimalFullCoverage_ReturnsSingleSet()
        {
            var set = new HashSet <int> {
                1, 2, 3, 4
            };
            var coverage = Set.GetOptimalFullCoverage(new[] { set }, EqualityComparer <int> .Default);

            TestHelper.AssertSequence(
                coverage, set);
        }
예제 #18
0
        public void SplitIntoSubsetsOfEqualValue_ReturnsEmptyArrayAndAll_ForNegativeZeroing()
        {
            var array = new[] { -1, 1 };

            TestHelper.AssertSequence(
                Set.SplitIntoSubsetsOfEqualValue(array, IntegerAggregator, Comparer <int> .Default, 2),
                new[] { -1, 1 },
                new int[] { }
                );
        }
예제 #19
0
        public void SplitIntoSubsetsOfEqualValue_ReturnsTwoPartitions_IfPossible()
        {
            var array = new[] { 2, 1, 3, 2 };

            TestHelper.AssertSequence(
                Set.SplitIntoSubsetsOfEqualValue(array, IntegerAggregator, Comparer <int> .Default, 2),
                new[] { 2, 2 },
                new[] { 1, 3 }
                );
        }
예제 #20
0
        public void GetOptimalFullCoverage_ReturnsGreatestOneFirst()
        {
            var set1 = new HashSet <int> {
                1, 4
            };
            var set2 = new HashSet <int> {
                2, 3, 1
            };

            var coverage = Set.GetOptimalFullCoverage(new[] { set1, set2 }, EqualityComparer <int> .Default);

            TestHelper.AssertSequence(coverage, set2, set1);
        }
예제 #21
0
        public void GetOptimalFullCoverage_ReturnsBestChoiceOnly()
        {
            var set1 = new HashSet <int> {
                1, 2
            };
            var set2 = new HashSet <int> {
                2
            };

            var coverage = Set.GetOptimalFullCoverage(new[] { set1, set2 }, EqualityComparer <int> .Default);

            TestHelper.AssertSequence(
                coverage, set1);
        }
예제 #22
0
        public void GetOptimalFullCoverage_ReturnsTwoSets()
        {
            var set1 = new HashSet <int> {
                1, 2
            };
            var set2 = new HashSet <int> {
                2, 3
            };
            var set3 = new HashSet <int> {
                1, 3
            };

            var coverage = Set.GetOptimalFullCoverage(new[] { set1, set2, set3 }, EqualityComparer <int> .Default);

            TestHelper.AssertSequence(coverage, set1, set2);
        }
예제 #23
0
        public void GetOptimalFullCoverage_ReturnsIndividualSets_IfNoIntersectionFound()
        {
            var set1 = new HashSet <int> {
                1
            };
            var set2 = new HashSet <int> {
                2
            };
            var set3 = new HashSet <int> {
                3
            };

            var coverage = Set.GetOptimalFullCoverage(new[] { set1, set2, set3 }, EqualityComparer <int> .Default);

            TestHelper.AssertSequence(
                coverage, set1, set2, set3);
        }
 public void ContainsSubsetWithExactValue_ThrowsException_ForNullSequence()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           Set.ContainsSubsetWithExactValue(null, 1));
 }
        public void ContainsSubsetWithExactValue_ReturnsFalse_WhenSumCannotBeCompleted()
        {
            var result = Set.ContainsSubsetWithExactValue(new[] { 2 }, 1);

            Assert.IsFalse(result);
        }
예제 #26
0
        public void GetOptimalFullCoverage_ReturnsNothing_ForEmptySets()
        {
            var coverage = Set.GetOptimalFullCoverage(new ISet <int>[] { }, EqualityComparer <int> .Default);

            TestHelper.AssertSequence(coverage);
        }
 public void ContainsSubsetWithExactValue_ThrowsException_ForNegativeNumberInSequence()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                 Set.ContainsSubsetWithExactValue(new[] { -1 }, 1));
 }
 public void ContainsSubsetWithExactValue_ThrowsException_ForZeroTargetSum()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                 Set.ContainsSubsetWithExactValue(new int[] { }, 0));
 }
예제 #29
0
 public void GetOptimalFullCoverage_ThrowsException_ForNullSets()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           Set.GetOptimalFullCoverage(null, EqualityComparer <int> .Default));
 }
예제 #30
0
 public void GetOptimalFullCoverage_ThrowsException_ForEqualityComparer()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           Set.GetOptimalFullCoverage(new ISet <int>[] { }, null));
 }