Ejemplo n.º 1
0
        public void TestConnectionBinarySearch()
        {
            var db = new ConnectionsDb();

            var connection0 = db.Add(0, 1, 1234, 0, 9);
            var connection1 = db.Add(0, 1, 1234, 10, 19);
            var connection2 = db.Add(0, 2, 1234, 20, 29);
            var connection3 = db.Add(0, 3, 1234, 30, 39);
            var connection4 = db.Add(0, 4, 1234, 40, 49);
            var connection5 = db.Add(0, 5, 1234, 50, 59);

            db.Sort(DefaultSorting.DepartureTime, null);

            var enumerator = db.GetEnumerator(DefaultSorting.DepartureTime);

            Assert.IsTrue(enumerator.MoveToDepartureTime(5));
            Assert.AreEqual(connection1, enumerator.Id);

            Assert.IsTrue(enumerator.MoveToDepartureTime(15));
            Assert.AreEqual(connection2, enumerator.Id);

            Assert.IsTrue(enumerator.MoveToDepartureTime(25));
            Assert.AreEqual(connection3, enumerator.Id);

            Assert.IsTrue(enumerator.MoveToDepartureTime(35));
            Assert.AreEqual(connection4, enumerator.Id);

            Assert.IsTrue(enumerator.MoveToDepartureTime(45));
            Assert.AreEqual(connection5, enumerator.Id);

            Assert.IsTrue(enumerator.MoveToDepartureTime(0));
            Assert.AreEqual(connection0, enumerator.Id);

            Assert.IsTrue(enumerator.MoveToDepartureTime(10));
            Assert.AreEqual(connection1, enumerator.Id);

            Assert.IsTrue(enumerator.MoveToDepartureTime(20));
            Assert.AreEqual(connection2, enumerator.Id);

            Assert.IsTrue(enumerator.MoveToDepartureTime(30));
            Assert.AreEqual(connection3, enumerator.Id);

            Assert.IsTrue(enumerator.MoveToDepartureTime(40));
            Assert.AreEqual(connection4, enumerator.Id);

            Assert.IsTrue(enumerator.MoveToDepartureTime(50));
            Assert.AreEqual(connection5, enumerator.Id);

            Assert.IsFalse(enumerator.MoveToDepartureTime(51));
        }
Ejemplo n.º 2
0
        public void TestConnectionMoveToPreviousConnection()
        {
            var db = new ConnectionsDb();

            var connection0 = db.Add(0, 1, 1, 0, 9);
            var connection1 = db.Add(0, 1, 2, 1, 19);
            var connection2 = db.Add(0, 2, 3, 2, 29);
            var connection3 = db.Add(0, 3, 3, 3, 39);
            var connection4 = db.Add(0, 4, 2, 4, 49);
            var connection5 = db.Add(0, 5, 1, 5, 59);

            db.Sort(DefaultSorting.DepartureTime, null);

            var enumerator = db.GetEnumerator();

            enumerator.MoveTo(connection5);
            Assert.IsTrue(enumerator.MoveToPreviousConnection());
            Assert.AreEqual(connection0, enumerator.Id);

            enumerator.MoveTo(connection4);
            Assert.IsTrue(enumerator.MoveToPreviousConnection());
            Assert.AreEqual(connection1, enumerator.Id);

            enumerator.MoveTo(connection3);
            Assert.IsTrue(enumerator.MoveToPreviousConnection());
            Assert.AreEqual(connection2, enumerator.Id);

            enumerator.MoveTo(connection2);
            Assert.IsFalse(enumerator.MoveToPreviousConnection());

            enumerator.MoveTo(connection1);
            Assert.IsFalse(enumerator.MoveToPreviousConnection());

            enumerator.MoveTo(connection0);
            Assert.IsFalse(enumerator.MoveToPreviousConnection());
        }
