public static void CopyTo_FilledHashTable_ReturnsSuccessful()
        {
            var studentsMarks = new ChainedHashTable <string, int>();

            studentsMarks.Add("Name1", 1);
            studentsMarks.Add("Name2", 5);
            studentsMarks.Add(new KeyValuePair <string, int>("Name3", 3));

            var array = new KeyValuePair <string, int> [studentsMarks.Count];

            studentsMarks.CopyTo(array, 0);

            Assert.True(studentsMarks.Count == 3);
            Assert.True(array.Length == 3);
            var arrayKeys = array.Select(x => x.Key).OrderBy(x => x).ToArray();

            Assert.Equal("Name1", arrayKeys[0]);
            Assert.Equal("Name2", arrayKeys[1]);
            Assert.Equal("Name3", arrayKeys[2]);
            var arrayValues = array.Select(x => x.Value).OrderBy(x => x).ToArray();

            Assert.Equal(1, arrayValues[0]);
            Assert.Equal(3, arrayValues[1]);
            Assert.Equal(5, arrayValues[2]);
        }
        public static void GetElement_ExistingElement_ReturnsElement()
        {
            var studentsMarks = new ChainedHashTable <string, int>();

            studentsMarks.Add("Name1", 1);
            studentsMarks.Add("Name2", 5);

            var value = studentsMarks["Name2"];

            Assert.Equal(5, value);
            Assert.True(studentsMarks.Count == 2);
        }
        public void Test_Add_LinearShift(int personCount)
        {
            TestFabrics.Init(personCount, ht);
            Person p = new Person(4, "Kasya2", "Babkin", 44);

            ht.Add(p);
            int  expectedPos = p.GetHashCode() % ht.Capacity;
            int  actualPos   = ht.GetPosition(p);
            bool res         = p.Equals(ht.Get(p));

            Assert.AreEqual(expectedPos, actualPos);
            Assert.IsTrue(res);
        }
        public static void GetElement_NonExistingElement_ReturnsException()
        {
            var studentsMarks = new ChainedHashTable <string, int>();

            studentsMarks.Add("Name1", 1);
            studentsMarks.Add("Name2", 5);

            int    value;
            Action act = () => value = studentsMarks["Name3"];

            Assert.Throws <KeyNotFoundException>(act);
            Assert.True(studentsMarks.Count == 2);
        }
        public static void Adding_TwoDuplicateElements_ReturnsException()
        {
            var studentsMarks = new ChainedHashTable <string, int>();

            studentsMarks.Add("Name1", 1);
            studentsMarks.Add("Name2", 5);

            Action act = () => studentsMarks.Add("Name2", 7);

            var exception = Assert.Throws <ArgumentException>(act);

            Assert.Equal("Key already exists in the hash table.", exception.Message);
            Assert.True(studentsMarks.Count == 2);
        }
        public static void RemovingAllElement_ThreeDifferentElements_ReturnsSuccessful()
        {
            var studentsMarks = new ChainedHashTable <string, int>();

            studentsMarks.Add("Name1", 1);
            studentsMarks.Add("Name2", 5);
            studentsMarks.Add(new KeyValuePair <string, int>("Name3", 3));

            studentsMarks.Remove("Name2");
            studentsMarks.Remove("Name1");
            studentsMarks.Remove("Name3");

            Assert.True(studentsMarks.Count == 0);
        }
        public static void CopyTo_EmptyHashTable_ReturnsSuccessful()
        {
            var studentsMarks = new ChainedHashTable <string, int>();

            studentsMarks.Add("Name1", 1);
            studentsMarks.Add("Name2", 5);
            studentsMarks.Add(new KeyValuePair <string, int>("Name3", 3));

            studentsMarks.Remove("Name2");
            studentsMarks.Remove("Name1");
            studentsMarks.Remove("Name3");

            Assert.True(studentsMarks.Count == 0);
            var array = new KeyValuePair <string, int> [studentsMarks.Count];

            studentsMarks.CopyTo(array, 0);
        }
        public static void Adding_ThreeDifferentElements_ReturnsSuccessful()
        {
            var studentsMarks = new ChainedHashTable <string, int>();

            studentsMarks.Add("Name1", 1);
            studentsMarks.Add("Name2", 5);
            studentsMarks.Add(new KeyValuePair <string, int>("Name3", 3));

            var mark = studentsMarks["Name1"];

            Assert.True(mark == 1);

            mark = studentsMarks["Name2"];
            Assert.True(mark == 5);

            mark = studentsMarks["Name3"];
            Assert.True(mark == 3);

            Assert.True(studentsMarks.Count == 3);
        }
