using System; using UnitTestSharp; namespace Susurrus.UnitTests { public class ByteTallyTests : TestFixture { public class CountTests : TestFixture { public void StartsAtZero() { CheckEqual(0L, new ByteTally().Count); } } public class AddTests : TestFixture { public void RaisesTheCountByTheBytesGiven() { ByteTally tally = new ByteTally(); tally.Add(100); tally.Add(25); CheckEqual(125L, tally.Count); } public void ZeroBytes_ChangesNothing() { ByteTally tally = new ByteTally(); tally.Add(0); CheckEqual(0L, tally.Count); } public void MoreThanAnIntHolds_IsKept() { ByteTally tally = new ByteTally(); tally.Add(int.MaxValue); tally.Add(int.MaxValue); CheckEqual(2L * int.MaxValue, tally.Count); } public void NegativeBytes_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new ByteTally().Add(-1); } } public class SubtractTests : TestFixture { public void LowersTheCountByTheBytesGiven() { ByteTally tally = new ByteTally(); tally.Add(100); tally.Subtract(30); CheckEqual(70L, tally.Count); } public void EveryByteCounted_LeavesZero() { ByteTally tally = new ByteTally(); tally.Add(100); tally.Subtract(100); CheckEqual(0L, tally.Count); } public void MoreThanTheCount_Throws() { ByteTally tally = new ByteTally(); tally.Add(100); CheckThrow(typeof(ArgumentOutOfRangeException)); tally.Subtract(101); } public void NegativeBytes_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new ByteTally().Subtract(-1); } } } }