public void ThreeSumTests() { int[] nums = new int[] { -4, -1, -1, 0, 1, 2 }; // solution set is: //[ // [-1, 0, 1], // [-1, -1, 2] //] _3Sum obj = new _3Sum(); var x = obj.ThreeSum(nums); // solution set is: //[ // [-1, 0, 1], // [-1, -1, 2] //] nums = new int[] { -4, -1, -1, -1, 0, 1, 2 }; x = obj.ThreeSum(nums); nums = new int[] { -4, 0, 1, 2, 2, 3 };// -4,2,2 -4,1,3 x = obj.ThreeSum(nums); }
public void LeetInput_1() { // Arrange int[] nums = new int[] { 3, 0, -2, -1, 1, 2 }; _3Sum algo = new _3Sum(true); // Act IList <IList <int> > triplets = algo.ThreeSum(nums); //Assert Assert.AreEqual(3, triplets.Count); // -2,-1,3 Assert.AreEqual(-2, triplets[0][0]); Assert.AreEqual(-1, triplets[0][1]); Assert.AreEqual(3, triplets[0][2]); // -2, 0, 2 Assert.AreEqual(-2, triplets[1][0]); Assert.AreEqual(0, triplets[1][1]); Assert.AreEqual(2, triplets[1][2]); // -1, 0, 1 Assert.AreEqual(-1, triplets[2][0]); Assert.AreEqual(0, triplets[2][1]); Assert.AreEqual(1, triplets[2][2]); }
public void ThreeSum_Test() { // Arrange int[] nums = new int[] { -1, 0, 1, 2, -1, -4 }; _3Sum algo = new _3Sum(true); // Act IList <IList <int> > triplets = algo.ThreeSum(nums); // as List<List<int>>; // Assert Assert.AreEqual(2, triplets.Count); }
public void CalculateSum() { _3Sum sum = new _3Sum(); IList <IList <int> > listToTest = sum.ThreeSum(new int[] { -1, 0, 1, 2, -1, -4 }); IList <IList <int> > compareList = new List <IList <int> >(); compareList.Add(new List <int>() { -1, 0, 1 }); compareList.Add(new List <int>() { -1, -1, 2 }); Assert.AreEqual(compareList, listToTest); }
public void ThreeSum_0000_Test() { // Arrange int[] nums = new int[] { 0, 0, 0, 0 }; _3Sum algo = new _3Sum(true); // Act IList <IList <int> > triplets = algo.ThreeSum(nums); // Assert Assert.AreEqual(1, triplets.Count); // 0,0,0 Assert.AreEqual(0, triplets[0][0]); Assert.AreEqual(0, triplets[0][1]); Assert.AreEqual(0, triplets[0][2]); }
public void LeetInput_3() { // Arrange int[] nums = new int[] { 1, -1, -1, 0 }; _3Sum algo = new _3Sum(true); // Act IList <IList <int> > triplets = algo.ThreeSum(nums); // Assert Assert.AreEqual(1, triplets.Count); // -1, 0, 1 Assert.AreEqual(-1, triplets[0][0]); Assert.AreEqual(0, triplets[0][1]); Assert.AreEqual(1, triplets[0][2]); }
[TestMethod(), Timeout(10000)] // timeout is in milliseconds public void BigArraySize_Test() { // Arrange // using ThreeSumTheSlowWay: 30:8ms, 40:5ms, 100:11ms, 200:180ms, 400:4s, 800:timeout int size = 800; // 100:4ms, 200:4ms, 400:4ms, 800:6ms, 1600:12ms, 3200:31ms, 6400:106ms, 128000:timeout int[] nums = new int[size]; Random rand = new Random(29322); for (int i = 0; i < size; i++) { nums[i] = rand.Next(-100, 100); } _3Sum algo = new _3Sum(true); // Act IList <IList <int> > triplets = algo.ThreeSum(nums); // Assert Assert.IsTrue(true); // if the test finishes within the timeout, it passes. }