public void SaveLoadUIntNET() { using (MemoryStream stream = new MemoryStream()) { var value = new BigUInt(); var value2 = new BigUInt("100"); stream.Seek(0, SeekOrigin.Begin); value.Save(stream); stream.Seek(0, SeekOrigin.Begin); value2.Load(stream); Assert.AreEqual(value, value2); value.Set("123"); stream.Seek(0, SeekOrigin.Begin); value.Save(stream); stream.Seek(0, SeekOrigin.Begin); value2.Load(stream); Assert.AreEqual(value, value2); value.Set("FFFFFFFFFFFFFFFFFFFFFFFFFF"); stream.Seek(0, SeekOrigin.Begin); value.Save(stream); stream.Seek(0, SeekOrigin.Begin); value2.Load(stream); Assert.AreEqual(value, value2); value.Set("0"); stream.Seek(0, SeekOrigin.Begin); value.Save(stream); stream.Seek(0, SeekOrigin.Begin); value2.Load(stream); Assert.AreEqual(value, value2); } }
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; }); }