-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path152.MaximumProductSubarray.Test.cs
More file actions
39 lines (37 loc) · 1.04 KB
/
152.MaximumProductSubarray.Test.cs
File metadata and controls
39 lines (37 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using Newtonsoft.Json;
using NUnit.Framework;
[TestFixture]
public class TestClass : TestClassBase
{
[TestCase(-10, 10, 10, 1000)]
[TestCase(-10, 10, 1, 100)]
[TestCase(-1, 1, 10, 100)]
public void TestMethod(int minNum, int maxNum, int numCount, int repeat)
{
Repeat(repeat, () =>
{
var nums = GenerateIntegerArray(numCount, numCount, minNum, maxNum);
var result = new Solution().MaxProduct(nums);
var expectedResult = MaxProduct(nums);
Assert.AreEqual(expectedResult, result, JsonConvert.SerializeObject(nums));
});
}
private int MaxProduct(int[] nums)
{
var result = int.MinValue;
for (var i = 0; i < nums.Length; ++i)
{
var product = 1;
for (var j = i; j < nums.Length; ++j)
{
product *= nums[j];
if (product > result)
{
result = product;
}
}
}
return result;
}
}