public void TestReserve() { IdentifierManager manager = new IdentifierManager(10L, 30L); Assert.AreEqual(12L, manager.Reserve(12L)); long reserve = manager.Reserve(12L); Assert.IsFalse(reserve == 12L, "Same id must be reserved twice!"); Assert.IsTrue(manager.Release(12L)); Assert.IsTrue(manager.Release(reserve)); Assert.IsFalse(manager.Release(12L)); Assert.IsFalse(manager.Release(reserve)); manager = new IdentifierManager(0L, 2L); Assert.AreEqual(0L, manager.Reserve(0L)); Assert.AreEqual(1L, manager.Reserve(1L)); Assert.AreEqual(2L, manager.Reserve(2L)); try { manager.Reserve(0L); Assert.Fail("Exception expected"); } catch (InvalidOperationException) { // expected } try { manager.Reserve(1L); Assert.Fail("Exception expected"); } catch (InvalidOperationException) { // expected } try { manager.Reserve(2L); Assert.Fail("Exception expected"); } catch (InvalidOperationException) { // expected } }
public void TestBasic() { IdentifierManager manager = new IdentifierManager(0L, 100L); Assert.AreEqual(101L, manager.GetRemainingIdentifiers()); Assert.AreEqual(0L, manager.ReserveNew()); Assert.AreEqual(100L, manager.GetRemainingIdentifiers()); Assert.AreEqual(1L, manager.Reserve(0L)); Assert.AreEqual(99L, manager.GetRemainingIdentifiers()); }
public void TestBasic() { IdentifierManager manager = new IdentifierManager(0L, 100L); Assert.AreEqual(101L, manager.GetRemainingIdentifiers()); Assert.AreEqual(0L, manager.ReserveNew()); Assert.AreEqual(100L, manager.GetRemainingIdentifiers()); Assert.AreEqual(1L, manager.Reserve(0L)); Assert.AreEqual(99L, manager.GetRemainingIdentifiers()); }
public void TestReserve() { IdentifierManager manager = new IdentifierManager(10L, 30L); Assert.AreEqual(12L, manager.Reserve(12L)); long reserve = manager.Reserve(12L); Assert.IsFalse(reserve == 12L, "Same id must be reserved twice!"); Assert.IsTrue(manager.Release(12L)); Assert.IsTrue(manager.Release(reserve)); Assert.IsFalse(manager.Release(12L)); Assert.IsFalse(manager.Release(reserve)); manager = new IdentifierManager(0L, 2L); Assert.AreEqual(0L, manager.Reserve(0L)); Assert.AreEqual(1L, manager.Reserve(1L)); Assert.AreEqual(2L, manager.Reserve(2L)); try { manager.Reserve(0L); Assert.Fail("Exception expected"); } catch (InvalidOperationException) { // expected } try { manager.Reserve(1L); Assert.Fail("Exception expected"); } catch (InvalidOperationException) { // expected } try { manager.Reserve(2L); Assert.Fail("Exception expected"); } catch (InvalidOperationException) { // expected } }
public void TestLongLimits() { long min = IdentifierManager.MIN_ID; long max = IdentifierManager.MAX_ID; IdentifierManager manager = new IdentifierManager(min, max); Assert.IsTrue(max - min + 1 > 0, "Limits lead to a long variable overflow"); Assert.IsTrue(manager.GetRemainingIdentifiers() > 0, "Limits lead to a long variable overflow"); Assert.AreEqual(min, manager.ReserveNew()); Assert.AreEqual(max, manager.Reserve(max)); Assert.AreEqual(max - min - 1, manager.GetRemainingIdentifiers()); manager.Release(max); manager.Release(min); }
public void TestLongLimits() { long min = IdentifierManager.MIN_ID; long max = IdentifierManager.MAX_ID; IdentifierManager manager = new IdentifierManager(min, max); Assert.IsTrue(max - min + 1 > 0, "Limits lead to a long variable overflow"); Assert.IsTrue(manager.GetRemainingIdentifiers() > 0, "Limits lead to a long variable overflow"); Assert.AreEqual(min, manager.ReserveNew()); Assert.AreEqual(max, manager.Reserve(max)); Assert.AreEqual(max - min - 1, manager.GetRemainingIdentifiers()); manager.Release(max); manager.Release(min); }
public void TestRelease() { IdentifierManager manager = new IdentifierManager(10L, 20L); Assert.AreEqual(10L, manager.Reserve(10L)); Assert.AreEqual(11L, manager.Reserve(11L)); Assert.AreEqual(12L, manager.Reserve(12L)); Assert.AreEqual(13L, manager.Reserve(13L)); Assert.AreEqual(14L, manager.Reserve(14L)); Assert.IsTrue(manager.Release(10L)); Assert.AreEqual(10L, manager.Reserve(10L)); Assert.IsTrue(manager.Release(10L)); Assert.IsTrue(manager.Release(11L)); Assert.AreEqual(11L, manager.Reserve(11L)); Assert.IsTrue(manager.Release(11L)); Assert.IsFalse(manager.Release(11L)); Assert.IsFalse(manager.Release(10L)); Assert.AreEqual(10L, manager.Reserve(10L)); Assert.AreEqual(11L, manager.Reserve(11L)); Assert.IsTrue(manager.Release(12L)); }
public void TestRelease() { IdentifierManager manager = new IdentifierManager(10L, 20L); Assert.AreEqual(10L, manager.Reserve(10L)); Assert.AreEqual(11L, manager.Reserve(11L)); Assert.AreEqual(12L, manager.Reserve(12L)); Assert.AreEqual(13L, manager.Reserve(13L)); Assert.AreEqual(14L, manager.Reserve(14L)); Assert.IsTrue(manager.Release(10L)); Assert.AreEqual(10L, manager.Reserve(10L)); Assert.IsTrue(manager.Release(10L)); Assert.IsTrue(manager.Release(11L)); Assert.AreEqual(11L, manager.Reserve(11L)); Assert.IsTrue(manager.Release(11L)); Assert.IsFalse(manager.Release(11L)); Assert.IsFalse(manager.Release(10L)); Assert.AreEqual(10L, manager.Reserve(10L)); Assert.AreEqual(11L, manager.Reserve(11L)); Assert.IsTrue(manager.Release(12L)); }