public void Add() { var list = new ListNoAlloc <int>(3); list.Add(2); list.Add(1); }
public void ListNoAllocTest() { MemoryWatch watch = new MemoryWatch(); var randomList = GetRandomList(); var listeners = new ListNoAlloc <IEvent> (10); var handler = new HandlerEvent(); listeners.Add(handler); watch.Start(); int l = 0; for (int j = 0; j < Seconds; ++j) { for (int i = 0; i < FramesPerSecond; ++i) { listeners.Add(handler); listeners.ForEach(x => x.EventHandler(true)); listeners.Remove(handler); l += 1; } } watch.Stop(); results.Add(watch.GetAllocationDesc($"Event add/remove using ListNoAlloc for each frame at {FramesPerSecond} FPS for {Seconds} s of game")); // Just so we force l to be used Assert.Less(0, l); }
public void Count() { var list = new ListNoAlloc <int>(3); Assert.AreEqual(0, list.Count); list.Add(2); Assert.AreEqual(2, list.Count); list.Add(1); Assert.AreEqual(1, list.Count); }
public void Index() { var list = new ListNoAlloc <int>(3); list.Add(2); list.Add(1); Assert.AreEqual(2, list[0]); Assert.AreEqual(1, list[1]); }
public void AddTooMany() { var list = new ListNoAlloc <int>(10); for (int i = 0; i < 10; ++i) { list.Add(i * i); } Assert.Throws <OverflowException>(() => list.Add(10)); }
public void RemoveAt() { var list = new ListNoAlloc <int>(3); list.Add(2); list.Add(5); list.Add(7); list.RemoveAt(1); Assert.AreEqual(2, list.Count); Assert.AreEqual(2, list[0]); Assert.AreEqual(7, list[1]); }
public void LogFormatDeferredTemplate() { MemoryWatch watch = new MemoryWatch(); var randomList = GetRandomList(); Log.EnableLogging = false; var listeners = new ListNoAlloc <IEvent>(10); var handler = new HandlerEvent(); listeners.Add(handler); watch.Start(); int l = 0; for (int j = 0; j < Seconds; ++j) { for (int i = 0; i < FramesPerSecond; ++i) { // This will not actually be written because EnableLogging = false // We deferr string construction here Log.InfoT("Formatted message from integer", i); l += 1; } } watch.Stop(); results.Add(watch.GetAllocationDesc($"Log message + template int (deferred) that is ignored for each frame at {FramesPerSecond} FPS for {Seconds} s of game")); // Just so we force l to be used Assert.Less(0, l); }
public void RemoveFail() { var list = new ListNoAlloc <int>(3); Assert.AreEqual(0, list.Count); list.Add(2); Assert.False(list.Remove(3)); Assert.AreEqual(1, list.Count); }
public void Remove() { var list = new ListNoAlloc <int>(3); Assert.AreEqual(0, list.Count); list.Add(2); list.Remove(2); Assert.AreEqual(0, list.Count); }
public void Clear() { var list = new ListNoAlloc <int>(10); for (int i = 0; i < 10; ++i) { list.Add(i * i); } list.Clear(); Assert.AreEqual(0, list.Count); Assert.Throws <ArgumentException>(() => { int x = list[1]; }); }