public void Setup()
 {
     Dictionary.Add(1, "Phil");
     Dictionary.Add(12, "Phillip");
     Dictionary.Add(34, "Frank");
     Dictionary.Add(54, "Bobby");
 }
        public void TrimExcess_NoArgument_TrimAfterEachBulkAddOrRemove_TrimsToAtLeastCount(int initialCount, int numRemove, int numAdd, int newCount, int newCapacity)
        {
            Random random     = new Random(32);
            var    dictionary = new LinkedDictionary <int, int>();

            dictionary.TrimExcess();
            Assert.InRange(dictionary.EnsureCapacity(0), dictionary.Count, int.MaxValue);

            var initialKeys = new int[initialCount];

            for (int i = 0; i < initialCount; i++)
            {
                initialKeys[i] = i;
            }
            random.Shuffle(initialKeys);
            foreach (var key in initialKeys)
            {
                dictionary.Add(key, 0);
            }
            dictionary.TrimExcess();
            Assert.InRange(dictionary.EnsureCapacity(0), dictionary.Count, int.MaxValue);

            random.Shuffle(initialKeys);
            for (int i = 0; i < numRemove; i++)
            {
                dictionary.Remove(initialKeys[i]);
            }
            dictionary.TrimExcess();
            Assert.InRange(dictionary.EnsureCapacity(0), dictionary.Count, int.MaxValue);

            var moreKeys = new int[numAdd];

            for (int i = 0; i < numAdd; i++)
            {
                moreKeys[i] = i + initialCount;
            }
            random.Shuffle(moreKeys);
            foreach (var key in moreKeys)
            {
                dictionary.Add(key, 0);
            }
            int currentCount = dictionary.Count;

            dictionary.TrimExcess();
            Assert.InRange(dictionary.EnsureCapacity(0), currentCount, int.MaxValue);

            int[] existingKeys = new int[currentCount];
            Array.Copy(initialKeys, numRemove, existingKeys, 0, initialCount - numRemove);
            Array.Copy(moreKeys, 0, existingKeys, initialCount - numRemove, numAdd);
            random.Shuffle(existingKeys);
            for (int i = 0; i < currentCount - newCount; i++)
            {
                dictionary.Remove(existingKeys[i]);
            }
            dictionary.TrimExcess();
            int finalCapacity = dictionary.EnsureCapacity(0);

            Assert.InRange(finalCapacity, newCount, initialCount);
            Assert.Equal(newCapacity, finalCapacity);
        }
        public void TrimExcess_DictionaryHasElementsChainedWithSameHashcode_Success()
        {
            var dictionary = new LinkedDictionary <string, int>(7);

            for (int i = 0; i < 4; i++)
            {
                dictionary.Add(i.ToString(), 0);
            }
            var s_64bit = new string[] { "95e85f8e-67a3-4367-974f-dd24d8bb2ca2", "eb3d6fe9-de64-43a9-8f58-bddea727b1ca" };
            var s_32bit = new string[] { "25b1f130-7517-48e3-96b0-9da44e8bfe0e", "ba5a3625-bc38-4bf1-a707-a3cfe2158bae" };

            string[] chained = (Environment.Is64BitProcess ? s_64bit : s_32bit).ToArray();
            dictionary.Add(chained[0], 0);
            dictionary.Add(chained[1], 0);
            for (int i = 0; i < 4; i++)
            {
                dictionary.Remove(i.ToString());
            }
            dictionary.TrimExcess(3);
            Assert.Equal(2, dictionary.Count);
            int val;

            Assert.True(dictionary.TryGetValue(chained[0], out val));
            Assert.True(dictionary.TryGetValue(chained[1], out val));
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Linked dictionary:");

            var dictionary = new LinkedDictionary <int, string>();

            dictionary.Add(1, "One");
            dictionary.Add(2, "Two");
            dictionary.Add(3, "Three");
            dictionary.Add(101, "One hundred one");

            foreach (var item in dictionary)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("\nRemove 1, 101, 5: ");
            dictionary.Remove(1);
            dictionary.Remove(101);
            dictionary.Remove(5);

            foreach (var item in dictionary)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine($"\nSearch 2: {dictionary.Search(2)}");
        }
