示例#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);
        }
示例#2
0
        public void Add_SimpleSpanTwo()
        {
            var baseTime = DateTime.UtcNow;
            var span     = new TRexSpan <CellPass>(new CellPass[2], TRexSpan <CellPass> .NO_SLAB_INDEX, 0, 2, false);
            var cp1      = new CellPass
            {
                Time = baseTime
            };
            var cp2 = new CellPass
            {
                Time = baseTime.AddMinutes(1)
            };

            span.Add(cp1);
            span.Add(cp2);

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

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

            span.OffsetPlusCount.Should().Be(2);
        }
示例#3
0
        public void Add_CentralSpanTwo(int poolSize, ushort spanOffset, int spanCapacity)
        {
            var baseTime = DateTime.UtcNow;
            var span     = new TRexSpan <CellPass>(new CellPass[poolSize], TRexSpan <CellPass> .NO_SLAB_INDEX, spanOffset, spanCapacity, false);
            var cp1      = new CellPass
            {
                Time = baseTime
            };
            var cp2 = new CellPass
            {
                Time = baseTime.AddMinutes(1)
            };

            span.Add(cp1);
            span.Add(cp2);

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

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

            span.OffsetPlusCount.Should().Be(spanOffset + span.Count);
        }
示例#4
0
        public void Add_Fail_ExceedsCapacity()
        {
            var span = new TRexSpan <CellPass>(new CellPass[1], TRexSpan <CellPass> .NO_SLAB_INDEX, 0, 1, false);
            var cp   = new CellPass();

            span.Add(cp);
            Action act = () => span.Add(cp);

            act.Should().Throw <ArgumentException>()
            .WithMessage($"No spare capacity to add new element, capacity = 1, element count = 1");
        }
示例#5
0
        public void Copy_Fail_SpanT_SourceCountOutOfBounds()
        {
            var span  = new TRexSpan <CellPass>(new CellPass[10], TRexSpan <CellPass> .NO_SLAB_INDEX, 5, 2, false);
            var span2 = new TRexSpan <CellPass>(new CellPass[10], TRexSpan <CellPass> .NO_SLAB_INDEX, 5, 1, false);
            var span3 = new TRexSpan <CellPass>(new CellPass[1], TRexSpan <CellPass> .NO_SLAB_INDEX, 0, 1, false);

            Action act = () => span2.Copy(span, 3);

            act.Should().Throw <ArgumentException>().WithMessage("Source count may not be negative or greater than the count of elements in the source");

            span.Add(new CellPass());
            span.Add(new CellPass());

            act = () => span3.Copy(span, 2);
            act.Should().Throw <ArgumentException>().WithMessage("Target has insufficient capacity (1) to contain required items from source (2)");
        }
示例#6
0
        public void GetElement_SingleElement_Success()
        {
            var baseTime = DateTime.UtcNow;
            var span     = new TRexSpan <CellPass>(new CellPass[3], TRexSpan <CellPass> .NO_SLAB_INDEX, 0, 3, false);

            var cp = new CellPass
            {
                Time = baseTime
            };

            span.Add(cp);

            span.GetElement(0).Should().BeEquivalentTo(cp);
        }
示例#7
0
        public void Copy_Central()
        {
            var baseTime = DateTime.UtcNow;
            var span     = new TRexSpan <CellPass>(new CellPass[12], TRexSpan <CellPass> .NO_SLAB_INDEX, 5, 2, false);
            var cp1      = new CellPass
            {
                Time = baseTime
            };
            var cp2 = new CellPass
            {
                Time = baseTime.AddMinutes(1)
            };

            span.Add(cp1);
            span.Add(cp2);

            var span2 = new TRexSpan <CellPass>(new CellPass[8], TRexSpan <CellPass> .NO_SLAB_INDEX, 0, 8, false);

            span2.Copy(span, 2);

            span2.Count.Should().Be(2);
            span2.GetElement(0).Should().BeEquivalentTo(cp1);
            span2.GetElement(1).Should().BeEquivalentTo(cp2);
        }
示例#8
0
        public void SetElement_SingleElement_RangeFailure()
        {
            var baseTime = DateTime.UtcNow;
            var span     = new TRexSpan <CellPass>(new CellPass[3], TRexSpan <CellPass> .NO_SLAB_INDEX, 0, 3, false);

            var cp = new CellPass
            {
                Time = baseTime
            };

            span.Add(cp);

            Action act = () => span.SetElement(cp, -1);

            act.Should().Throw <ArgumentException>("Index out of range");

            act = () => span.SetElement(cp, 1);
            act.Should().Throw <ArgumentException>("Index out of range");
        }
示例#9
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
            }
        }