public void Queue_ShouldAddElements()
        {
            queue.Add(1);
            Assert.AreEqual(1, queue.Peek());

            queue.Add(3);
            Assert.AreEqual(1, queue.Peek());
        }
 public virtual void TestAdd()
 {
     Assert.IsTrue(q.Add("item1"));
     Assert.IsTrue(q.Add("item2"));
     Assert.IsTrue(q.Add("item3"));
     Assert.IsTrue(q.Add("item4"));
     Assert.IsTrue(q.Add("item5"));
     Assert.AreEqual(5, q.Count);
 }
示例#3
0
        [Test] public void AddChokesWhenQueueIsFull()
        {
            Options.SkipWhenNot(CollectionContractOptions.Bounded);
            IQueue queue = NewQueueFilledWithSample();

            Assert.Throws <InvalidOperationException>(() => queue.Add(MakeData(0)));
        }
示例#4
0
        private void InitSerialPort(BasicInformation connection)
        {
            //// let the connection remains open until the server is closed/disposed
            connection.Connector.Open();

            connection.OnBeginExecuting();

            BaseResult <GenericTypeResult <string> > manufacturer = connection.GetManufacturer();

            if (!string.IsNullOrEmpty(manufacturer.Response.Result))
            {
                connection.GetServiceCenter();
                connection.SetErrorMessageFormat(1);
                connection.GetOperator();

                PhoneBook pb = new PhoneBook(connection);
                pb.SetPhoneBookMemory(MemoryStorage.SIMOwnNumber);
                pb.GetInfo();

                SMS sms = new SMS(connection);
                sms.SetMessageStorage(MemoryStorage.MobilePhonebook, MemoryStorage.MobilePhonebook, MemoryStorage.MobilePhonebook);
                sms.SetMessageFormat(connection.PDUMode);

                string prefixOwnNumber = string.Empty;
                if (string.IsNullOrEmpty(prefixOwnNumber))
                {
                    GSMServer.Configuration.IConfiguration configuration = ObjectPool.Instance.Resolve <GSMServer.Configuration.IConfiguration>();
                    prefixOwnNumber = ((ApplicationSettings)configuration).General.PrefixOwnNumber;
                }

                BaseResult <GenericTypeResult <List <PhoneNumberInfo> > > list = pb.ReadPhoneBook(MemoryStorage.SIMOwnNumber, 1, -1);
                if (list.Response.Result.Count > 0)
                {
                    foreach (PhoneNumberInfo info in list.Response.Result)
                    {
                        if (info.Name.Equals(prefixOwnNumber))
                        {
                            connection.OwnNumber = info.PhoneNumber;
                            break;
                        }
                    }
                }
                portColletion.Add(connection);
            }
            connection.OnEndExecuting();
        }
  }     // readMaze

  private void addPosition(int row, int col)
  // Put a new position on the queue of positions
  {
      Position p = new Position();

      p.r = row;
      p.c = col;
      posQueue.Add(p);
  }     // addPosition
示例#6
0
 private static void AddDataToBuffer(IQueue <double> buffer)
 {
     Console.WriteLine("Podaj liczby do bufora: ");
     while (double.TryParse(Console.ReadLine(), out double value))
     {
         buffer.Add(value);
     }
     Console.WriteLine("W naszej kolejce są liczby: ");
 }
示例#7
0
        protected virtual IQueue <T> NewQueueFilledWithSample()
        {
            IQueue <T> queue = NewQueue();

            foreach (T sample in Samples)
            {
                queue.Add(sample);
            }
            return(queue);
        }
示例#8
0
        [Test] public void AddAllSamplesuccessfully()
        {
            IQueue queue = NewQueue();

            foreach (object o in Samples)
            {
                queue.Add(o);
            }
            Assert.That(queue.Count, Is.EqualTo(Samples.Length));
            CollectionAssert.AreEquivalent(Samples, queue);
        }
示例#9
0
        [Test] public virtual void AddAllSamplesSuccessfully()
        {
            IQueue <T> queue = NewQueue();

            foreach (T sample in Samples)
            {
                queue.Add(sample);
            }
            Assert.That(queue.Count, Is.EqualTo(Samples.Length));
            CollectionAssert.AreEquivalent(Samples, queue);
        }
