コード例 #1
0
ファイル: BigUIntTests.cs プロジェクト: eshnil2000/bootcamp
        public void DuplicateToNET()
        {
            var original = new BigUInt(123);

            original.Set(56789);

            var target = new BigUInt();

            original.DuplicateTo(target);
            Assert.AreEqual(target.BitCount, original.BitCount);
            Assert.IsTrue(target.Equals(original));
        }
コード例 #2
0
ファイル: BigUIntTests.cs プロジェクト: eshnil2000/bootcamp
        public void ExceptionsTest()
        {
            BigUInt bui  = new BigUInt("DEADBEEF");
            BigUInt bui1 = null;

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = new BigUInt((BigUInt)null));
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = new BigUInt((string)null));
            Utilities.AssertThrows <ArgumentException>(() => bui1     = new BigUInt(bitCount: -1));
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = new BigUInt(bitCount: 64, hexString: null));
            Utilities.AssertThrows <ArgumentException>(() => bui1     = new BigUInt(bitCount: -1, hexString: "ABCDEF"));
            Utilities.AssertThrows <ArgumentException>(() => bui1     = new BigUInt(bitCount: -1, value: 10ul));

            bui1 = new BigUInt();
            BigUInt bui2 = new BigUInt();

            Utilities.AssertThrows <ArgumentOutOfRangeException>(() => bui.Data(1));

            Utilities.AssertThrows <ArgumentOutOfRangeException>(() => bui[5]);
            Utilities.AssertThrows <ArgumentOutOfRangeException>(() => bui[5] = 2);

            Utilities.AssertThrows <ArgumentNullException>(() => bui.DivideRemainder(bui1, null));
            Utilities.AssertThrows <ArgumentNullException>(() => bui.DivideRemainder(null, bui2));
            Utilities.AssertThrows <ArgumentException>(() => bui.DivideRemainder(bui1, bui2));

            Utilities.AssertThrows <ArgumentNullException>(() => bui.DivideRemainder(1ul, null));
            Utilities.AssertThrows <ArgumentException>(() => bui.DivideRemainder(0ul, bui2));

            Utilities.AssertThrows <ArgumentNullException>(() => bui.DuplicateFrom(null));
            Utilities.AssertThrows <ArgumentNullException>(() => bui.DuplicateTo(null));

            Assert.IsFalse(bui.Equals(null));

            Utilities.AssertThrows <ArgumentNullException>(() => bui.Load(null));
            Utilities.AssertThrows <ArgumentNullException>(() => bui.ModuloInvert(null));
            Utilities.AssertThrows <ArgumentException>(() => bui.Resize(bitCount: -1));
            Utilities.AssertThrows <ArgumentNullException>(() => bui.Save(null));

            Utilities.AssertThrows <ArgumentNullException>(() => bui.Set((BigUInt)null));
            Utilities.AssertThrows <ArgumentNullException>(() => bui.Set((string)null));

            Utilities.AssertThrows <ArgumentNullException>(() => bui.TryModuloInvert(bui1, null));
            Utilities.AssertThrows <ArgumentNullException>(() => bui.TryModuloInvert(null, bui2));
            Utilities.AssertThrows <ArgumentException>(() => bui.TryModuloInvert(bui1, bui2));
            Utilities.AssertThrows <ArgumentNullException>(() => bui.TryModuloInvert(1ul, null));

            bui2 = null;

            Utilities.AssertThrows <ArgumentNullException>(() => bui2 = +bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui2 = -bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui2 = ~bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui2++);
            Utilities.AssertThrows <ArgumentNullException>(() => bui2--);

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui + bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 + bui);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 + 1ul);

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui - bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 - bui);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 - 1ul);

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui * bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 * bui);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 * 1ul);

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui / bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 / bui);
            Utilities.AssertThrows <ArgumentException>(() => bui1     = bui / bui1);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 / 1ul);
            Utilities.AssertThrows <ArgumentException>(() => bui1     = bui / 0ul);

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui ^ bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 ^ bui);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 ^ 1ul);

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui & bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 & bui);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 & 1ul);

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui | bui2);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 | bui);
            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 | 1ul);

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 << 5);
            Utilities.AssertThrows <ArgumentException>(() => bui1     = bui1 << -1);

            Utilities.AssertThrows <ArgumentNullException>(() => bui1 = bui2 >> 5);
            Utilities.AssertThrows <ArgumentException>(() => bui1     = bui1 >> -1);

            Utilities.AssertThrows <ArgumentNullException>(() => { double d = (double)bui2; });
            Utilities.AssertThrows <ArgumentNullException>(() => { float f = (float)bui2; });
            Utilities.AssertThrows <ArgumentNullException>(() => { ulong u = (ulong)bui2; });
            Utilities.AssertThrows <ArgumentNullException>(() => { long l = (long)bui2; });
            Utilities.AssertThrows <ArgumentNullException>(() => { uint u = (uint)bui2; });
            Utilities.AssertThrows <ArgumentNullException>(() => { int i = (int)bui2; });
        }