Example #1
0
        public void Insert_InMiddle()
        {
            var baseTime = DateTime.UtcNow;
            var span     = new TRexSpan <CellPass>(new CellPass[3], TRexSpan <CellPass> .NO_SLAB_INDEX, 0, 3, false);
            var cp1      = new CellPass
            {
                Time = baseTime
            };
            var cp2 = new CellPass
            {
                Time = baseTime.AddMinutes(1)
            };

            span.Add(cp1);
            span.Add(cp1);
            span.Insert(cp2, 1);

            span.Count.Should().Be(3);
            span.First().Should().BeEquivalentTo(cp1);
            span.Last().Should().BeEquivalentTo(cp1);

            span.GetElement(0).Should().BeEquivalentTo(cp1);
            span.GetElement(1).Should().BeEquivalentTo(cp2);

            span.OffsetPlusCount.Should().Be(3);
        }
Example #2
0
        public void Insert_FailOutOfRange_High()
        {
            var span = new TRexSpan <CellPass>(new CellPass[10], TRexSpan <CellPass> .NO_SLAB_INDEX, 5, 6, false);
            var cp   = new CellPass();

            Action act = () => span.Insert(cp, 7);

            act.Should().Throw <ArgumentException>().WithMessage("Index out of range");
        }
Example #3
0
        /// <summary>
        /// AddPass takes a pass record containing pass information processed
        /// for a machine crossing this cell and adds it to the passes list
        /// </summary>
        public void AddPass(CellPass pass)
        {
#if CELLDEBUG
            CheckPassesAreInCorrectTimeOrder("AddPass(CellPass pass) - before");
            pass._additionStamp = Interlocked.Increment(ref CellPass._lastAdditionStamp);
#endif

            // Locate the position in the list of time ordered passes to insert the new pass
            if (LocateTime(pass.Time, out var position))
            {
                throw new TRexException("Pass with same time being added to cell");
            }

            if (!Passes.IsRented)
            {
                AllocatePasses(PASS_COUNT_INCREMENT_STEP_SIZE);
            }
            else if (Passes.Capacity == Passes.Count)
            {
                AllocatePasses(Passes.Capacity + PASS_COUNT_INCREMENT_STEP_SIZE);
            }

            if (position < PassCount)
            {
                Passes.Insert(pass, position);
#if CELLDEBUG
                CheckPassesAreInCorrectTimeOrder("AddPass(CellPass pass) - after insert");
#endif
            }
            else // Add the new pass to the passes list.
            {
                Passes.Add(pass);
#if CELLDEBUG
                CheckPassesAreInCorrectTimeOrder("AddPass(CellPass pass) - after add");
#endif
            }
        }