示例#10
0
 private void QueueListControl_AddClick(object sender, RoutedEventArgs e)
 {
     try
     {
         queue.Add(QueueListControl.Number);
         QueueListControl.ItemSource = FillCollection(queue.Elements);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
     }
 }
示例#11
0
        [Test] public void IsEmptyReturnsTrueWhenQueueIsEmptyElseFalse()
        {
            IQueue queue = NewQueue();

            Assert.IsTrue(queue.IsEmpty);
            if (SampleSize == 0)
            {
                Assert.Pass();
            }
            queue.Add(Samples[0]);
            Assert.IsFalse(queue.IsEmpty);
        }
示例#12
0
        public void Add(TKey key, TItem item)
        {
            IQueue <TKey, TItem> queue = _index.GetOrAdd(key,
                                                         k => new ConsumerQueue <TKey, TItem>(k, WorkCompleted, OnDequeue));

            queue.Add(item);
            _pendingWorkIndex.AddOrUpdate(key, new Counter().Increment(), (k, v) => v.Increment());
            Interlocked.Increment(ref _pendingRequestCounter);
            if (_onAddAction != null)
            {
                _onAddAction(key, item);
            }
        }
示例#13
0
 /// <summary>Schedule a new job on the backend</summary>
 /// <param name="annotate">
 /// A callback, which will be called when a backend is free
 /// to do some processing. The implementation of this callback
 /// MUST CALL the second argument when it is done processing,
 /// to register the backend as free for further work.
 /// </param>
 public virtual void Schedule(IBiConsumer <StanfordCoreNLPClient.Backend, IConsumer <StanfordCoreNLPClient.Backend> > annotate)
 {
     stateLock.Lock();
     try
     {
         queue.Add(annotate);
         enqueued.Signal();
     }
     finally
     {
         stateLock.Unlock();
     }
 }
示例#14
0
        public void CreateMessage(string text)
        {
            if (IsVirus(text))
            {
                queue.DeleteAll();
                return;
            }

            if (!IsCorupt(text))
            {
                queue.Add(new Message(text));
                return;
            }
        }
示例#15
0
        [Test] public virtual void RemainingCapacityDecreasesOnAddIncreasesOnRemove()
        {
            IQueue <T> queue = NewQueue();

            AssertRemainingCapacity(queue, SampleSize);
            for (int i = SampleSize - 1; i >= 0; i--)
            {
                queue.Add(Samples[i]);
                AssertRemainingCapacity(queue, i);
            }
            queue = NewQueueFilledWithSample();
            AssertRemainingCapacity(queue, 0);
            for (int i = 1; i <= SampleSize; i++)
            {
                queue.Remove();
                AssertRemainingCapacity(queue, i);
            }
        }
示例#16
0
 private void AddRemoveOneLoop(IQueue queue, int size)
 {
     for (int i = 0; i < size; i++)
     {
         queue.Add(Samples[i]);
     }
     for (int i = 0; i < size; i++)
     {
         object o = queue.Remove();
         if (IsFifo)
         {
             Assert.That(o, Is.EqualTo(Samples[i]));
         }
         else
         {
             CollectionAssert.Contains(Samples, o);
         }
     }
 }
示例#17
0
        private void Run(object state)
        {
            try
            {
                _logger.Add($"{Name}; ThreadId={Thread.CurrentThread.ManagedThreadId} начал работу");
                var stopWatch = new Stopwatch();
                stopWatch.Start();

                Execute(_part);

                stopWatch.Stop();
                _logger.Add(
                    $"{Name}; ThreadId={Thread.CurrentThread.ManagedThreadId} закончил заботу с part {_part} за {stopWatch.ElapsedMilliseconds} ms");
                _statistic.Add(Name, stopWatch.ElapsedMilliseconds, _systemInfoProvider.PagedMemorySize64);
                _nextQueue?.Add(_part);
            }
            catch (Exception ex)
            {
                _exceptionHandler(ex);
            }
        }
        public StatusCodeResult Publish(EventPayload evnt)
        {
            _queue.Add(evnt);

            return(new StatusCodeResult(200));
        }
