public void PeakEmptyHeapReturnsNull() { using (NativeBinaryHeap <int> heap = CreateEmptyHeap()) { Assert.That(heap.Peak(), Is.Null); } }
public void ConstructorChoosesCapacityClosestToNextPowerOfTwo(int capacity, int expected) { using (NativeBinaryHeap <int> heap = new NativeBinaryHeap <int>(capacity, Allocator.Temp)) { Assert.That(heap.Capacity, Is.EqualTo(expected)); } }
public void ConstructorClampsToMinimumCapacity() { using (NativeBinaryHeap <int> heap = new NativeBinaryHeap <int>(1, Allocator.Temp)) { Assert.That(heap.Capacity, Is.GreaterThan(1)); } }
public void ConstructorCreatesEmptySet() { using (NativeBinaryHeap <int> heap = new NativeBinaryHeap <int>(1, Allocator.Temp)) { Assert.That(heap.Length, Is.EqualTo(0)); } }
public void GetLengthRequiresReadAccess() { using (NativeBinaryHeap <int> heap = CreateEmptyHeap()) { int len; AssertRequiresReadOrWriteAccess( heap, () => len = heap.Length); } }
private static void AssertRequiresReadOrWriteAccess( NativeBinaryHeap <int> heap, Action action) { heap.TestUseOnlySetAllowReadAndWriteAccess(false); try { Assert.That( () => action(), Throws.TypeOf <InvalidOperationException>()); } finally { heap.TestUseOnlySetAllowReadAndWriteAccess(true); } }
public void PushAndPopFunctionsCorrectly() { using (NativeBinaryHeap <int> heap = CreateEmptyHeap()) { heap.Push(1); heap.Push(5); heap.Push(2); Assert.That(heap.Peak(), Is.EqualTo(5)); Assert.That(heap.Length, Is.EqualTo(3)); Assert.That(heap.Pop(), Is.EqualTo(5)); Assert.That(heap.Pop(), Is.EqualTo(2)); Assert.That(heap.Pop(), Is.EqualTo(1)); Assert.That(heap.Pop(), Is.Null); } }
// Start is called before the first frame update void Start() { Debug.Log(UnsafeUtility.SizeOf(typeof(NativeQuadTreeNode))); binaryHeap = new NativeBinaryHeap <int>(100000, Allocator.Persistent); var binaryHeap2 = new BinaryHeap <int>((a, b) => { return(a < b); }); var date2 = DateTime.UtcNow; for (var i = 0; i < 100000; i++) { binaryHeap2.Push(i); } for (var i = 10000; i >= 0; i--) { binaryHeap2.Remove(i); } Debug.Log((DateTime.UtcNow - date2).TotalSeconds); Debug.Log(binaryHeap2.Count); Debug.Log(binaryHeap2.Peek()); var date = DateTime.UtcNow; new AddJob() { p = binaryHeap, }.Run(); new RemoveJob() { p = binaryHeap }.Run(); Debug.Log((DateTime.UtcNow - date).TotalSeconds); Debug.Log(binaryHeap.Count); Debug.Log(binaryHeap.Peek()); }