Exemple #1
0
        public void TestCompressAndUncompress_Normal()
        {
            _quoteCapture.Add(1, 1);
            _quoteCapture.Add(2, 1);
            _quoteCapture.Add(3, 1);

            _quoteCapture.Add(4, 2);
            _quoteCapture.Add(5, 2);
            _quoteCapture.Add(6, 2);
            _quoteCapture.Add(7, 2);

            _quoteCapture.Add(9, 2);

            _quoteCapture.Add(10, 3);
            _quoteCapture.Add(11, 3);
            _quoteCapture.Add(12, 3);

            var compress = QuoteCapture.Compress(_quoteCapture);

            Assert.AreNotEqual(compress.Count, _quoteCapture.Count);

            var uncompress = QuoteCapture.Uncompress(compress);

            Assert.AreEqual(_quoteCapture.Count, uncompress.Count);
            Assert.AreEqual(_quoteCapture.Symbol, uncompress.Symbol);
            Assert.AreEqual(_quoteCapture.PipFactor, uncompress.PipFactor);

            for (var i = 0; i < uncompress.Count; i++)
            {
                Assert.AreEqual(_quoteCapture.Time[i], uncompress.Time[i]);
                Assert.AreEqual(_quoteCapture.Price[i], uncompress.Price[i]);
            }
        }
Exemple #2
0
        public void TestCompress_Safety()
        {
            //不压缩重复数据
            _quoteCapture.Add(1, 1);
            _quoteCapture.Add(1, 1);
            _quoteCapture.Add(2, 2);
            _quoteCapture.Add(3, 2);
            _quoteCapture.Add(3, 2);
            _quoteCapture.Add(4, 2);
            _quoteCapture.Add(5, 2);
            _quoteCapture.Add(6, 7);
            var result = QuoteCapture.Compress(_quoteCapture);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Count, 7);
            Assert.AreEqual(result.Time[0], 1);
            Assert.AreEqual(result.Price[0], 1);
            Assert.AreEqual(result.Time[1], 1);
            Assert.AreEqual(result.Price[1], 1);

            Assert.AreEqual(result.Time[2], 2);
            Assert.AreEqual(result.Price[2], 2);
            Assert.AreEqual(result.Time[3], 3);
            Assert.AreEqual(result.Price[3], -1);

            Assert.AreEqual(result.Time[4], 3);
            Assert.AreEqual(result.Price[4], 2);
            Assert.AreEqual(result.Time[5], 5);
            Assert.AreEqual(result.Price[5], -1);
            Assert.AreEqual(result.Time[6], 6);
            Assert.AreEqual(result.Price[6], 7);

            //time时间突然变小也不压缩
            _quoteCapture.Clear();
            _quoteCapture.Add(3, 1);
            _quoteCapture.Add(2, 1);
            _quoteCapture.Add(1, 1);
            _quoteCapture.Add(3, 2);
            _quoteCapture.Add(4, 2);
            _quoteCapture.Add(5, 2);
            result = QuoteCapture.Compress(_quoteCapture);
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Count, 5);
            Assert.AreEqual(result.Time[0], 3);
            Assert.AreEqual(result.Price[0], 1);
            Assert.AreEqual(result.Time[1], 2);
            Assert.AreEqual(result.Price[1], 1);
            Assert.AreEqual(result.Time[2], 1);
            Assert.AreEqual(result.Price[2], 1);
            Assert.AreEqual(result.Time[3], 3);
            Assert.AreEqual(result.Price[3], 2);
            Assert.AreEqual(result.Time[4], 5);
            Assert.AreEqual(result.Price[4], -1);

            //时间间隔大于1也不压缩
            _quoteCapture.Clear();
            _quoteCapture.Add(3, 2);
            _quoteCapture.Add(6, 2);
            _quoteCapture.Add(9, 2);
            _quoteCapture.Add(15, 2);
            result = QuoteCapture.Compress(_quoteCapture);
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Count, 4);
            Assert.AreEqual(result.Time[0], 3);
            Assert.AreEqual(result.Price[0], 2);
            Assert.AreEqual(result.Time[1], 6);
            Assert.AreEqual(result.Price[1], 2);
            Assert.AreEqual(result.Time[2], 9);
            Assert.AreEqual(result.Price[2], 2);
            Assert.AreEqual(result.Time[3], 15);
            Assert.AreEqual(result.Price[3], 2);

            //测试负值情况
            _quoteCapture.Clear();
            _quoteCapture.Add(3, 2);
            _quoteCapture.Add(-2, 2);
            _quoteCapture.Add(-1, 2);
            _quoteCapture.Add(0, 2);
            result = QuoteCapture.Compress(_quoteCapture);
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Count, 3);
            Assert.AreEqual(result.Time[0], 3);
            Assert.AreEqual(result.Price[0], 2);
            Assert.AreEqual(result.Time[1], -2);
            Assert.AreEqual(result.Price[1], 2);
            Assert.AreEqual(result.Time[2], 0);
            Assert.AreEqual(result.Price[2], -1);
        }
