Example #1
0
        public void Fill(int amount)
        {
            if (Content > Capacity)
            {
                Full?.Invoke(this, EventArgs.Empty);
                return;
            }

            int overflowed = 0;

            for (int i = 0; i <= amount; i++)
            {
                if (Content > Capacity)
                {
                    Overflowing?.Invoke(this, ++overflowed);
                }

                Content += 1;

                if (Content == Capacity)
                {
                    Full?.Invoke(this, EventArgs.Empty);
                }
            }

            if (overflowed > 0)
            {
                Overflowed?.Invoke(this, overflowed);
            }
        }
Example #2
0
 private static void AssertMultiplicationOverflow(bool expected, ulong x, ulong y)
 {
     Assert.AreEqual(expected, Overflowing.CheckIfMultiplicationOverflows(x, y));
     Assert.AreEqual(expected, Overflowing.CheckIfMultiplicationOverflows(y, x));
     Assert.DoesNotThrow(() => x *= y);
 }
Example #3
0
 private static void AssertAdditionOverflow(bool expected, long x, long y)
 {
     Assert.AreEqual(expected, Overflowing.CheckIfAdditionOverflows(x, y));
     Assert.AreEqual(expected, Overflowing.CheckIfAdditionOverflows(y, x));
     Assert.DoesNotThrow(() => x += y);
 }