Esempio n. 1
0
        [Test, Ignore("broken")] // TODO
        public void CouldAppendSeries()
        {
            var sa = new AppendSeries <int, int>(DataBlock.Create());

            Assert.IsTrue(sa.TryAddLast(1, 1).Result);
            Assert.IsFalse(sa.TryAddLast(1, 1).Result);

            Assert.IsTrue(sa.TryAddLast(2, 2).Result);

            Assert.Throws <KeyNotFoundException>(() =>
            {
                var _ = sa[0];
            });

            Assert.AreEqual(1, sa[1]);
            Assert.AreEqual(2, sa[2]);

            Assert.AreEqual(2, sa.Count());

            for (int i = 3; i < 42000; i++)
            {
                Assert.IsTrue(sa.TryAddLast(i, i).Result);
                Assert.AreEqual(i, sa.Last.Present.Value);
            }

            //// TODO remove when implemented
            //Assert.Throws<NotImplementedException>(() =>
            //{
            //    for (int i = 32000; i < 33000; i++)
            //    {
            //        Assert.IsTrue(sa.TryAddLast(i, i).Result);
            //    }
            //});

            GC.Collect(2, GCCollectionMode.Forced, true, true);
            GC.WaitForPendingFinalizers();
            GC.Collect(2, GCCollectionMode.Forced, true, true);
            GC.WaitForPendingFinalizers();

            sa.Dispose();

            GC.Collect(2, GCCollectionMode.Forced, true, true);
            GC.WaitForPendingFinalizers();
            GC.Collect(2, GCCollectionMode.Forced, true, true);
            GC.WaitForPendingFinalizers();
        }
Esempio n. 2
0
        public void CouldAppendSeries(int count)
        {
            //var counts = new[] { 50, 50000 };
            //foreach (var count in counts)
            {
                var sa = new AppendSeries <int, int>();

                Assert.IsTrue(sa.TryAppend(1, 1));
                Assert.AreEqual(1, sa.RowCount, "Row count == 1");
                Assert.IsFalse(sa.TryAppend(1, 1));

                Assert.IsTrue(sa.TryAppend(2, 2));

                Assert.Throws <KeyNotFoundException>(() =>
                {
                    var _ = sa[0];
                });

                Assert.AreEqual(1, sa[1]);
                Assert.AreEqual(2, sa[2]);

                Assert.AreEqual(2, sa.Count());

                for (int i = 3; i < count; i++)
                {
                    Assert.IsTrue(sa.TryAppend(i, i));
                    Assert.AreEqual(i, sa.Last.Present.Value);
                }

                GC.Collect(2, GCCollectionMode.Forced, true, true);
                GC.WaitForPendingFinalizers();
                GC.Collect(2, GCCollectionMode.Forced, true, true);
                GC.WaitForPendingFinalizers();

                //using (var cursor = sa.GetEnumerator())
                //{
                //    for (int i = 1; i < count; i++)
                //    {
                //        Assert.IsTrue(cursor.MoveNext(), $"could MN {i}");
                //        Assert.AreEqual(i, cursor.CurrentKey);
                //        Assert.AreEqual(i, cursor.CurrentValue);
                //    }
                //}

                //using (var cursor = sa.GetEnumerator())
                //{
                //    for (int i = count - 1; i >= 1; i--)
                //    {
                //        Assert.IsTrue(cursor.MovePrevious(), $"could MP {i}");
                //        Assert.AreEqual(i, cursor.CurrentKey);
                //        Assert.AreEqual(i, cursor.CurrentValue);
                //    }
                //}

                using (var cursor = sa.GetEnumerator())
                {
                    Assert.IsTrue(cursor.Move(count + 1, false) == 0);
                    Assert.IsTrue(cursor.State == CursorState.Initialized);
                }

                using (var cursor = sa.GetEnumerator())
                {
                    Assert.AreEqual(count - 1, cursor.Move(count + 1, true));
                    Assert.IsTrue(cursor.State == CursorState.Moving);
                    Assert.AreEqual(sa.Last.Present.Key, cursor.CurrentKey);
                    Assert.AreEqual(sa.Last.Present.Value, cursor.CurrentValue);
                }

                using (var cursor = sa.GetEnumerator())
                {
                    Assert.AreEqual(-(count - 1), cursor.Move(-count - 1, true));
                    Assert.IsTrue(cursor.State == CursorState.Moving);
                    Assert.AreEqual(sa.First.Present.Key, cursor.CurrentKey);
                    Assert.AreEqual(sa.First.Present.Value, cursor.CurrentValue);
                }

                sa.Dispose();

                GC.Collect(2, GCCollectionMode.Forced, true, true);
                GC.WaitForPendingFinalizers();
                GC.Collect(2, GCCollectionMode.Forced, true, true);
                GC.WaitForPendingFinalizers();
            }
        }