public void SweepBitsInt64() { NumRig rig = new NumRig(); const string SUCCESS = "bar"; rig.Foo = SUCCESS; // to help test stream ending prematurely for (int i = 0; i < 64; i++) { long bigBit = i == 0 ? 0 : (1 << i - 1); for (int j = 0; j <= i; j++) { long smallBit = 1 << j; long val = bigBit | smallBit; rig.Int64Default = rig.Int64FixedSize = rig.Int64TwosComplement = rig.Int64ZigZag = val; NumRig clone = Serializer.DeepClone(rig); Assert.AreEqual(val, clone.Int64Default, "Default"); Assert.AreEqual(val, clone.Int64FixedSize, "FixedSize"); Assert.AreEqual(val, clone.Int64ZigZag, "ZigZag"); Assert.AreEqual(val, clone.Int64TwosComplement, "TwosComplement"); Assert.AreEqual(SUCCESS, clone.Foo, "EOF check: " + val.ToString()); } } }
public void SweepBitsInt64KnownTricky() { try { int i = 31, j = 31; long bigBit = i == 0 ? 0 : (1 << i - 1); long smallBit = 1 << j; long val = bigBit | smallBit; NumRig rig = new NumRig(); rig.Int64Default // 9 => 72 = rig.Int64FixedSize // 12 => 97? = rig.Int64TwosComplement // 11 => 88 = rig.Int64ZigZag // 10 => 80 = val; const string SUCCESS = "bar"; rig.Foo = SUCCESS; // to help test stream ending prematurely MemoryStream ms = new MemoryStream(); Serializer.Serialize(ms, rig); byte[] raw = ms.ToArray(); ms.Position = 0; NumRig clone = Serializer.Deserialize <NumRig>(ms); Assert.AreEqual(val, clone.Int64Default, "Default"); Assert.AreEqual(val, clone.Int64FixedSize, "FixedSize"); Assert.AreEqual(val, clone.Int64ZigZag, "ZigZag"); Assert.AreEqual(val, clone.Int64TwosComplement, "TwosComplement"); Assert.AreEqual(SUCCESS, clone.Foo, "EOF check"); } catch (Exception ex) { Debug.WriteLine(ex.StackTrace); Assert.Fail(ex.Message); } }
public void SweepBitsInt32() { NumRig rig = new NumRig(); const string SUCCESS = "bar"; rig.Foo = SUCCESS; // to help test stream ending prematurely for (int i = 0; i < 32; i++) { int bigBit = i == 0 ? 0 : (1 << i - 1); for (int j = 0; j <= i; j++) { int smallBit = 1 << j; int val = bigBit | smallBit; rig.Int32Default = rig.Int32FixedSize = rig.Int32TwosComplement = rig.Int32ZigZag = val; NumRig clone = Serializer.DeepClone(rig); Assert.AreEqual(val, rig.Int32Default); Assert.AreEqual(val, rig.Int32FixedSize); Assert.AreEqual(val, rig.Int32TwosComplement); Assert.AreEqual(val, rig.Int32ZigZag); Assert.AreEqual(SUCCESS, rig.Foo); } } }
public void SweepBitsInt64KnownTricky() { try { int i = 31, j = 31; long bigBit = i == 0 ? 0 : (1 << i - 1); long smallBit = 1 << j; long val = bigBit | smallBit; NumRig rig = new NumRig(); rig.Int64Default // 9 => 72 = rig.Int64FixedSize // 12 => 97? = rig.Int64TwosComplement // 11 => 88 = rig.Int64ZigZag // 10 => 80 = val; const string SUCCESS = "bar"; rig.Foo = SUCCESS; // to help test stream ending prematurely MemoryStream ms = new MemoryStream(); Serializer.Serialize(ms, rig); byte[] raw = ms.ToArray(); ms.Position = 0; NumRig clone = Serializer.Deserialize<NumRig>(ms); Assert.AreEqual(val, clone.Int64Default, "Default"); Assert.AreEqual(val, clone.Int64FixedSize, "FixedSize"); Assert.AreEqual(val, clone.Int64ZigZag, "ZigZag"); Assert.AreEqual(val, clone.Int64TwosComplement, "TwosComplement"); Assert.AreEqual(SUCCESS, clone.Foo, "EOF check"); } catch (Exception ex) { Debug.WriteLine(ex.StackTrace); Assert.Fail(ex.Message); } }