示例#19
0
        public void processPatients(bool usePriority)
        {
            Hospital.CurrentTime = 0;
            List <Patient> patientList = new List <Patient>();
            List <Patient> fatalities  = new List <Patient>();
            // TODO:  You'll need some counters and accumulators
            int totalPatients  = 0;
            int totalAdmited   = 0;
            int maxWaiting     = 0;
            int totalWaiting   = 0;
            int averageWaiting = 0;
            int averageStay    = 0;
            int totalStay      = 0;

            // this is for free
            if (usePriority)
            {
                waitingQueue = new PriorityQueue <Patient>();
            }
            else
            {
                waitingQueue = new SimpleQueue <Patient>();
            }

            while (Hospital.CurrentTime < numMinutes)
            {
                //Pack The Loby
                foreach (Patient current in triage.getNewPatients())
                {
                    current.setFinalOperationTime(Hospital.CurrentTime);
                    current.IntakeTime = Hospital.CurrentTime;
                    current.setFinalOperationTime(Hospital.CurrentTime);
                    waitingQueue.Add(current.TimeToLive, current);
                    totalPatients++;
                }

                //If Tables are emtpy then add people from the waiting list
                while (ERtables.Count < NUM_TABLES)
                {
                    if (waitingQueue.Count > 0)
                    {
                        Patient Current = waitingQueue.Remove();
                        Current.TimeEnteringER = Hospital.CurrentTime;
                        if (Hospital.CurrentTime <= Current.LastPossibleMoment)
                        {
                            ERtables.Add(new ERTable(Current));
                            totalStay += Current.TimeForProcedure;
                            totalAdmited++;
                        }
                        else
                        {
                            fatalities.Add(Current);
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                //Process Existing Tables
                var index = 0;
                while (index < ERtables.Count)
                {
                    ERTable current = ERtables[index];

                    Patient subject = current.Patient;
                    current.ETC = current.ETC - 1; //Because all operations are smooth and painless
                    //TODO dice rolls for operation progression and success
                    if (Hospital.CurrentTime > subject.LastPossibleMoment)
                    {
                        fatalities.Add(subject);
                        ERtables.RemoveAt(index);
                    }
                    else if (Hospital.CurrentTime == current.ETC)
                    {
                        patientList.Add(subject);
                        ERtables.RemoveAt(index); // I know but if I'm not taking them off the tables then they stay till death
                    }
                    else
                    {
                        index++;
                    }
                }

                //Counting the Highest WaitingRoom Population
                if (waitingQueue.Count > 0)
                {
                    if (waitingQueue.Count > maxWaiting)
                    {
                        maxWaiting = waitingQueue.Count;
                    }
                    totalWaiting += 1;
                }


                Hospital.CurrentTime++;
            }

            averageWaiting = maxWaiting / totalWaiting;

            averageStay = totalStay / totalAdmited;

            // print time, total patients, max waiting, average waiting, expired patients
            Console.WriteLine("time : {0}" + lr +
                              "total patients : {1}" + lr +
                              "max waiting : {2}" + lr +
                              "average waiting : {3}" + lr +
                              "expired patients: {4}" + lr +
                              "Average Stay: {5}" + lr,
                              Hospital.CurrentTime, totalPatients, maxWaiting, averageWaiting, fatalities.Count, averageStay);
        }
示例#20
0
 public void Add(Crouton crouton)
 {
     croutonQueue.Add(crouton);
     displayCrouton();
 }
 public void AddOrder(int botId, string instrument, decimal price, EnmOrderDir dir, decimal amount)
 {
     _queueTransactions.Add(new Action(() => _astsConnectionMain.AddOrder(botId, instrument, price, dir, amount)));
     //_queueTransactions.Add(botId);
 }
 public void Submit(SubmittedBankStatement bankStatement)
 {
     store.Write(bankStatement.Name, bankStatement.Content);
     queue.Add(new SubmittedBankStatementQueueItem(bankStatement));
 }
示例#23
0
 [Test] public void NonGenericAddDelegatesToGenericAdd()
 {
     _sut.Stub(x => x.Add(Arg <T> .Is.Anything));
     _sutAsNonGeneric.Add(TestData <T> .One);
     _sut.AssertWasCalled(x => x.Add(TestData <T> .One));
 }
示例#24
0
  public void BasicTest()
  {
    int[] oneToTen = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    List<int> list = new List<int>(oneToTen);

    MyCircularList<int> circ = new MyCircularList<int>(40);
    Assert.IsTrue(circ.CanGrow);
    Assert.IsFalse(circ.IsReadOnly);

    // test AddRange
    circ.AddRange(oneToTen);
    Compare(circ, oneToTen);

    // test IndexOf
    foreach(int i in oneToTen)
    {
      Assert.AreEqual(i-1, circ.IndexOf(i));
    }
    Assert.AreEqual(-1, circ.IndexOf(11));

    // test TrimExcess() -- resizing downward
    circ.TrimExcess();
    Compare(circ, list);

    // test resizing upwards (and AddRange(IEnumerable<T>))
    circ.AddRange((IEnumerable<int>)oneToTen); // small resize code path
    list.AddRange(oneToTen);
    Compare(circ, list);
    list.AddRange(oneToTen);
    circ.Clear();
    circ.Capacity = 4;
    circ.AddRange(list.ToArray()); // test the big resize code path (that goes through the while loop)
    Compare(circ, list);

    // test Insert(0, T[])
    circ.Insert(0, oneToTen, 0, oneToTen.Length);
    list.AddRange(oneToTen);
    Compare(circ, list);

    // test Insert(Count, T[])
    circ.Insert(circ.Count, oneToTen, 0, oneToTen.Length);
    list.AddRange(oneToTen);
    Compare(circ, list);

    // test RemoveFirst()
    foreach(int i in list)
    {
      Assert.AreEqual(i, circ.RemoveFirst());
    }
    Assert.AreEqual(0, circ.Count);
    list.Clear();

    // test RemoveLast()
    circ.MakeNonContiguous(oneToTen);
    for(int i=oneToTen.Length-1; i >= 0; i--)
    {
      Assert.AreEqual(oneToTen[i], circ.RemoveLast());
    }
    Assert.AreEqual(0, circ.Count);

    // test RemoveFirst(T[])
    circ.Insert(0, oneToTen, 0, oneToTen.Length);
    int[] firstFive = new int[5];
    circ.RemoveFirst(firstFive, 0, 5);
    TestHelpers.AssertArrayEquals(firstFive, 1, 2, 3, 4, 5);
    Compare(circ, 6, 7, 8, 9, 10);

    // test CopyTo
    Array.Clear(firstFive, 0, firstFive.Length);
    circ.CopyTo(firstFive, 0);
    TestHelpers.AssertArrayEquals(firstFive, 6, 7, 8, 9, 10);

    // test RemoveLast(T[])
    circ.Clear();
    circ.Insert(0, oneToTen, 0, oneToTen.Length);
    int[] lastFive = new int[5];
    circ.RemoveLast(lastFive, 0, 5);
    TestHelpers.AssertArrayEquals(lastFive, 6, 7, 8, 9, 10);
    Compare(circ, 1, 2, 3, 4, 5);

    // test RemoveRange()
    circ.RemoveRange(0, 2);
    Compare(circ, 3, 4, 5);
    circ.RemoveRange(circ.Count-2, 2);
    Compare(circ, 3);

    // test setter
    circ.Clear();
    circ.AddRange(oneToTen);
    for(int i=0; i<circ.Count; i++)
    {
      circ[i]++;
      Assert.AreEqual(oneToTen[i]+1, circ[i]);
    }

    // test Insert(int, T)
    circ.Clear();
    foreach(int i in oneToTen) circ.Insert(0, i);
    list = new List<int>(oneToTen);
    list.Reverse();
    Compare(circ, list);

    // test RemoveAt(int)
    circ.Clear();
    circ.AddRange(oneToTen);
    circ.RemoveAt(2);
    Compare(circ, 1, 2, 4, 5, 6, 7, 8, 9, 10);
    circ.RemoveAt(0);
    Compare(circ, 2, 4, 5, 6, 7, 8, 9, 10);
    circ.RemoveAt(circ.Count-1);
    Compare(circ, 2, 4, 5, 6, 7, 8, 9);

    // test Remove(T) (and thus RemoveAt(int)) with a non-contiguous block
    circ.MakeNonContiguous(oneToTen);
    Assert.IsTrue(circ.Remove(2));
    Assert.IsTrue(circ.Remove(4));
    Assert.IsTrue(circ.Remove(9));
    Assert.IsTrue(circ.Remove(7));
    Assert.IsFalse(circ.Remove(50));

    // test Add(T)
    circ.Clear();
    foreach(int i in oneToTen) circ.Add(i);
    Compare(circ, oneToTen);

    // test Contains()
    foreach(int i in oneToTen) Assert.IsTrue(circ.Contains(i));
    Assert.IsFalse(circ.Contains(11));

    // test CopyTo(int, T[])
    int[] dest = new int[8];
    circ.CopyTo(1, dest, 0, 8);
    TestHelpers.AssertArrayEquals(dest, 2, 3, 4, 5, 6, 7, 8, 9);

    // test the GetEnumerable
    list.Clear();
    foreach(int i in circ) list.Add(i);
    Compare(circ, list);

    // test IndexOf() for the non-contiguous code path
    circ.Clear();
    circ.AddRange(oneToTen, 5, 5);
    circ.Insert(0, oneToTen, 0, 5);
    Assert.AreEqual(0, circ.IndexOf(1));
    Assert.AreEqual(5, circ.IndexOf(6));
    Assert.AreEqual(9, circ.IndexOf(10));
    Assert.AreEqual(-1, circ.IndexOf(1, 1, 9));
    Assert.AreEqual(1, circ.IndexOf(2, 1, 9));
    Assert.AreEqual(-1, circ.IndexOf(10, 0, 9));

    // test wraparound case for MoveTail()
    circ = new MyCircularList<int>(10);
    circ.Insert(0, 2);
    circ.Insert(0, 1);
    Assert.AreEqual(1, circ.RemoveFirst());

    // test RemoveFirst(int) and wraparound case for MoveHead(int)
    circ.Clear();
    circ.AddRange(1, 2, 3, 4, 5);
    circ.RemoveFirst(5);
    Assert.AreEqual(0, circ.Count);
    circ.AddRange(oneToTen);
    Compare(circ, oneToTen);

    // test wraparound case for MoveTail(int)
    circ.RemoveFirst(10);
    Assert.AreEqual(0, circ.Count);

    // test AddRange(T[], int, int)
    circ.AddRange(oneToTen, 1, 9);
    Compare(circ, 2, 3, 4, 5, 6, 7, 8, 9, 10);

    // test edge case for RemoveRange()
    circ.AddRange(6, 7, 8, 9, 10);
    circ.RemoveFirst(5);
    Compare(circ, 7, 8, 9, 10, 6, 7, 8, 9, 10);
    circ.RemoveRange(2, 7);
    Compare(circ, 7, 8);

    // test CopyTo() when the list is empty
    circ.Clear();
    circ.CopyTo(firstFive, 0);

    // test IsFull and get_Capacity
    circ.Clear();
    circ.Capacity = oneToTen.Length;
    Assert.AreEqual(oneToTen.Length, circ.Capacity);
    circ.AddRange(oneToTen);
    Assert.AreEqual(0, circ.AvailableSpace);
    Assert.IsTrue(circ.IsFull);
    circ.RemoveFirst();
    Assert.AreEqual(1, circ.AvailableSpace);
    Assert.IsFalse(circ.IsFull);

    // test wraparound case for MoveHead()
    circ.Clear();
    circ.Capacity = oneToTen.Length;
    circ.AddRange(oneToTen, 0, 9);
    circ.Add(10);
    Compare(circ, oneToTen);

    // test AddRange(IEnumerable<T>) in the case where Add(T) is called
    circ.Clear();
    circ.Capacity = 15;
    circ.AddRange(oneToTen);
    circ.RemoveFirst(9);
    circ.AddRange((IEnumerable<int>)oneToTen);
    Compare(circ, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

    // test AddRange(IEnumerable<T>) in the case where MakeContiguous() is called
    list = new List<int>(oneToTen);
    list.AddRange(oneToTen);
    circ.Clear();
    circ.Capacity = 25;
    circ.AddRange(oneToTen);
    circ.RemoveFirst(9);
    circ.AddRange(list);
    Compare(circ, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

    // test Insert(T[]) in the case where the free space is fragmented
    circ.Clear();
    circ.Capacity = 10;
    circ.AddRange(oneToTen, 0, 5);
    circ.RemoveFirst(4);
    circ.Insert(1, oneToTen, 0, 9);
    Compare(circ, 5, 1, 2, 3, 4, 5, 6, 7, 8, 9);

    // test CopyTo(T[]) in the case where the data is fragmented
    circ.Clear();
    circ.AddRange(oneToTen);
    circ.RemoveFirst(8);
    circ.AddRange(oneToTen, 0, 5);
    circ.CopyTo(0, firstFive, 0, 5);
    TestHelpers.AssertArrayEquals(firstFive, 9, 10, 1, 2, 3);

    // test IQueue<T> interface
    circ.Clear();
    IQueue<int> queue = circ;
    // ... test addition
    foreach(int i in oneToTen) queue.Add(i);
    Assert.AreEqual(oneToTen.Length, queue.Count);
    // ... test peeking and removal
    foreach(int i in oneToTen)
    {
      Assert.AreEqual(i, queue.Peek());
      Assert.AreEqual(i, queue.Dequeue());
    }
    Assert.AreEqual(0, queue.Count);

    TestHelpers.TestEnumerator(queue);
  }
        [Test] public void OfferChokesOnIncompatibleDataType()
        {
            IQueue queue = NewQueue();

            Assert.Throws <InvalidCastException>(() => queue.Add(new object()));
        }
示例#26
0
        public void processPatients()
        {
            Hospital.CurrentTime = 0;
            bool           usePriority = true;
            List <Patient> patientList;
            // TODO:  You'll need some counters and accumulators
            int expiry          = 0;
            int totalPatients   = 0;
            int patients_Seen   = 0;
            int waitingPatients = 0;
            int totalWait       = 0;
            int averageWait     = 0;
            int averageERwait   = 0;

            // this is for free
            if (usePriority)
            {
                waitingQueue = new PriorityQueue <Patient>();
            }
            else
            {
                waitingQueue = new SimpleQueue <Patient>();
            }

            while (Hospital.CurrentTime < numMinutes)
            {
                int i = 0;

                while (i > ERtables.Count)
                {
                    if (ERtables[i].ETC >= Hospital.CurrentTime)
                    {
                        ERtables.RemoveAt(i);
                    }
                    else
                    {
                        i++;
                    }
                }

                patientList = triage.getNewPatients();

                foreach (Patient p in patientList)
                {
                    p.IntakeTime = Hospital.CurrentTime;
                    p.setFinalOperationTime(Hospital.CurrentTime);
                    waitingQueue.Add(p.LastPossibleMoment, p);
                    totalPatients++;
                }

                while (waitingQueue.Count > 0 && ERtables.Count <= ERtables.Capacity)
                {
                    ERTable ER = new ERTable(waitingQueue.Remove());
                    totalWait += (Hospital.CurrentTime - ER.Patient.IntakeTime);
                    if (Hospital.CurrentTime <= ER.Patient.TimeToLive)
                    {
                        expiry++;
                    }
                    else
                    {
                        ER.Patient.TimeEnteringER = Hospital.CurrentTime;
                        patients_Seen++;
                        ERtables.Add(ER);

                        averageERwait += ER.ETC;
                    }
                }


                // TODO:  your code goes here
                Hospital.CurrentTime += 10;
                waitingPatients       = waitingQueue.Count;
            }
            //waitingPatients = waitingQueue.Count;
            averageWait   = totalWait / totalPatients;
            averageERwait = averageERwait / patients_Seen;
            Console.Write("Simulation run time: {0}\n", numMinutes);
            Console.Write("Total patients entering hospital: {0}\n", totalPatients);
            Console.Write("Patients served: {0}\n", patients_Seen);
            Console.Write("Patients that expired: {0}\n", expiry);
            Console.Write("Patients waiting at end of cycle: {0}\n", waitingPatients);
            Console.Write("Average wait time: {0}\n", averageWait);
            Console.Write("Average ER wait: {0}", averageERwait);
            // print time, total patients, max waiting, average waiting, expired patients
        }