private static void Fill(PrioritizedList <object> list, int startPriority, int endPriority)
 {
     for (var priority = startPriority; priority <= endPriority; priority++)
     {
         list.Add(new object(), priority);
     }
 }
        public void Add_ItemIsAdded()
        {
            var item = new object();
            var list = new PrioritizedList <object>();

            list.Add(item);

            Assert.IsTrue(list.Contains(item));
        }
        public void Add_Descending_SamePriority_IsAddedAfterOthers()
        {
            var item = new object();
            var list = new PrioritizedList <object>(ListSortDirection.Descending);

            Fill(list, -5, 5);
            list.Add(item, list[3].Priority);

            Assert.AreSame(item, list[4].Item);
        }
        public void Add_Descending_HighestPriority_IsAddedFirst()
        {
            var item = new object();
            var list = new PrioritizedList <object>(ListSortDirection.Descending);

            Fill(list, -5, 5);
            list.Add(item, 100);

            Assert.AreSame(item, list[0].Item);
        }
        public void Add_Descending_LowestPriority_IsAddedLast()
        {
            var item = new object();
            var list = new PrioritizedList <object>(ListSortDirection.Descending);

            Fill(list, -5, 5);
            list.Add(item, -100);

            Assert.AreSame(item, list[list.Count - 1].Item);
        }
        public void IndexOf_FindsItem()
        {
            var item = new object();
            var list = new PrioritizedList <object>();

            Fill(list, -5, 5);
            list.Add(item, list[4].Priority);

            var index = list.IndexOf(item);

            Assert.AreEqual(5, index);
        }
        public static void RegisterTypeVisualizer(string rosMessageName, IVisualFactory visualFactory, int priority = 0, MessageSubtopic subtopic = MessageSubtopic.Default)
        {
            Dictionary <string, PrioritizedList <IVisualFactory> > factoriesTable = (subtopic != MessageSubtopic.Response) ? s_TypeVisualFactories : s_TypeResponseVisualFactories;
            PrioritizedList <IVisualFactory> currentEntry;

            if (!factoriesTable.TryGetValue(rosMessageName, out currentEntry))
            {
                currentEntry = new PrioritizedList <IVisualFactory>();
                currentEntry.Add(s_DefaultVisualFactory, int.MinValue);
                factoriesTable[rosMessageName] = currentEntry;
            }
            currentEntry.Add(visualFactory, priority);
        }