/* Haven't managed to run this within ~40h [InlineData(M01, ?, ?)] */ public void Fast(string file, int expectedCount, int secondsRuntime) { string actualFilePath = $"../../data/{file}"; if (!File.Exists(actualFilePath)) { throw new InvalidOperationException(file); } int[] intArray = File.ReadAllLines(actualFilePath).Select(s => int.Parse(s)).ToArray(); var tuple = Helper.Time(() => ThreeSumFast.Count(intArray), "fast"); Assert.Equal(expectedCount, tuple.Item1); Assert.True(tuple.Item2 < secondsRuntime * 1000); }
public void FastVsSlow(string file, int expectedCount, int timeoutInSeconds) { string actualFilePath = $"../../data/{file}"; if (!File.Exists(actualFilePath)) { throw new InvalidOperationException(file); } int[] intArray = File.ReadAllLines(actualFilePath).Select(s => int.Parse(s)).ToArray(); var fast = Helper.Time(() => ThreeSumFast.Count(intArray), "3SumFast"); Assert.Equal(expectedCount, fast.Item1); var slow = Helper.Time(() => ThreeSum.Count(intArray), "3SumSlow"); Assert.Equal(expectedCount, slow.Item1); Assert.True(fast.Item2 < slow.Item2); Assert.True(fast.Item2 + slow.Item2 < timeoutInSeconds * 1000); }
public void ThreeSumFastThrowsExceptionIfInputArrayContainsDuplicates() { Assert.Throws <ArgumentException>(() => ThreeSumFast.Count(Enumerable.Range(20, 50).Concat(Enumerable.Range(30, 80)).ToArray())); }