public void TestRandomAllocation() { int repeatCount = 10000; int range = 100; IList<int> allocated = new List<int>(); IntAllocator intAllocator = new IntAllocator(0, range); Random rand = new Random(); while (repeatCount-- > 0) { if (rand.Next(2) == 0) { int a = intAllocator.Allocate(); if (a > -1) { Assert.False(allocated.Contains(a)); allocated.Add(a); } } else if (allocated.Count > 0) { int a = allocated[0]; intAllocator.Free(a); allocated.RemoveAt(0); } } }
public void TestAllocateAll() { int range = 100; IList<int> allocated = new List<int>(); IntAllocator intAllocator = new IntAllocator(0, range); for (int i=0; i <= range; i++) { int a = intAllocator.Allocate(); Assert.AreNotEqual(-1, a); Assert.False(allocated.Contains(a)); allocated.Add(a); } }
public SessionManager(Connection connection, ushort channelMax) { m_connection = connection; ChannelMax = (channelMax == 0) ? ushort.MaxValue : channelMax; Ints = new IntAllocator(1, ChannelMax); }