public void ClearTest() { var set = UnsafeSortedDictionary.Allocate <int, float>(16, fixedSize: false); // Add some random data Random r = new Random(); for (int i = 0; i < 10; i++) { UnsafeSortedDictionary.Add <int, float>(set, r.Next(), (float)r.NextDouble()); } // Verify data has been added Assert.AreEqual(10, UnsafeSortedDictionary.GetCount(set)); Assert.AreEqual(16, UnsafeSortedDictionary.GetCapacity(set)); // Clear set and verify it's cleared UnsafeSortedDictionary.Clear(set); Assert.AreEqual(0, UnsafeSortedDictionary.GetCount(set)); Assert.AreEqual(16, UnsafeSortedDictionary.GetCapacity(set)); // Validate we can still add data and have it be valid // Add data to cleared set for (int i = 10; i >= 0; i--) { UnsafeSortedDictionary.Add(set, i, 41f); } var count = UnsafeSortedDictionary.GetCount(set); var arr = new KeyValuePair <int, float> [count]; UnsafeSortedDictionary.CopyTo(set, arr, 0); // Validate data has been written int num = 0; for (int i = 0; i < count; i++) { Assert.AreEqual(i, arr[num++].Key); } Assert.AreEqual(count, UnsafeSortedDictionary.GetCount(set)); Assert.AreEqual(16, UnsafeSortedDictionary.GetCapacity(set)); UnsafeSortedDictionary.Free(set); }