Example #1
0
 private static bool SlicesAreEqual(Solution.Slice a, Solution.Slice b)
 {
     return(a.MinIndex == b.MinIndex &&
            a.MaxIndex == b.MaxIndex &&
            a.Sum == b.Sum &&
            a.SliceLength == b.SliceLength &&
            a.MaxValueInSlice == b.MaxValueInSlice);
 }
Example #2
0
        public void GetNextSlice_ExampleFirstSlice()
        {
            var A = new[] { 3, 2, -6, 3, 1 };
            var nextSliceStart = 0;
            var expected       = new Solution.Slice()
            {
                MinIndex        = 0,
                MaxIndex        = 1,
                Sum             = 5,
                SliceLength     = 2,
                MaxValueInSlice = 3
            };

            var actual = Solution.GetNextSlice(A, nextSliceStart);

            Assert.IsTrue(SlicesAreEqual(expected, actual));
        }
Example #3
0
        public void GetNextSlice_DiminishedThenExceeded_JustOneSlice()
        {
            var A = new[] { 3, 2, -4, 3, 3 };
            var nextSliceStart = 0;

            var expected = new Solution.Slice()
            {
                MinIndex        = 0,
                MaxIndex        = 4,
                Sum             = 7,
                SliceLength     = 5,
                MaxValueInSlice = 3
            };

            var actual = Solution.GetNextSlice(A, nextSliceStart);

            Assert.IsTrue(SlicesAreEqual(expected, actual));
        }
Example #4
0
        public void GetNextSlice_DiminishButNotToZeroLastSlice()
        {
            var A = new[] { 3, 2, -4, 1, 1 };
            var nextSliceStart = 3;

            var expected = new Solution.Slice()
            {
                MinIndex        = 3,
                MaxIndex        = 4,
                Sum             = 2,
                SliceLength     = 2,
                MaxValueInSlice = 1
            };

            var actual = Solution.GetNextSlice(A, nextSliceStart);

            Assert.IsTrue(SlicesAreEqual(expected, actual));
        }