public void CopyToTest() { var set = UnsafeSortedDictionary.Allocate <int, bool>(10); // Fill set for (int i = 10; i >= 0; i--) { UnsafeSortedDictionary.Add(set, i, i % 2 == 0); } var count = UnsafeSortedDictionary.GetCount(set); var arr = new KeyValuePair <int, bool> [count]; UnsafeSortedDictionary.CopyTo(set, arr, 0); // Check int num = 0; for (int i = 0; i < count; i++) { Assert.AreEqual(i, arr[num++].Key); } UnsafeSortedDictionary.Free(set); }
public void ConstructorTest() { var set = UnsafeSortedDictionary.Allocate <int, bool>(10); Assert.AreEqual(0, UnsafeSortedDictionary.GetCount(set)); Assert.AreEqual(10, UnsafeSortedDictionary.GetCapacity(set)); UnsafeSortedDictionary.Free(set); }
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); }
public void ExpandTest() { var set = UnsafeSortedDictionary.Allocate <int, short>(8, fixedSize: false); // Valid adds for (int i = 0; i < 8; i++) { UnsafeSortedDictionary.Add <int, short>(set, i + 1, 2); } Assert.AreEqual(8, UnsafeSortedDictionary.GetCount(set)); Assert.AreEqual(8, UnsafeSortedDictionary.GetCapacity(set)); UnsafeSortedDictionary.Add <int, short>(set, 42, 12); Assert.AreEqual(9, UnsafeSortedDictionary.GetCount(set)); Assert.AreEqual(16, UnsafeSortedDictionary.GetCapacity(set)); UnsafeSortedDictionary.Free(set); }
public void ExpandFailedTest() { var set = UnsafeSortedDictionary.Allocate <int, float>(8, true); // Valid adds for (int i = 0; i < 8; i++) { UnsafeSortedDictionary.Add <int, float>(set, i + 1, i * i); } Assert.AreEqual(8, UnsafeSortedDictionary.GetCount(set)); Assert.AreEqual(8, UnsafeSortedDictionary.GetCapacity(set)); Assert.Throws <InvalidOperationException>(() => { UnsafeSortedDictionary.Add <int, float>(set, 42, 13.3f); }); UnsafeSortedDictionary.Free(set); }