Exemple #9
0
 public void AddMovie(Movie movie)
 {
     if (graphs.ContainsKey(movie.Category))
     {
         var graph   = graphs[movie.Category];
         var newNode = movie.GetNode();
         graph.AddVertex(newNode);
         var nodes = graph.BreadthFirstWalk();
         foreach (var node in nodes)
         {
             var resultingTags = newNode.Tags.Intersect(node.Tags);
             if (resultingTags.Count() > 0)
             {
                 graph.AddEdge(newNode, node);
             }
         }
     }
     else
     {
         var graph = new UndirectedSparseGraph <MovieNode>();
         graph.AddVertex(movie.GetNode());
         graphs.Add(movie.Category, graph);
     }
 }
Exemple #10
0
        public static void DoTest()
        {
            var studentsMarks = new ChainedHashTable <string, int>();

            //
            // TEST ADD KEY-VALUE PAIRS
            studentsMarks.Add("Konstantinos", 124);
            studentsMarks.Add("Bic", 224);
            studentsMarks.Add("Z", 324);
            studentsMarks.Add("Ioanna", 424);
            studentsMarks.Add("Mark Zuckerberg", 524);
            studentsMarks.Add("Semsem", 624);
            studentsMarks.Add("Sa3eeed", 724);
            studentsMarks.Add("Sameer", 824);
            studentsMarks.Add("Ahmad", 924);
            studentsMarks.Add("Zeyad", 999);
            studentsMarks.Add("Mahmoood 3eed", 111);
            studentsMarks.Add("Mahmoood Abu 3eed", 222);
            studentsMarks.Add("EISA", 333);
            studentsMarks.Add("Test1", 3210);
            studentsMarks.Add("Test11", 3210);
            studentsMarks.Add("Test222", 3210);
            studentsMarks.Add("Test3333", 3210);
            studentsMarks.Add("Test44444", 3210);
            studentsMarks.Add("Test555555", 3210);
            studentsMarks.Add("Test6666666", 3210);
            studentsMarks.Add("Test77777777", 3210);
            studentsMarks.Add("Test888888888", 3210);

            //
            // TEST FETCH KEY-VALUE
            var mark = studentsMarks["Ahmad"];

            Assert.True(mark == 924);

            mark = studentsMarks["Konstantinos"];
            Assert.True(mark == 124);

            mark = studentsMarks["Bic"];
            Assert.True(mark == 224);

            mark = studentsMarks["Z"];
            Assert.True(mark == 324);

            mark = studentsMarks["Ioanna"];
            Assert.True(mark == 424);

            mark = studentsMarks["Mark Zuckerberg"];
            Assert.True(mark == 524);

            mark = studentsMarks["Semsem"];
            Assert.True(mark == 624);

            mark = studentsMarks["Sa3eeed"];
            Assert.True(mark == 724);

            mark = studentsMarks["Sameer"];
            Assert.True(mark == 824);

            mark = studentsMarks["Zeyad"];
            Assert.True(mark == 999);

            mark = studentsMarks["Mahmoood 3eed"];
            Assert.True(mark == 111);

            mark = studentsMarks["Mahmoood Abu 3eed"];
            Assert.True(mark == 222);

            mark = studentsMarks["EISA"];
            Assert.True(mark == 333);

            //
            // TEST DELETE BY KEYS
            studentsMarks.Remove("Ahmad");
            studentsMarks.Remove("Zeyad");
            studentsMarks.Remove("Bic");
            studentsMarks.Remove("Konstantinos");
            studentsMarks.Remove("Sameer");
            studentsMarks.Remove("Z");
            studentsMarks.Remove("Ioanna");
            studentsMarks.Remove("Mark Zuckerberg");
            studentsMarks.Remove("Semsem");
            studentsMarks.Remove("Sa3eeed");
            studentsMarks.Remove("Test1");
            studentsMarks.Remove("Test11");
            studentsMarks.Remove("Test222");
            studentsMarks.Remove("Test3333");
            studentsMarks.Remove("Test44444");
            studentsMarks.Remove("Test555555");
            studentsMarks.Remove("Test6666666");
            studentsMarks.Remove("Test77777777");
            studentsMarks.Remove("Test888888888");

            Assert.True(studentsMarks.Count == 3);

            KeyValuePair <string, int>[] array = new KeyValuePair <string, int> [studentsMarks.Count];
            studentsMarks.CopyTo(array, 0);

            Assert.True(array.Length == studentsMarks.Count);
        }
        public static void DoTest()
        {
            var studentsMarks = new ChainedHashTable<string, int>();

            //
            // TEST ADD KEY-VALUE PAIRS
            studentsMarks.Add("Konstantinos", 124);
            studentsMarks.Add("Bic", 224);
            studentsMarks.Add("Z", 324);
            studentsMarks.Add("Ioanna", 424);
            studentsMarks.Add("Mark Zuckerberg", 524);
            studentsMarks.Add("Semsem", 624);
            studentsMarks.Add("Sa3eeed", 724);
            studentsMarks.Add("Sameer", 824);
            studentsMarks.Add("Ahmad", 924);
            studentsMarks.Add("Zeyad", 999);
            studentsMarks.Add("Mahmoood 3eed", 111);
            studentsMarks.Add("Mahmoood Abu 3eed", 222);
            studentsMarks.Add("EISA", 333);
            studentsMarks.Add("Test1", 3210);
            studentsMarks.Add("Test11", 3210);
            studentsMarks.Add("Test222", 3210);
            studentsMarks.Add("Test3333", 3210);
            studentsMarks.Add("Test44444", 3210);
            studentsMarks.Add("Test555555", 3210);
            studentsMarks.Add("Test6666666", 3210);
            studentsMarks.Add("Test77777777", 3210);
            studentsMarks.Add("Test888888888", 3210);

            //
            // TEST FETCH KEY-VALUE
            var mark = studentsMarks["Ahmad"];
            Debug.Assert(mark == 924);

            mark = studentsMarks["Konstantinos"];
            Debug.Assert(mark == 124);

            mark = studentsMarks["Bic"];
            Debug.Assert(mark == 224);

            mark = studentsMarks["Z"];
            Debug.Assert(mark == 324);

            mark = studentsMarks["Ioanna"];
            Debug.Assert(mark == 424);

            mark = studentsMarks["Mark Zuckerberg"];
            Debug.Assert(mark == 524);

            mark = studentsMarks["Semsem"];
            Debug.Assert(mark == 624);

            mark = studentsMarks["Sa3eeed"];
            Debug.Assert(mark == 724);

            mark = studentsMarks["Sameer"];
            Debug.Assert(mark == 824);

            mark = studentsMarks["Zeyad"];
            Debug.Assert(mark == 999);

            mark = studentsMarks["Mahmoood 3eed"];
            Debug.Assert(mark == 111);

            mark = studentsMarks["Mahmoood Abu 3eed"];
            Debug.Assert(mark == 222);

            mark = studentsMarks["EISA"];
            Debug.Assert(mark == 333);

            //
            // TEST DELETE BY KEYS
            studentsMarks.Remove("Ahmad");
            studentsMarks.Remove("Zeyad");
            studentsMarks.Remove("Bic");
            studentsMarks.Remove("Konstantinos");
            studentsMarks.Remove("Sameer");
            studentsMarks.Remove("Z");
            studentsMarks.Remove("Ioanna");
            studentsMarks.Remove("Mark Zuckerberg");
            studentsMarks.Remove("Semsem");
            studentsMarks.Remove("Sa3eeed");
            studentsMarks.Remove("Test1");
            studentsMarks.Remove("Test11");
            studentsMarks.Remove("Test222");
            studentsMarks.Remove("Test3333");
            studentsMarks.Remove("Test44444");
            studentsMarks.Remove("Test555555");
            studentsMarks.Remove("Test6666666");
            studentsMarks.Remove("Test77777777");
            studentsMarks.Remove("Test888888888");

            Debug.Assert(studentsMarks.Count == 3);

            KeyValuePair<string, int>[] array = new KeyValuePair<string, int>[studentsMarks.Count];
            studentsMarks.CopyTo(array, 0);

            Debug.Assert(array.Length == studentsMarks.Count);
        }