public void Random() { Random random = new Random(); for (int i = 0; i < 5000; i++) { BloomFilter <int> bf = new BloomFilter <int>(); List <int> values = new List <int>(); for (int j = 0; j < 50; j++) { DataStructures.HashSet <int> hashSet = new DataStructures.HashSet <int>(); int rand = random.Next(); if (!hashSet.Contains(rand)) { values.Add(rand); hashSet.Add(rand); bf.Add(rand); } } foreach (int check in values) { Assert.True(bf.Contains(check)); } } }
public void CompareHashSet() { DataStructures.HashSet <int> ht = new DataStructures.HashSet <int>(); Random rand = new Random(); for (int i = 0; i < 50000; i++) { ht.Add(rand.Next(50000)); } for (int i = 0; i < 2000000; i++) { ht.Contains(i % 50000); } }
public void Random() { // Test with between 2 and 100 nodes for (int count = 2; count < 100; count++) { // Test 100 times with the same number of nodes for (int j = 0; j < 100; j++) { DataStructures.HashSet <int> hashSet = new DataStructures.HashSet <int>(); List <int> ordered = new List <int>(); Random random = new Random(); for (int i = 0; i < count; i++) { // Only use unique numbers int rand = random.Next(); if (!hashSet.Contains(rand)) { ordered.Add(rand); hashSet.Add(rand); } } BinaryHeap <int, int> bh = new BinaryHeap <int, int>(); foreach (int i in ordered) { bh.Add(i, i); } Assert.Equal(ordered.Count, bh.Count); ordered.Sort(); ordered.Reverse(); foreach (int i in ordered) { Assert.Equal(i, bh.Pop().Item1); } } } }