Beispiel #1
0
        private void AssertMultiplicationResultInRange(ulong left, ulong right, ulong maxValue, bool shouldSucceed, ulong expectedResult, NumericTypes numericTypes)
        {
            bool result;

            if (numericTypes.HasFlag(NumericTypes.ULong))
            {
                result = WinCopies.
#if !WinCopies3
                         Util.
#endif
                         Math.IsMultiplicationResultInRange(left, right, maxValue);
                ulong?resultULong = WinCopies.
#if !WinCopies3
                                    Util.
#endif
                                    Math.TryMultiply(left, right, maxValue);

                if (shouldSucceed)
                {
                    Assert.IsTrue(result);

                    Assert.IsTrue(resultULong.HasValue);
                    Assert.AreEqual(expectedResult, resultULong.Value);
                }
                else
                {
                    Assert.IsFalse(result);

                    Assert.IsFalse(resultULong.HasValue);
                }
            }

            if (numericTypes.HasFlag(NumericTypes.UInt))
            {
                var _left     = (uint)left;
                var _right    = (uint)right;
                var _maxValue = (uint)maxValue;

                result = WinCopies.
#if !WinCopies3
                         Util.
#endif
                         Math.IsMultiplicationResultInRange(_left, _right, _maxValue);
                uint?resultUInt = WinCopies.
#if !WinCopies3
                                  Util.
#endif
                                  Math.TryMultiply(_left, _right, _maxValue);

                if (shouldSucceed)
                {
                    Assert.IsTrue(result);

                    Assert.IsTrue(resultUInt.HasValue);
                    Assert.AreEqual((uint)expectedResult, resultUInt.Value);
                }
                else
                {
                    Assert.IsFalse(result);

                    Assert.IsFalse(resultUInt.HasValue);
                }
            }

            if (numericTypes.HasFlag(NumericTypes.UShort))
            {
                var _left     = (ushort)left;
                var _right    = (ushort)right;
                var _maxValue = (ushort)maxValue;

                result = WinCopies.
#if !WinCopies3
                         Util.
#endif
                         Math.IsMultiplicationResultInRange(_left, _right, _maxValue);
                ushort?resultUShort = WinCopies.
#if !WinCopies3
                                      Util.
#endif
                                      Math.TryMultiply(_left, _right, _maxValue);

                if (shouldSucceed)
                {
                    Assert.IsTrue(result);

                    Assert.IsTrue(resultUShort.HasValue);
                    Assert.AreEqual((ushort)expectedResult, resultUShort.Value);
                }
                else
                {
                    Assert.IsFalse(result);

                    Assert.IsFalse(resultUShort.HasValue);
                }
            }

            if (numericTypes.HasFlag(NumericTypes.Byte))
            {
                var _left     = (byte)left;
                var _right    = (byte)right;
                var _maxValue = (byte)maxValue;

                result = WinCopies.
#if !WinCopies3
                         Util.
#endif
                         Math.IsMultiplicationResultInRange(_left, _right, _maxValue);
                byte?resultByte = WinCopies.
#if !WinCopies3
                                  Util.
#endif
                                  Math.TryMultiply(_left, _right, _maxValue);

                if (shouldSucceed)
                {
                    Assert.IsTrue(result);

                    Assert.IsTrue(resultByte.HasValue);
                    Assert.AreEqual((byte)expectedResult, resultByte.Value);
                }
                else
                {
                    Assert.IsFalse(result);

                    Assert.IsFalse(resultByte.HasValue);
                }
            }
        }