Ejemplo n.º 5
0
        public static void TestRemove()
        {
            LinkedDictionary <string, int> linked = new LinkedDictionary <string, int>();

            linked.Add("a", 1);
            linked.Add("b", 2);
            Assert.AreEqual(linked.Count, 2);
            Assert.AreEqual(linked["a"], 1);
            Assert.AreEqual(linked["b"], 2);
            Assert.IsTrue(linked.ContainsKey("a"));
            Assert.IsTrue(linked.ContainsKey("b"));

            Assert.IsTrue(linked.Remove("a"));
            Assert.IsFalse(linked.Remove("c"));

            Assert.AreEqual(linked.Count, 1);
            Assert.IsFalse(linked.ContainsKey("a"));
            Assert.IsTrue(linked.ContainsKey("b"));
            Assert.AreEqual(linked["b"], 2);

            Assert.IsFalse(linked.Remove("a"));
            Assert.IsTrue(linked.Remove("b"));
            Assert.AreEqual(linked.Count, 0);
            Assert.IsFalse(linked.ContainsKey("b"));
        }
 public void Setup()
 {
     LDictionary.Add(5, "Bill");
     LDictionary.Add(6, "Phil");
     LDictionary.Add(7, "Frank");
     LDictionary.Add(9, "Bobby");
     Iterator = LDictionary.ValueIterator;
 }
Ejemplo n.º 7
0
        public static void TestAdd()
        {
            LinkedDictionary <int, int> linked = new LinkedDictionary <int, int>();

            linked.Add(1, 1);
            Assert.AreEqual(linked.Count, 1);
            Assert.AreEqual(linked[1], 1);

            linked.Add(2, 2);
            Assert.AreEqual(linked.Count, 2);
            Assert.AreEqual(linked[1], 1);
            Assert.AreEqual(linked[2], 2);
        }
Ejemplo n.º 8
0
        //Return Index As Dictionary<Term,IndexEntry>
        public LinkedDictionary <String, IndexEntry> ReadData()
        {
            LinkedDictionary <String, IndexEntry> result = new LinkedDictionary <String, IndexEntry>();

            result.OverrideValues = true;
            Int32 i = 1;

            while (i < 101)
            {
                String        path = _s + "\\ltext" + i + ".txt";
                List <String> ie   = __LoadData(path);//Get all terms from file_i


                Counter <String>           c      = new Counter <String>(ie);
                Int32                      count  = ie.Count;            //count of words.
                List <(String e, Int32 c)> tuples = c.MostCommon(count); //count frequencies of all terms

                IndexEntry entry;
                foreach (var tuple in tuples)
                {
                    if (result.TryGetValue(tuple.e, out entry))
                    {
                        entry.TCount += tuple.c;
                        entry.Freqs.Add(tuple.c);                                            //AddLast(new LinkedListNode<Int32>(tuple.c));
                        entry.Ids.Add(i);                                                    //AddLast(new LinkedListNode<Int32>(i));
                        entry.Probs.Add(tuple.c / (double)count);                            //TF
                        len[i - 1] += (tuple.c / (double)count) * (tuple.c / (double)count); //OR Math.Pow(tuple.c/(double)count,2d);
                        result.Add(tuple.e, entry);
                    }
                    else
                    {
                        IndexEntry ne = new IndexEntry();
                        ne.Ids.Add(i);                                                       //AddLast(new LinkedListNode<Int32>(i));
                        ne.Freqs.Add(tuple.c);                                               //AddLast(new LinkedListNode<Int32>(tuple.c));
                        ne.TCount += tuple.c;
                        ne.Probs.Add(tuple.c / (double)count);                               //TF
                        len[i - 1] += (tuple.c / (double)count) * (tuple.c / (double)count); //OR Math.Pow(tuple.c/(double)count,2d);
                        result.Add(tuple.e, ne);
                    }
                }
                i++;
            }
            //FULL LENGTH OF THE VECTORS OF TERMS WHERE VECTOR IS A DOCUMENT D(t1,t2...tn)

            for (Int32 k = 0; k < 100; k++)
            {
                len[k] = Math.Sqrt(len[k]);
            }
            return(result);
        }
Ejemplo n.º 9
0
            public void Add(string key, string value)
            {
                string    dataKey = Attributes.DataKey(key);
                Attribute attr    = new Attribute(dataKey, value);

                enclosingAttributes.Add(dataKey, attr);
            }