Ejemplo n.º 3
0
        public void TestConnectionSorting()
        {
            var db = new ConnectionsDb();

            Assert.IsFalse(db.Sorting.HasValue);

            db.Add(0, 1, 1234, 0, 100);
            db.Add(0, 1, 1234, 100, 1000);
            db.Add(0, 2, 1234, 10, 200);
            db.Add(0, 3, 1234, 1000, 2000);
            db.Add(0, 4, 1234, 101, 201);
            db.Add(0, 5, 1234, 102, 101 + (1 << 15) - 1);

            db.Sort(DefaultSorting.DepartureTime, null);
            Assert.IsTrue(db.Sorting.HasValue);
            Assert.AreEqual(DefaultSorting.DepartureTime, db.Sorting.Value);

            var enumerator = db.GetEnumerator(DefaultSorting.DepartureTime);

            Assert.IsTrue(enumerator.MoveTo(0));
            Assert.AreEqual(0, enumerator.DepartureStop);
            Assert.AreEqual(1, enumerator.ArrivalStop);
            Assert.AreEqual(1234, enumerator.TripId);
            Assert.AreEqual(0, enumerator.DepartureTime);
            Assert.AreEqual(100, enumerator.ArrivalTime);

            Assert.IsTrue(enumerator.MoveTo(1));
            Assert.AreEqual(0, enumerator.DepartureStop);
            Assert.AreEqual(2, enumerator.ArrivalStop);
            Assert.AreEqual(1234, enumerator.TripId);
            Assert.AreEqual(10, enumerator.DepartureTime);
            Assert.AreEqual(200, enumerator.ArrivalTime);

            Assert.IsTrue(enumerator.MoveTo(2));
            Assert.AreEqual(0, enumerator.DepartureStop);
            Assert.AreEqual(1, enumerator.ArrivalStop);
            Assert.AreEqual(1234, enumerator.TripId);
            Assert.AreEqual(100, enumerator.DepartureTime);
            Assert.AreEqual(1000, enumerator.ArrivalTime);

            Assert.IsTrue(enumerator.MoveTo(3));
            Assert.AreEqual(0, enumerator.DepartureStop);
            Assert.AreEqual(4, enumerator.ArrivalStop);
            Assert.AreEqual(1234, enumerator.TripId);
            Assert.AreEqual(101, enumerator.DepartureTime);
            Assert.AreEqual(201, enumerator.ArrivalTime);

            Assert.IsTrue(enumerator.MoveTo(4));
            Assert.AreEqual(0, enumerator.DepartureStop);
            Assert.AreEqual(5, enumerator.ArrivalStop);
            Assert.AreEqual(1234, enumerator.TripId);
            Assert.AreEqual(102, enumerator.DepartureTime);
            Assert.AreEqual(101 + (1 << 15) - 1, enumerator.ArrivalTime);

            Assert.IsTrue(enumerator.MoveTo(5));
            Assert.AreEqual(0, enumerator.DepartureStop);
            Assert.AreEqual(3, enumerator.ArrivalStop);
            Assert.AreEqual(1234, enumerator.TripId);
            Assert.AreEqual(1000, enumerator.DepartureTime);
            Assert.AreEqual(2000, enumerator.ArrivalTime);

            enumerator = db.GetEnumerator(DefaultSorting.ArrivalTime);

            Assert.IsTrue(enumerator.MoveTo(0));
            Assert.AreEqual(0, enumerator.DepartureStop);
            Assert.AreEqual(1, enumerator.ArrivalStop);
            Assert.AreEqual(1234, enumerator.TripId);
            Assert.AreEqual(0, enumerator.DepartureTime);
            Assert.AreEqual(100, enumerator.ArrivalTime);

            Assert.IsTrue(enumerator.MoveTo(1));
            Assert.AreEqual(0, enumerator.DepartureStop);
            Assert.AreEqual(2, enumerator.ArrivalStop);
            Assert.AreEqual(1234, enumerator.TripId);
            Assert.AreEqual(10, enumerator.DepartureTime);
            Assert.AreEqual(200, enumerator.ArrivalTime);

            Assert.IsTrue(enumerator.MoveTo(2));
            Assert.AreEqual(0, enumerator.DepartureStop);
            Assert.AreEqual(4, enumerator.ArrivalStop);
            Assert.AreEqual(1234, enumerator.TripId);
            Assert.AreEqual(101, enumerator.DepartureTime);
            Assert.AreEqual(201, enumerator.ArrivalTime);

            Assert.IsTrue(enumerator.MoveTo(3));
            Assert.AreEqual(0, enumerator.DepartureStop);
            Assert.AreEqual(1, enumerator.ArrivalStop);
            Assert.AreEqual(1234, enumerator.TripId);
            Assert.AreEqual(100, enumerator.DepartureTime);
            Assert.AreEqual(1000, enumerator.ArrivalTime);

            Assert.IsTrue(enumerator.MoveTo(4));
            Assert.AreEqual(0, enumerator.DepartureStop);
            Assert.AreEqual(3, enumerator.ArrivalStop);
            Assert.AreEqual(1234, enumerator.TripId);
            Assert.AreEqual(1000, enumerator.DepartureTime);
            Assert.AreEqual(2000, enumerator.ArrivalTime);

            Assert.IsTrue(enumerator.MoveTo(5));
            Assert.AreEqual(0, enumerator.DepartureStop);
            Assert.AreEqual(5, enumerator.ArrivalStop);
            Assert.AreEqual(1234, enumerator.TripId);
            Assert.AreEqual(102, enumerator.DepartureTime);
            Assert.AreEqual(101 + (1 << 15) - 1, enumerator.ArrivalTime);
        }