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]); } }
public void TestUncompress_Safety() { //只有1个数据的时候 _quoteCapture.Add(5, -1); var result = QuoteCapture.Uncompress(_quoteCapture); Assert.IsNotNull(result); Assert.AreEqual(result.Count, 1); Assert.AreEqual(result.Time[0], 5); Assert.AreEqual(result.Price[0], -1); //处理负数时间 _quoteCapture.Clear(); _quoteCapture.Add(-3, 1); _quoteCapture.Add(-1, -1); _quoteCapture.Add(5, 2); result = QuoteCapture.Uncompress(_quoteCapture); Assert.IsNotNull(result); Assert.AreEqual(result.Count, 4); 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], 5); Assert.AreEqual(result.Price[3], 2); //处理非递增序列 _quoteCapture.Clear(); _quoteCapture.Add(0, 1); _quoteCapture.Add(-2, -1); _quoteCapture.Add(3, -1);//用-1作为分段起点 _quoteCapture.Add(5, -1); result = QuoteCapture.Uncompress(_quoteCapture); Assert.IsNotNull(result); Assert.AreEqual(result.Count, 5); Assert.AreEqual(result.Time[0], 0); Assert.AreEqual(result.Price[0], 1); Assert.AreEqual(result.Time[1], -2); Assert.AreEqual(result.Price[1], -1); Assert.AreEqual(result.Time[2], 3); Assert.AreEqual(result.Price[2], -1); Assert.AreEqual(result.Time[3], 4); Assert.AreEqual(result.Price[3], -1); Assert.AreEqual(result.Time[4], 5); Assert.AreEqual(result.Price[4], -1); }
public void TestUncompress_Normal() { TestHelper.AssertException(() => QuoteCapture.Uncompress(null), typeof(ArgumentNullException)); Assert.AreEqual(QuoteCapture.Uncompress(_quoteCapture).Count, 0); //重复数据在开始 _quoteCapture.Add(1, 1); _quoteCapture.Add(3, -1); _quoteCapture.Add(4, 2); var result = QuoteCapture.Uncompress(_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], 1); Assert.AreEqual(result.Time[2], 3); Assert.AreEqual(result.Price[2], 1); Assert.AreEqual(result.Time[3], 4); Assert.AreEqual(result.Price[3], 2); //重复数据在末尾 _quoteCapture.Clear(); _quoteCapture.Add(1, 1); _quoteCapture.Add(2, 2); _quoteCapture.Add(5, -1); result = QuoteCapture.Uncompress(_quoteCapture); Assert.IsNotNull(result); Assert.AreEqual(result.Count, 5); 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], 3); Assert.AreEqual(result.Price[2], 2); Assert.AreEqual(result.Time[3], 4); Assert.AreEqual(result.Price[3], 2); Assert.AreEqual(result.Time[4], 5); Assert.AreEqual(result.Price[4], 2); //重复数据在中间 _quoteCapture.Clear(); _quoteCapture.Add(1, 1); _quoteCapture.Add(2, 2); _quoteCapture.Add(4, -1); _quoteCapture.Add(5, 6); result = QuoteCapture.Uncompress(_quoteCapture); Assert.IsNotNull(result); Assert.AreEqual(result.Count, 5); 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], 3); Assert.AreEqual(result.Price[2], 2); Assert.AreEqual(result.Time[3], 4); Assert.AreEqual(result.Price[3], 2); Assert.AreEqual(result.Time[4], 5); Assert.AreEqual(result.Price[4], 6); //复合重复数据 开始中间结尾都有 _quoteCapture.Clear(); _quoteCapture.Add(1, 1); _quoteCapture.Add(3, -1); _quoteCapture.Add(4, 2); _quoteCapture.Add(6, -1); _quoteCapture.Add(7, 3); _quoteCapture.Add(8, 4); _quoteCapture.Add(10, -1); result = QuoteCapture.Uncompress(_quoteCapture); Assert.IsNotNull(result); Assert.AreEqual(result.Count, 10); Assert.AreEqual(result.Time[0], 1); Assert.AreEqual(result.Price[0], 1); Assert.AreEqual(result.Time[1], 2); Assert.AreEqual(result.Price[1], 1); Assert.AreEqual(result.Time[2], 3); Assert.AreEqual(result.Price[2], 1); Assert.AreEqual(result.Time[3], 4); Assert.AreEqual(result.Price[3], 2); Assert.AreEqual(result.Time[4], 5); Assert.AreEqual(result.Price[4], 2); Assert.AreEqual(result.Time[5], 6); Assert.AreEqual(result.Price[5], 2); Assert.AreEqual(result.Time[6], 7); Assert.AreEqual(result.Price[6], 3); Assert.AreEqual(result.Time[7], 8); Assert.AreEqual(result.Price[7], 4); Assert.AreEqual(result.Time[8], 9); Assert.AreEqual(result.Price[8], 4); Assert.AreEqual(result.Time[9], 10); Assert.AreEqual(result.Price[9], 4); }