Ejemplo n.º 10
0
        public void AddVisibleColumn(IDetector detector, IColumnInfo visibleColumn)
        {
            if (detector == null)
            {
                throw new ArgumentNullException("detector");
            }
            if (visibleColumn == null)
            {
                throw new ArgumentNullException("visibleColumn");
            }

            List <IColumnInfo> visibleColumns;

            if (_visibleColumns.TryGetValue(detector, out visibleColumns))
            {
                visibleColumns.Add(visibleColumn);
            }
            else
            {
                visibleColumns = new List <IColumnInfo>();
                visibleColumns.Add(visibleColumn);
                _visibleColumns.Add(detector, visibleColumns);
            }
            UpdateProject(ProjectChangedType.VisibleColumnsChanged, detector);
        }
 public void IDictionary_NonGeneric_Add_KeyOfWrongType()
 {
     if (!IsReadOnly)
     {
         IDictionary dictionary = new LinkedDictionary <string, string>();
         object      missingKey = 23;
         AssertExtensions.Throws <ArgumentException>("key", () => dictionary.Add(missingKey, CreateTValue(12345)));
         Assert.Empty(dictionary);
     }
 }
 public void IDictionary_NonGeneric_Add_NullValueWhenDefaultTValueIsNonNull()
 {
     if (!IsReadOnly)
     {
         IDictionary dictionary = new LinkedDictionary <string, int>();
         object      missingKey = GetNewKey(dictionary);
         Assert.Throws <ArgumentNullException>(() => dictionary.Add(missingKey, null));
         Assert.Empty(dictionary);
     }
 }
 public void IDictionary_NonGeneric_Add_ValueOfWrongType()
 {
     if (!IsReadOnly)
     {
         IDictionary dictionary = new LinkedDictionary <string, string>();
         object      missingKey = GetNewKey(dictionary);
         AssertExtensions.Throws <ArgumentException>("value", () => dictionary.Add(missingKey, 324));
         Assert.Empty(dictionary);
     }
 }
Ejemplo n.º 14
0
        private IDictionary <string, IndexMetaData> CreateIndexes(ICollection <IndexMetaData> indexMetaDataList)
        {
            IDictionary <string, IndexMetaData> result = new LinkedDictionary <string, IndexMetaData>();

            foreach (var indexMetaData in indexMetaDataList)
            {
                result.Add(indexMetaData.Name.ToLower(), indexMetaData);
            }

            return(result);
        }
Ejemplo n.º 15
0
        protected override ICollection NonGenericICollectionFactory(int count)
        {
            LinkedDictionary <string, string> list = new LinkedDictionary <string, string>();
            int seed = 13453;

            for (int i = 0; i < count; i++)
            {
                list.Add(CreateT(seed++), CreateT(seed++));
            }
            return((ICollection)list.Keys);
        }
Ejemplo n.º 16
0
        public void LinkedDictionary_Generic_KeyCollection_GetEnumerator(int count)
        {
            LinkedDictionary <string, string> dictionary = new LinkedDictionary <string, string>();
            int seed = 13453;

            while (dictionary.Count < count)
            {
                dictionary.Add(CreateT(seed++), CreateT(seed++));
            }
            dictionary.Keys.GetEnumerator();
        }
        public void TrimExcess_NoArguments_TrimsToAtLeastCount(int count)
        {
            var dictionary = new LinkedDictionary <int, int>(20);

            for (int i = 0; i < count; i++)
            {
                dictionary.Add(i, 0);
            }
            dictionary.TrimExcess();
            Assert.InRange(dictionary.EnsureCapacity(0), count, int.MaxValue);
        }
Ejemplo n.º 18
0
        public static void TestLastKey()
        {
            LinkedDictionary <int, bool> linked = new LinkedDictionary <int, bool>();

            linked.Add(1, false);
            Assert.AreEqual(linked.LastKey, 1);
            linked.Add(2, true);
            Assert.AreEqual(linked.LastKey, 2);
            linked.Remove(1);
            Assert.AreEqual(linked.LastKey, 2);
            linked.AddFirst(3, false);
            Assert.AreEqual(linked.LastKey, 2);
            linked.Add(4, true);
            Assert.AreEqual(linked.LastKey, 4);
            linked.Remove(3);
            Assert.AreEqual(linked.LastKey, 4);
            linked.Remove(4);
            Assert.AreEqual(linked.LastKey, 2);
            linked.Remove(2);
        }
