Ejemplo n.º 1
0
        public void Test1()
        {
            int[] arr    = { 6, -3, -10, 0, 2 };
            var   result = MaximumProductSubarray.RunImplementationA(arr);

            Assert.That(result, Is.EqualTo(180));
        }
        public void ShouldReturn0WhenNullOrEmpty()
        {
            var sol = new MaximumProductSubarray();

            Assert.AreEqual(0, sol.MaxProduct(null));
            Assert.AreEqual(0, sol.MaxProduct(new int[0]));
        }
        public void ShouldReturnSingleValue()
        {
            var sol = new MaximumProductSubarray();

            Assert.AreEqual(99, sol.MaxProduct(new[] { 99 }));
            Assert.AreEqual(-99, sol.MaxProduct(new int[] { -99 }));
        }
Ejemplo n.º 4
0
        public void Test8()
        {
            int[] arr    = {  };
            var   result = MaximumProductSubarray.RunImplementationA(arr);

            Assert.That(result, Is.EqualTo(null));
        }
Ejemplo n.º 5
0
        public void Test6()
        {
            int[] arr    = { 1, -3, -5, -2, 0, 4, 9, 0, 3, -8, 7, -6 };
            var   result = MaximumProductSubarray.RunImplementationA(arr);

            Assert.That(result, Is.EqualTo(1008));
        }
Ejemplo n.º 6
0
        public void Test4()
        {
            int[] arr    = { -1, 0, 0, 1, -1, 1 };
            var   result = MaximumProductSubarray.RunImplementationA(arr);

            Assert.That(result, Is.EqualTo(1));
        }
Ejemplo n.º 7
0
        public void Test3()
        {
            int[] arr    = { -2, -3, 0, -2, -40 };
            var   result = MaximumProductSubarray.RunImplementationA(arr);

            Assert.That(result, Is.EqualTo(80));
        }
Ejemplo n.º 8
0
        public void GetMaximumProduct_ShouldReturn_MaximumProductInSubArray(int[] nums, int expectedProduct)
        {
            // Arrange
            var maximumProductCalculator = new MaximumProductSubarray();

            // Act
            var product = maximumProductCalculator.GetMaximumProduct(nums);

            // Assert
            product.Should().Be(expectedProduct);
        }
Ejemplo n.º 9
0
        public void TestMaximumProductSubarray()
        {
            var r = MaximumProductSubarray.Calc(new[] { 2, 3, -2, 4 });

            Assert.AreEqual(r, 6);

            r = MaximumProductSubarray.Calc(new[] { -2, 0, -1 });
            Assert.AreEqual(r, 0);


            r = MaximumProductSubarray.Calc(new[] { 6, 5, -1, -100, 0, 2, 49, 22 });
            Assert.AreEqual(r, 3000);
        }
        public void MaxProductTests()
        {
            MaximumProductSubarray obj = new MaximumProductSubarray();
            //        Input: [2, 3, -2, 4]
            //Output: 6
            //Explanation: [2, 3] has the largest product 6.

            var arr = new int[] { 2, 3, -2, 4 };
            var x   = obj.MaxProduct(arr);


            //        Input: [-2, 0, -1]
            //Output: 0
            //Explanation: The result cannot be 2, because[-2, -1] is not a subarray.
            arr = new int[] { -2, 0, -1 };
            x   = obj.MaxProduct(arr);

            arr = new int[] { -3, 0, 1, -2 };
            x   = obj.MaxProduct(arr);//1


            arr = new int[] { 3, -1, 4 };
            x   = obj.MaxProduct(arr);//4
        }
        public void Example4()
        {
            var sol = new MaximumProductSubarray();

            Assert.AreEqual(6, sol.MaxProduct(new[] { -1, -2, -3 }));
        }
        public void Example3()
        {
            var sol = new MaximumProductSubarray();

            Assert.AreEqual(0, sol.MaxProduct(new[] { 0, 0, -2, 0 }));
        }
        public void Example1()
        {
            var sol = new MaximumProductSubarray();

            Assert.AreEqual(6, sol.MaxProduct(new[] { 2, 3, -2, 4 }));
        }