Exemplo n.º 1
0
        private static void TestCursor <TEntry, T>(
            Func <DoubleEntry[], TEntry[]> convert,
            Func <TEntry, T> getValue,
            Func <TEntry[], IColumnCursor <T> > factory,
            T defaultValue = default(T))
            where T : struct
        {
            const int iterations = 5;
            var       chunk      = new DoubleEntry[0]
                                   .Add(0, 12.2)
                                   .Add(4, 15.2)
                                   .Add(5, 16.2)
                                   .Add(6, 13.2)
                                   .Add(7, 14.2);

            var convertedChunk = convert(chunk);
            var cursor         = factory(convertedChunk);

            // Test MoveNext
            for (var i = 0; i < iterations; i++)
            {
                Assert.AreEqual(getValue(convertedChunk[0]), cursor.GetNext(0));
                Assert.AreEqual(getValue(convertedChunk[0]), cursor.GetNext(1));
                Assert.AreEqual(getValue(convertedChunk[0]), cursor.GetNext(2));
                Assert.AreEqual(getValue(convertedChunk[1]), cursor.GetNext(4));
                Assert.AreEqual(getValue(convertedChunk[2]), cursor.GetNext(5));
                Assert.AreEqual(getValue(convertedChunk[3]), cursor.GetNext(6));
                Assert.AreEqual(getValue(convertedChunk[4]), cursor.GetNext(7));
                Assert.AreEqual(getValue(convertedChunk[4]), cursor.GetNext(8));
                Assert.AreEqual(getValue(convertedChunk[4]), cursor.GetNext(9));
                cursor.Reset();
            }

            cursor.Dispose();

            chunk.Set(0, 1, 12.2);
            cursor = factory(convert(chunk));
            for (var i = 0; i < iterations; i++)
            {
                Assert.AreEqual(defaultValue, cursor.GetNext(0));
                Assert.AreEqual(getValue(convertedChunk[0]), cursor.GetNext(1));
                Assert.AreEqual(getValue(convertedChunk[3]), cursor.GetNext(6));
                Assert.AreEqual(getValue(convertedChunk[4]), cursor.GetNext(7));
                cursor.Reset();
            }

            cursor.Dispose();
        }