Ejemplo n.º 19
0
        public static void TestFirstKey()
        {
            LinkedDictionary <int, char> linked = new LinkedDictionary <int, char>();

            linked.Add(1, 'a');
            Assert.AreEqual(linked.FirstKey, 1);
            linked.Add(2, 'b');
            Assert.AreEqual(linked.FirstKey, 1);
            linked.Remove(1);
            Assert.AreEqual(linked.FirstKey, 2);
            linked.AddFirst(3, 'c');
            Assert.AreEqual(linked.FirstKey, 3);
            linked.Add(4, 'd');
            Assert.AreEqual(linked.FirstKey, 3);
            linked.Remove(3);
            Assert.AreEqual(linked.FirstKey, 2);
            linked.Remove(2);
            Assert.AreEqual(linked.FirstKey, 4);
            linked.Remove(4);
        }
Ejemplo n.º 20
0
        public static void TestContains()
        {
            LinkedDictionary <int, string> linked = new LinkedDictionary <int, string>();

            linked.Add(1, "a");
            Assert.AreEqual(linked.Count, 1);
            Assert.AreEqual(linked[1], "a");
            Assert.IsTrue(linked.ContainsKey(1));
            Assert.IsFalse(linked.ContainsKey(0));
            Assert.IsFalse(linked.ContainsKey(2));
        }
        public void TrimExcess_Generic_CapacitySmallerThanCount_Throws(int suggestedCapacity)
        {
            var dictionary = new LinkedDictionary <TKey, TValue>();

            dictionary.Add(GetNewKey(dictionary), CreateTValue(0));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("capacity", () => dictionary.TrimExcess(0));

            dictionary = new LinkedDictionary <TKey, TValue>(suggestedCapacity);
            dictionary.Add(GetNewKey(dictionary), CreateTValue(0));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("capacity", () => dictionary.TrimExcess(0));
        }
Ejemplo n.º 22
0
        static void Main(string[] args)
        {
            LinkedDictionary <String, ICommand> cmds    = new LinkedDictionary <String, ICommand>();
            IHandler <String, String[]>         handler = new StringHandler();

            CurrentDirectory dir = new CurrentDirectory()
            {
                CPath = System.IO.Directory.GetCurrentDirectory()
            };

            cmds.Add("change", new ChangeCommand(dir));
            cmds.Add("mkfile", new MkFileCommand(dir));
            cmds.Add("show", new ShowCommand(dir));
            cmds.Add("mkdir", new MkDirCommand(dir));
            cmds.Add("copy", new CopyCommand(dir));
            cmds.Add("s", new ShowCommand(dir));
            cmds.Add("help", new HelpCommand(GetCmds(cmds.Values)));


            Console.WriteLine("===Welcome to the ConsoleCommander===\nTo see available commands type help\n");
            while (true)
            {
                String c = Console.ReadLine();

                String[] A   = handler.Handle(c);//c.Split(new Char[]{'-',' ','='},StringSplitOptions.RemoveEmptyEntries);
                ICommand cmd = cmds[A[0]];
                if (A[0] == "change")
                {
                    cmd.Execute(GetArgs <String>(A));
                }
                else if (A[0] == "mkfile")
                {
                    cmd.Execute(GetArgs <String>(A));
                }
                else if (A[0] == "mkdir")
                {
                    cmd.Execute(GetArgs <String>(A));
                }
                else if (A[0] == "show" || A[0] == "s")
                {
                    cmd.Execute(null);
                }
                else if (A[0] == "copy")
                {
                    cmd.Execute(GetArgs <String>(A));
                }
                else if (A[0] == "help")
                {
                    cmd.Execute(GetArgs <String>(A));
                }
                else
                {
                    break;
                }
            }
        }
Ejemplo n.º 23
0
        public void AddCallback(AssetAsyncLoad asyncLoad, UnityAction <Object> loaded, UnityAction <float> progress)
        {
            if (loaded != null)
            {
                m_LoadedCallbackList.Add(asyncLoad, loaded);
            }

            if (progress != null)
            {
                m_ProgressCallbackList.Add(asyncLoad, progress);
            }
        }
