public void AddWaypoint(Waypoint waypoint) { if (waypoint != null) { _waypoints.Enqueue(waypoint); } }
public void EnqueueItemToAFlexQueue() { // Arrange var queue = new FlexQueue<int>(); // Act queue.Enqueue(23); queue.Enqueue(64); queue.Enqueue(100023); queue.Enqueue(-50); }
public void GetNumberOfItemsInFlexQueue() { // Arrange var queue = new FlexQueue<object>(); queue.Enqueue("Hello"); queue.Enqueue(65); queue.Enqueue(new List<string>()); queue.Enqueue(new Action(() => Console.Write("Adding Action"))); // Act and Assert Assert.AreEqual(4, queue.Count); queue.Dequeue(); Assert.AreEqual(3, queue.Count); }
private static FitResult TryFitMeasurement(DocumentPage page, Measurement measurement, FlexQueue <Measurement> queue, bool flexMode, ref double height) { var size = measurement.TotalSize; if (size.Height > height) { if (measurement.Flexible) { if (flexMode) { return(FitResult.Stop); } else { queue.Enqueue(measurement, measurement.Flexible); return(FitResult.Enqueue); } } else { return(FitResult.AddPage); } } if (measurement.Element.Page == null) { measurement.Element.Page = page; } height -= size.Height; page.Measurements.Add(measurement); return(FitResult.Continue); }
public void GetNextItemFromFlexQueue() { // Arrange var queue = new FlexQueue<string>(); // Act queue.Enqueue("DDD"); queue.Enqueue("EEE"); queue.Enqueue("FFF"); queue.Enqueue("GGG"); var firstItem = queue.Dequeue(); var secondItem = queue.Dequeue(); var thirdItem = queue.Dequeue(); // Assert Assert.AreEqual("DDD", firstItem); Assert.AreEqual("EEE", secondItem); Assert.AreEqual("FFF", thirdItem); }
public void Arrange(Document document) { var pageSize = document.Variables["page"]["size"].GetValue <Size>(); var margin = document.Variables["page"]["margin"].GetValue <Thickness>(); var boxSize = pageSize; boxSize.Height -= margin.Height; boxSize.Width -= margin.Width; var startOffset = new Position(margin.Left, margin.Top); var contentArea = new Rectangle(startOffset, boxSize); var curPage = AddPage(document, pageSize, contentArea); double curHeight = boxSize.Height; var flexQueue = new FlexQueue <Measurement>(); //new Queue<Measurement>(); var enqueueNext = false; // Stage one: // Add measurements to pages foreach (var measurement in document.Measurements) { if (enqueueNext) { flexQueue.Enqueue(measurement, measurement.Flexible); enqueueNext = measurement.PagebreakPenalty > 0; } else if (measurement.PagebreakPenalty > 0) { flexQueue.Enqueue(measurement.Flexible); flexQueue.Enqueue(measurement, measurement.Flexible); enqueueNext = true; } else { while (flexQueue.Count > 0) { var peeked = flexQueue.Peek(); if (FitAll(peeked, curHeight)) { foreach (var ms in peeked) { TryFitMeasurement(curPage, ms, flexQueue, true, ref curHeight); } flexQueue.Dequeue(); } else if (!flexQueue.IsFlex) { curHeight = boxSize.Height; curPage.Filled = true; curPage = AddPage(document, pageSize, contentArea); } else { break; } } if (TryFitMeasurement(curPage, measurement, flexQueue, false, ref curHeight) == FitResult.AddPage) { curHeight = boxSize.Height; curPage.Filled = true; curPage = AddPage(document, pageSize, contentArea); } } } // Add leftover flexible items while (flexQueue.Count > 0) { var ms = flexQueue.Dequeue(); foreach (var m in ms) { m.Flexible = false; if (TryFitMeasurement(curPage, m, flexQueue, false, ref curHeight) == FitResult.AddPage) { curHeight = boxSize.Height; curPage.Filled = true; curPage = AddPage(document, pageSize, contentArea); } } } // Stage two: // Layout measurements on each page foreach (var page in document.Pages) { var currentOffset = startOffset; foreach (var measurement in page.Measurements) { var size = measurement.Size; currentOffset.Y += measurement.Margin.Top; var visualOffset = currentOffset; visualOffset.X += measurement.Margin.Left; measurement.Position = visualOffset; Realign(measurement, boxSize, pageSize, measurement.Element.HorizontalAlignment); measurement.Element.Arrange(measurement); currentOffset.Y += size.Height; currentOffset.Y += measurement.Margin.Bottom; } // Set number at the end of the page layouting // so that any number changing elements can take effect page.Number = document.PageNumbering.Next(); page.AddPageItems(); } }
public void LookAtItemInTheMiddleOfFlexQueue() { // Arrange var queue = new FlexQueue<ushort>(); var entries = new List<ushort>{10,1,9,2,3,8,50,31,2000,23,2,65,10000}; entries.ForEach(x => queue.Enqueue(x)); // Assert Enumerable.Range(0, entries.Count).ToList().ForEach(x => { Assert.AreEqual(entries[x], queue.PeekAt(x)); Assert.AreEqual(entries.Count, queue.Count); }); }
public void LookAtItemInMiddleOfFlexQueueThatDoesntExist() { // Arrange var queue = new FlexQueue<ushort>(); var entries = new List<char> { 'c','/','>','L','s' }; entries.ForEach(x => queue.Enqueue(x)); // Assert queue.PeekAt(500); }
public void RemoveItemFromMiddleOfFlexQueue() { // Arrange var queue = new FlexQueue<int>(); var entries = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }; var expEntriesWith5Removed = new List<int> { 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }; var expEntriesWith5and15Removed = new List<int> { 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20 }; var expEntriesWith5and15and1Removed = new List<int> { 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20 }; entries.ForEach(x => queue.Enqueue(x)); // Assert Assert.AreEqual(20, queue.Count); var firstItem = queue.RemoveAt(4); Assert.AreEqual(5, firstItem); Assert.AreEqual(19, queue.Count); Enumerable.Range(0, 19).ToList().ForEach(x => Assert.AreEqual(expEntriesWith5Removed[x], queue.PeekAt(x))); var secondItem = queue.RemoveAt(13); Assert.AreEqual(15, secondItem); Assert.AreEqual(18, queue.Count); Enumerable.Range(0, 18).ToList().ForEach(x => Assert.AreEqual(expEntriesWith5and15Removed[x], queue.PeekAt(x))); var thirdItem = queue.RemoveAt(0); Assert.AreEqual(1, thirdItem); Assert.AreEqual(17, queue.Count); Enumerable.Range(0, 17).ToList().ForEach(x => Assert.AreEqual(expEntriesWith5and15and1Removed[x], queue.PeekAt(x))); }
public void RemoveItemFromFlexQueueWhenOutOfRange() { // Arrange var queue = new FlexQueue<int>(); var entries = new List<int> { 1, 2 }; entries.ForEach(x => queue.Enqueue(x)); // Act queue.RemoveAt(20); }
public void PeekAtNextItemInFlexQueue() { // Arrange var queue = new FlexQueue<Tuple<string,int>>(); queue.Enqueue(new Tuple<string, int>("Entry1", 11111)); queue.Enqueue(new Tuple<string, int>("Entry2", 22222)); queue.Enqueue(new Tuple<string, int>("Entry3", 33333)); queue.Enqueue(new Tuple<string, int>("Entry4", 44444)); queue.Enqueue(new Tuple<string, int>("Entry5", 55555)); // Assert Assert.AreEqual(5, queue.Count); var nextItem = queue.Peek(); Assert.AreEqual(5, queue.Count); Assert.AreEqual("Entry1", nextItem.Item1); Assert.AreEqual(11111, nextItem.Item2); }