Beispiel #1
0
        public void SaveLoadPlaintextNET()
        {
            var stream = new MemoryStream();

            var plain  = new Plaintext();
            var plain2 = new Plaintext();

            plain.Save(stream);
            stream.Seek(0, SeekOrigin.Begin);
            plain2.Load(stream);
            Assert.AreEqual(0, plain2.Capacity);
            Assert.AreEqual(0, plain2.CoeffCount);

            plain.Reserve(20);
            plain.Resize(5);
            plain[0] = 1;
            plain[1] = 2;
            plain[2] = 3;
            stream.Seek(0, SeekOrigin.Begin);
            plain.Save(stream);
            stream.Seek(0, SeekOrigin.Begin);
            plain2.Load(stream);
            Assert.AreEqual(5, plain2.Capacity);
            Assert.AreEqual(5, plain2.CoeffCount);
            Assert.AreEqual(1UL, plain2[0]);
            Assert.AreEqual(2UL, plain2[1]);
            Assert.AreEqual(3UL, plain2[2]);
            Assert.AreEqual(0UL, plain2[3]);
            Assert.AreEqual(0UL, plain2[4]);
        }
Beispiel #2
0
        public void SaveLoadTest()
        {
            {
                SEALContext context = GlobalContext.BFVContext;
                Plaintext   plain   = new Plaintext("6x^5 + 5x^4 + 4x^3 + 3x^2 + 2x^1 + 5");
                Plaintext   other   = new Plaintext();

                Assert.AreNotSame(plain, other);
                Assert.AreNotEqual(plain, other);

                using (MemoryStream stream = new MemoryStream())
                {
                    plain.Save(stream);

                    stream.Seek(offset: 0, loc: SeekOrigin.Begin);

                    other.Load(context, stream);
                }

                Assert.AreNotSame(plain, other);
                Assert.AreEqual(plain, other);
                Assert.IsTrue(ValCheck.IsValidFor(other, context));
            }
            {
                SEALContext context = GlobalContext.BGVContext;
                Plaintext   plain   = new Plaintext("6x^5 + 5x^4 + 4x^3 + 3x^2 + 2x^1 + 5");
                Plaintext   other   = new Plaintext();

                Assert.AreNotSame(plain, other);
                Assert.AreNotEqual(plain, other);

                using (MemoryStream stream = new MemoryStream())
                {
                    plain.Save(stream);

                    stream.Seek(offset: 0, loc: SeekOrigin.Begin);

                    other.Load(context, stream);
                }

                Assert.AreNotSame(plain, other);
                Assert.AreEqual(plain, other);
                Assert.IsTrue(ValCheck.IsValidFor(other, context));
            }
        }