Ejemplo n.º 1
0
        public Property StableListPriorityQueue_must_be_stable(NonEmptyString[] values)
        {
            var sortedValues = values
                               .Select(x => x.Item)
                               .GroupBy(x => x.Length)
                               .OrderBy(x => x.Key)
                               .SelectMany(x => x).ToList();
            var pq = new StableListPriorityQueue(10, Priority);

            foreach (var i in values.Select(x => x.Item))
            {
                pq.Enqueue(new Envelope(i, ActorRefs.NoSender));
            }

            var isConsistent = pq.IsConsistent().ToProperty().Label("Expected queue to be consistent, but was not.");

            var queueValues = new List <string>();

            while (pq.Count() > 0)
            {
                queueValues.Add((string)pq.Dequeue().Message);
            }

            var sequenceEqual = queueValues.SequenceEqual(sortedValues).ToProperty().Label(
                $"Expected output to be [{string.Join(",", sortedValues)}] but was [{string.Join(",", queueValues)}]");

            return(sequenceEqual.And(isConsistent));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new unbounded priority message queue.
 /// </summary>
 /// <param name="priorityGenerator">The calculator function for determining the priority of inbound messages.</param>
 /// <param name="initialCapacity">The initial capacity of the queue.</param>
 public UnboundedStablePriorityMessageQueue(Func <object, int> priorityGenerator, int initialCapacity)
 {
     _prioQueue = new StableListPriorityQueue(initialCapacity, priorityGenerator);
 }