Exemple #3
0
        public void TestCompress_Normal()
        {//测试基本功能
            TestHelper.AssertException(() => QuoteCapture.Compress(null), typeof(ArgumentNullException));
            Assert.AreEqual(QuoteCapture.Compress(_quoteCapture).Count, 0);
            //重复数据在开始
            _quoteCapture.Add(1, 1);
            _quoteCapture.Add(2, 1);
            _quoteCapture.Add(3, 1);
            _quoteCapture.Add(4, 2);
            var result = QuoteCapture.Compress(_quoteCapture);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Count, 3);
            Assert.AreEqual(result.Time[0], 1);
            Assert.AreEqual(result.Price[0], 1);
            Assert.AreEqual(result.Time[1], 3);
            Assert.AreEqual(result.Price[1], -1);
            Assert.AreEqual(result.Time[2], 4);
            Assert.AreEqual(result.Price[2], 2);
            //重复数据在末尾
            _quoteCapture.Clear();
            _quoteCapture.Add(1, 1);
            _quoteCapture.Add(2, 2);
            _quoteCapture.Add(3, 2);
            _quoteCapture.Add(4, 2);
            result = QuoteCapture.Compress(_quoteCapture);
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Count, 3);
            Assert.AreEqual(result.Time[0], 1);
            Assert.AreEqual(result.Price[0], 1);
            Assert.AreEqual(result.Time[1], 2);
            Assert.AreEqual(result.Price[1], 2);
            Assert.AreEqual(result.Time[2], 4);
            Assert.AreEqual(result.Price[2], -1);
            //重复数据在中间
            _quoteCapture.Clear();
            _quoteCapture.Add(1, 1);
            _quoteCapture.Add(2, 2);
            _quoteCapture.Add(3, 2);
            _quoteCapture.Add(4, 2);
            _quoteCapture.Add(5, 3);
            result = QuoteCapture.Compress(_quoteCapture);
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Count, 4);
            Assert.AreEqual(result.Time[0], 1);
            Assert.AreEqual(result.Price[0], 1);
            Assert.AreEqual(result.Time[1], 2);
            Assert.AreEqual(result.Price[1], 2);
            Assert.AreEqual(result.Time[2], 4);
            Assert.AreEqual(result.Price[2], -1);
            Assert.AreEqual(result.Time[3], 5);
            Assert.AreEqual(result.Price[3], 3);
            //复合数据 开始中间末尾都有重复数据
            _quoteCapture.Clear();
            _quoteCapture.Add(1, 1);
            _quoteCapture.Add(2, 1);
            _quoteCapture.Add(3, 1);

            _quoteCapture.Add(4, 2);
            _quoteCapture.Add(5, 2);
            _quoteCapture.Add(6, 2);
            _quoteCapture.Add(7, 2);
            _quoteCapture.Add(9, 2);

            _quoteCapture.Add(10, 3);
            _quoteCapture.Add(11, 3);
            _quoteCapture.Add(12, 3);

            result = QuoteCapture.Compress(_quoteCapture);
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Count, 7);
            Assert.AreEqual(result.Time[0], 1);
            Assert.AreEqual(result.Price[0], 1);
            Assert.AreEqual(result.Time[1], 3);
            Assert.AreEqual(result.Price[1], -1);
            Assert.AreEqual(result.Time[2], 4);
            Assert.AreEqual(result.Price[2], 2);
            Assert.AreEqual(result.Time[3], 7);
            Assert.AreEqual(result.Price[3], -1);

            Assert.AreEqual(result.Time[4], 9);
            Assert.AreEqual(result.Price[4], 2);
            Assert.AreEqual(result.Time[5], 10);
            Assert.AreEqual(result.Price[5], 3);
            Assert.AreEqual(result.Time[6], 12);
            Assert.AreEqual(result.Price[6], -1);
        }