public void SaveLoadTest() { SmallModulus sm1 = new SmallModulus(65537ul); SmallModulus sm2 = new SmallModulus(); Assert.AreNotSame(sm1, sm2); Assert.AreNotEqual(sm1, sm2); Assert.AreNotEqual(sm1.IsPrime, sm2.IsPrime); using (MemoryStream stream = new MemoryStream()) { sm1.Save(stream); stream.Seek(offset: 0, loc: SeekOrigin.Begin); sm2.Load(stream); } Assert.AreNotSame(sm1, sm2); Assert.AreEqual(sm1, sm2); Assert.AreEqual(sm1.BitCount, sm2.BitCount); Assert.AreEqual(sm1.UInt64Count, sm2.UInt64Count); Assert.AreEqual(sm1.ConstRatio.Item1, sm2.ConstRatio.Item1); Assert.AreEqual(sm1.ConstRatio.Item2, sm2.ConstRatio.Item2); Assert.AreEqual(sm1.ConstRatio.Item3, sm2.ConstRatio.Item3); Assert.AreEqual(sm1.IsPrime, sm2.IsPrime); }
public void SaveLoadSmallModulusNET() { var stream = new MemoryStream(); var mod = new SmallModulus(); stream.Seek(0, SeekOrigin.Begin); mod.Save(stream); var mod2 = new SmallModulus(); stream.Seek(0, SeekOrigin.Begin); mod2.Load(stream); Assert.AreEqual(mod2.Value, mod.Value); Assert.AreEqual(mod2.BitCount, mod.BitCount); Assert.AreEqual(mod2.UInt64Count, mod.UInt64Count); Assert.AreEqual(mod2.ConstRatio.Item1, mod.ConstRatio.Item1); Assert.AreEqual(mod2.ConstRatio.Item2, mod.ConstRatio.Item2); Assert.AreEqual(mod2.ConstRatio.Item3, mod.ConstRatio.Item3); mod.Set(3); stream.Seek(0, SeekOrigin.Begin); mod.Save(stream); stream.Seek(0, SeekOrigin.Begin); mod2.Load(stream); Assert.AreEqual(mod2.Value, mod.Value); Assert.AreEqual(mod2.BitCount, mod.BitCount); Assert.AreEqual(mod2.UInt64Count, mod.UInt64Count); Assert.AreEqual(mod2.ConstRatio.Item1, mod.ConstRatio.Item1); Assert.AreEqual(mod2.ConstRatio.Item2, mod.ConstRatio.Item2); Assert.AreEqual(mod2.ConstRatio.Item3, mod.ConstRatio.Item3); mod.Set(0xF00000F00000F); stream.Seek(0, SeekOrigin.Begin); mod.Save(stream); stream.Seek(0, SeekOrigin.Begin); mod2.Load(stream); Assert.AreEqual(mod2.Value, mod.Value); Assert.AreEqual(mod2.BitCount, mod.BitCount); Assert.AreEqual(mod2.UInt64Count, mod.UInt64Count); Assert.AreEqual(mod2.ConstRatio.Item1, mod.ConstRatio.Item1); Assert.AreEqual(mod2.ConstRatio.Item2, mod.ConstRatio.Item2); Assert.AreEqual(mod2.ConstRatio.Item3, mod.ConstRatio.Item3); }