public HashSetBenchmark() { _collection = HashSetDataProvider.GetDate(); _dotNetHashSet = new HashSet <long>(_collection); _chainedHashSet = new ChainedHashSet <long>(_collection); _openAddressedHashSet = new OpenAddressedHashSet <long>(_collection); }
public void Calculate_SumOnTestData_Returns22() { List <long> values = SumCalculationTestDataBuilder.CreateTestData(Resources.WeekSixTestInput); var uniqueSums = new ChainedHashSet <long>(); var valuesSet = new ChainedHashSet <long>(values); List <int> range = new List <int>(); for (int i = -1000; i <= 1000; i++) { range.Add(i); } for (int i = 0; i < values.Count; i++) { for (int j = 0; j < range.Count; j++) { var x = range[j] - values[i]; if (valuesSet.Contains(x)) { uniqueSums.Add(range[j]); } } } Assert.That(uniqueSums.Count, Is.EqualTo(22)); }
public void Calculate_SumOnTestDataBruteForce_Returns22() { List <long> values = SumCalculationTestDataBuilder.CreateTestData(Resources.WeekSixTestInput); var uniqueSums = new ChainedHashSet <long>(); for (int i = 0; i < values.Count; i++) { for (int j = i; j < values.Count; j++) { var sum = values[j] + values[i]; if (sum <= 1000 && sum >= -1000) { uniqueSums.Add(sum); } } } Assert.That(uniqueSums.Count, Is.EqualTo(22)); }