示例#1
0
        public void encodeDecodeLinear()
        {
            Random random = new Random();
            int    n      = 1000;

            double[] mzs = new double[n];
            mzs[0] = 300 + random.NextDouble();
            for (int i = 1; i < n; i++)
            {
                mzs[i] = mzs[i - 1] + random.NextDouble();
            }

            byte[] encoded      = new byte[n * 5];
            double fixedPoint   = MSNumpress.optimalLinearFixedPoint(mzs, n);
            int    encodedBytes = MSNumpress.encodeLinear(mzs, n, encoded, fixedPoint);

            double[] decoded        = new double[n];
            int      decodedDoubles = MSNumpress.decodeLinear(encoded, encodedBytes, decoded);

            Assert.AreEqual(n, decodedDoubles);

            var list = Enumerable.Range(0, 1000).Select(i => decoded[i] / mzs[i]).ToList();

            for (int i = 0; i < n; i++)
            {
                Assert.AreEqual(mzs[i], decoded[i], 0.000005);
            }
        }
示例#2
0
        public void encodeDecodeLinearEmpty()
        {
            byte[] encoded      = new byte[8];
            int    encodedBytes = MSNumpress.encodeLinear(new double[0], 0, encoded, 100000.0);

            double[] decoded      = new double[0];
            int      decodedBytes = MSNumpress.decodeLinear(encoded, 8, decoded);

            Assert.AreEqual(0, decodedBytes);
        }
示例#3
0
        public void encodeLinear()
        {
            double[] mzs          = { 100.0, 200.0, 300.00005, 400.00010 };
            byte[]   encoded      = new byte[40];
            int      encodedBytes = MSNumpress.encodeLinear(mzs, 4, encoded, 100000.0);

            Assert.AreEqual(18, encodedBytes);
            Assert.AreEqual(0x80, 0xff & encoded[8]);
            Assert.AreEqual(0x96, 0xff & encoded[9]);
            Assert.AreEqual(0x98, 0xff & encoded[10]);
            Assert.AreEqual(0x00, 0xff & encoded[11]);
            Assert.AreEqual(0x75, 0xff & encoded[16]);
            Assert.AreEqual(0x80, 0xf0 & encoded[17]);
        }
示例#4
0
        public void decodeLinearWierd()
        {
            double[] mzs          = { 100.0, 200.0, 4000.00005, 0.00010 };
            byte[]   encoded      = new byte[28];
            double   fixedPoint   = MSNumpress.optimalLinearFixedPoint(mzs, 4);
            int      encodedBytes = MSNumpress.encodeLinear(mzs, 4, encoded, fixedPoint);

            double[] decoded    = new double[4];
            int      numDecoded = MSNumpress.decodeLinear(encoded, encodedBytes, decoded);

            Assert.AreEqual(100.0, decoded[0], 0.000005);
            Assert.AreEqual(200.0, decoded[1], 0.000005);
            Assert.AreEqual(4000.00005, decoded[2], 0.000005);
            Assert.AreEqual(0.00010, decoded[3], 0.000005);
        }
示例#5
0
        public void decodeLinearNice()
        {
            double[] mzs          = { 100.0, 200.0, 300.00005, 400.00010 };
            byte[]   encoded      = new byte[28];
            int      encodedBytes = MSNumpress.encodeLinear(mzs, 4, encoded, 100000.0);

            double[] decoded    = new double[4];
            int      numDecoded = MSNumpress.decodeLinear(encoded, encodedBytes, decoded);

            Assert.AreEqual(4, numDecoded);
            Assert.AreEqual(100.0, decoded[0], 0.000005);
            Assert.AreEqual(200.0, decoded[1], 0.000005);
            Assert.AreEqual(300.00005, decoded[2], 0.000005);
            Assert.AreEqual(400.00010, decoded[3], 0.000005);
        }
示例#6
0
        public void encodeDecodeLinear5()
        {
            Random random = new Random();
            int    n      = 1000;

            double[] mzs = new double[n];
            mzs[0] = 300 + random.NextDouble();
            for (int i = 1; i < n; i++)
            {
                mzs[i] = mzs[i - 1] + random.NextDouble();
            }

            byte[]   encoded      = new byte[n * 5];
            double[] decoded      = new double[n];
            double[] firstDecoded = new double[n];
            double   fixedPoint   = MSNumpress.optimalLinearFixedPoint(mzs, n);

            int encodedBytes   = MSNumpress.encodeLinear(mzs, n, encoded, fixedPoint);
            int decodedDoubles = MSNumpress.decodeLinear(encoded, encodedBytes, decoded);

            for (int i = 0; i < n; i++)
            {
                firstDecoded[i] = decoded[i];
            }

            for (int i = 0; i < 5; i++)
            {
                MSNumpress.encodeLinear(decoded, n, encoded, fixedPoint);
                MSNumpress.decodeLinear(encoded, encodedBytes, decoded);
            }

            Assert.AreEqual(n, decodedDoubles);

            for (int i = 0; i < n; i++)
            {
                Assert.AreEqual(firstDecoded[i], decoded[i], double.Epsilon);
            }
        }