コード例 #1
0
 public void GetSubsetWithGreatestValue_ReturnsLastThreeElements()
 {
     TestHelper.AssertSequence(
         Set.GetSubsetWithGreatestValue(new[] { 100, 200, 1, 50, 70, 188 }, 3,
                                        IntegerAggregator, Comparer <int> .Default),
         100, 188, 200);
 }
コード例 #2
0
 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 } });
 }
コード例 #5
0
 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);
        }
コード例 #24
0
 public void ContainsSubsetWithExactValue_ThrowsException_ForNullSequence()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           Set.ContainsSubsetWithExactValue(null, 1));
 }
コード例 #25
0
        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);
        }
コード例 #27
0
 public void ContainsSubsetWithExactValue_ThrowsException_ForNegativeNumberInSequence()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                 Set.ContainsSubsetWithExactValue(new[] { -1 }, 1));
 }
コード例 #28
0
 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));
 }