Ejemplo n.º 24
0
        public static void TestUpdate()
        {
            LinkedDictionary <string, string> linked = new LinkedDictionary <string, string>();

            linked.Add("a", "a");
            Assert.AreEqual(linked.Count, 1);
            Assert.AreEqual(linked["a"], "a");

            linked["a"] = "b";
            Assert.AreEqual(linked.Count, 1);
            Assert.AreEqual(linked["a"], "b");
        }
        public void TryAdd_ItemAlreadyExists_DoesNotInvalidateEnumerator()
        {
            var dictionary = new LinkedDictionary <string, string>();

            dictionary.Add("a", "b");

            IEnumerator valuesEnum = dictionary.GetEnumerator();

            Assert.False(dictionary.TryAdd("a", "c"));

            Assert.True(valuesEnum.MoveNext());
        }
        public void LinkedDictionary_Generic_ContainsValue_Present(int count)
        {
            LinkedDictionary <TKey, TValue> dictionary = (LinkedDictionary <TKey, TValue>)GenericIDictionaryFactory(count);
            int seed = 4315;

            SCG.KeyValuePair <TKey, TValue> notPresent = CreateT(seed++);
            while (dictionary.Contains(notPresent))
            {
                notPresent = CreateT(seed++);
            }
            dictionary.Add(notPresent.Key, notPresent.Value);
            Assert.True(dictionary.ContainsValue(notPresent.Value));
        }
Ejemplo n.º 27
0
            public void GetEnumerator_ArbitarilyOrderedDictionary_KeysRetainOrderAfterMutation()
            {
                List <string> values = new List <string>()
                {
                    "a", "c", "q", "f", "t", "s", "v", "x", "z", "y"
                };
                var linkedDictionary = new LinkedDictionary <string, string>();

                foreach (string value in values)
                {
                    linkedDictionary.Add(value, value);
                }

                values.Remove("f");
                linkedDictionary.Remove("f");
                values.Add("r");
                linkedDictionary.Add("r", "r");

                List <string> actual = linkedDictionary.Values.ToList();

                Assert.Equal <string>(values, actual);
            }
        public void LinkedDictionary_Generic_RemoveKey_ValidKeyContainedInDictionary(int count)
        {
            LinkedDictionary <TKey, TValue> dictionary = (LinkedDictionary <TKey, TValue>)GenericIDictionaryFactory(count);
            TKey   missingKey = GetNewKey(dictionary);
            TValue outValue;
            TValue inValue = CreateTValue(count);

            dictionary.Add(missingKey, inValue);
            Assert.True(dictionary.Remove(missingKey, out outValue));
            Assert.Equal(count, dictionary.Count);
            Assert.Equal(inValue, outValue);
            Assert.False(dictionary.TryGetValue(missingKey, out outValue));
        }
        public void LinkedDictionary_Generic_ContainsValue_DefaultValuePresent(int count)
        {
            LinkedDictionary <TKey, TValue> dictionary = (LinkedDictionary <TKey, TValue>)GenericIDictionaryFactory(count);
            int  seed       = 4315;
            TKey notPresent = CreateTKey(seed++);

            while (dictionary.ContainsKey(notPresent))
            {
                notPresent = CreateTKey(seed++);
            }
            dictionary.Add(notPresent, default(TValue));
            Assert.True(dictionary.ContainsValue(default(TValue)));
        }
Ejemplo n.º 30
0
            public void GetEnumerator_ArbitarilyOrderedDictionary_KeysRetainOrderAfterMutation()
            {
                List <string> keys = new List <string>()
                {
                    "a", "c", "q", "f", "t", "s", "v", "x", "z", "y"
                };
                var linkedDictionary = new LinkedDictionary <string, int>();

                foreach (string key in keys)
                {
                    linkedDictionary.Add(key, key.GetHashCode());
                }

                keys.Remove("f");
                linkedDictionary.Remove("f");
                keys.Add("r");
                linkedDictionary.Add("r", "r".GetHashCode());

                List <string> actual = linkedDictionary.Keys.ToList();

                Assert.Equal <string>(keys, actual);
            }