public void AddMethodShouldAddAnElementIfItDoesNotExistInTheSet()
        {
            var testSet = new CustomHashSet<int>();
            testSet.Add(3);

            Assert.IsTrue(testSet.Contains(3));
        }
        public void AddMethodShouldReturnTrueIfTheElementIsAdded()
        {
            var testSet = new CustomHashSet<int>();
            var isAdded = testSet.Add(3);

            Assert.IsTrue(isAdded);
        }
Beispiel #3
0
        public void AddMethodShouldReturnTrueIfTheElementIsAdded()
        {
            var testSet = new CustomHashSet <int>();
            var isAdded = testSet.Add(3);

            Assert.IsTrue(isAdded);
        }
        public void FindShouldReturnProperValue()
        {
            var testSet = new CustomHashSet<int> { 1, 2, 3 };
            var number = testSet.Find(2);

            Assert.AreEqual(2, number);
        }
 public void RemoveShouldReturnTrueWhenValueIsFoundAndRemoved()
 {
     var testSet = new CustomHashSet<int> { 1, 2, 3 };
     bool isRemoved = testSet.Remove(2);
     Assert.AreEqual(2, testSet.Count);
     Assert.IsTrue(isRemoved);
 }
Beispiel #6
0
 public void SetUp()
 {
     hashset = new CustomHashSet <int>()
     {
         10, 20, 30, 40, 50, 60
     };
 }
Beispiel #7
0
        public void TestIfIntersectWokscorrectly()
        {
            var firstList = new List <string>()
            {
                "alabala",
                "gruhgruh",
                "tintirimintiri",
                "ivichka e vyrhyt",
                "koki"
            };
            var secondList = new List <string>()
            {
                "trilalal",
                "tophrop",
                "trimtirim",
                "ivichka e vyrhyt",
                "koki"
            };


            var firstSet  = new CustomHashSet <string>(firstList);
            var secondSet = new CustomHashSet <string>(secondList);

            var resultList = firstSet.Intersect(secondList);

            var resultSet = firstSet.Intersect(secondSet);

            foreach (var entry in resultList)
            {
                var result = resultSet.Contains(entry);
                Assert.AreEqual(true, result);
            }

            Assert.AreEqual(resultList.Count(), resultSet.Count);
        }
Beispiel #8
0
        public void AddMethodShouldAddAnElementIfItDoesNotExistInTheSet()
        {
            var testSet = new CustomHashSet <int>();

            testSet.Add(3);

            Assert.IsTrue(testSet.Contains(3));
        }
Beispiel #9
0
        public void IntersectShouldWorkProperly()
        {
            var firstSet = new CustomHashSet<string> { "Perl", "Java", "C#", "SQL", "PHP" };
            var secondSet = new CustomHashSet<string> { "Oracle", "SQL", "MySQL" };
            var union = firstSet.IntersectWith(secondSet);

            Assert.AreEqual("SQL", union.ToString());
        }
Beispiel #10
0
 public void TestConstructorWithListOfStrings()
 {
     var set = new CustomHashSet<string>(new List<string>()
     {
         "alabala", "gruhgruh", "tintirimintiri", "ivichka e vyrhyt", "koki"
     });
     Assert.AreEqual(5, set.Count);
 }
 static void Main(string[] args)
 {
     var array   = new CustomArray <int>(2);
     var list    = new CustomList <int>();
     var queue   = new CustomQueue <int>();
     var stack   = new CustomStack <int>();
     var hashset = new CustomHashSet <int>();
 }
Beispiel #12
0
        public void FindShouldReturnProperValue()
        {
            var testSet = new CustomHashSet <int> {
                1, 2, 3
            };
            var number = testSet.Find(2);

            Assert.AreEqual(2, number);
        }
Beispiel #13
0
        public void RemoveShouldReturnFalseWhenValueIsNotFound()
        {
            var testSet = new CustomHashSet <int> {
                1, 2, 3
            };
            bool isRemoved = testSet.Remove(5);

            Assert.IsFalse(isRemoved);
        }
        public void ToStringShouldWorkProperly()
        {
            var testSet = new CustomHashSet<int>();
            testSet.Add(1);
            testSet.Add(2);
            testSet.Add(3);

            Assert.AreEqual("1, 2, 3", testSet.ToString());
        }
Beispiel #15
0
        public void ClearShouldEmptyTheSet()
        {
            var testSet = new CustomHashSet <int> {
                1, 2, 3
            };

            testSet.Clear();
            Assert.AreEqual(0, testSet.Count);
        }
Beispiel #16
0
        public void TestConstructorWithListOfStrings()
        {
            var set = new CustomHashSet <string>(new List <string>()
            {
                "alabala", "gruhgruh", "tintirimintiri", "ivichka e vyrhyt", "koki"
            });

            Assert.AreEqual(5, set.Count);
        }
        public void AddMethodShouldReturnFalseIfItExistsInTheSet()
        {
            var testSet = new CustomHashSet<int>();
            testSet.Add(3);
            var isAdded = testSet.Add(3);
            Console.WriteLine(testSet.Count);

            Assert.IsFalse(isAdded);
        }
Beispiel #18
0
        public void RemoveShouldReturnTrueWhenValueIsFoundAndRemoved()
        {
            var testSet = new CustomHashSet <int> {
                1, 2, 3
            };
            bool isRemoved = testSet.Remove(2);

            Assert.AreEqual(2, testSet.Count);
            Assert.IsTrue(isRemoved);
        }
Beispiel #19
0
        public void ToStringShouldWorkProperly()
        {
            var testSet = new CustomHashSet <int>();

            testSet.Add(1);
            testSet.Add(2);
            testSet.Add(3);

            Assert.AreEqual("1, 2, 3", testSet.ToString());
        }
Beispiel #20
0
        public void AddMethodShouldReturnFalseIfItExistsInTheSet()
        {
            var testSet = new CustomHashSet <int>();

            testSet.Add(3);
            var isAdded = testSet.Add(3);

            Console.WriteLine(testSet.Count);

            Assert.IsFalse(isAdded);
        }
Beispiel #21
0
        public void AnyShouldReturnFalseIfThereIsNoElementInTheHashSet()
        {
            //Arrange
            var expectedResult = false;

            hashset = new CustomHashSet <int>();
            //Act
            var actualResult = hashset.Any();

            //Assert
            Assert.AreEqual(expectedResult, actualResult);
        }
Beispiel #22
0
        public void IntersectShouldWorkProperly()
        {
            var firstSet = new CustomHashSet <string> {
                "Perl", "Java", "C#", "SQL", "PHP"
            };
            var secondSet = new CustomHashSet <string> {
                "Oracle", "SQL", "MySQL"
            };
            var union = firstSet.IntersectWith(secondSet);

            Assert.AreEqual("SQL", union.ToString());
        }
Beispiel #23
0
        public void UnionShouldWorkProperly()
        {
            var firstSet = new CustomHashSet <string> {
                "Perl", "Java", "C#", "SQL", "PHP"
            };
            var secondSet = new CustomHashSet <string> {
                "Oracle", "SQL", "MySQL"
            };
            var union = firstSet.UnionWith(secondSet);

            Assert.AreEqual(7, union.Count);
        }
Beispiel #24
0
        public void TestIfFindThrowsExeptionWhenInvalidKeyIsEntered()
        {
            var firstList = new List<string>()
            {
                "alabala",
                "gruhgruh",
                "tintirimintiri",
                "ivichka e vyrhyt",
                "koki"
            };

            var firstSet = new CustomHashSet<string>(firstList);
            firstSet.Find("Vesich");
        }
Beispiel #25
0
        public void TestIfFindThrowsExeptionWhenInvalidKeyIsEntered()
        {
            var firstList = new List <string>()
            {
                "alabala",
                "gruhgruh",
                "tintirimintiri",
                "ivichka e vyrhyt",
                "koki"
            };

            var firstSet = new CustomHashSet <string>(firstList);

            firstSet.Find("Vesich");
        }
Beispiel #26
0
        public void TestIfRemovingValueWorksCorrectly()
        {
            var firstList = new List <string>()
            {
                "alabala",
                "gruhgruh",
                "tintirimintiri",
                "ivichka e vyrhyt",
                "koki"
            };

            var firstSet = new CustomHashSet <string>(firstList);

            firstSet.Remove("koki");

            Assert.AreEqual(4, firstSet.Count);
        }
        private static void DisplayUnionIntersect(CustomHashSet <string> firstSet, CustomHashSet <string> secondSet)
        {
            Console.Write("First set: ");
            PrintSet(firstSet);

            Console.Write("Second set: ");
            PrintSet(secondSet);

            var union = firstSet.UnionWith(secondSet);

            Console.Write("Union: ");
            PrintSet(union);

            var intersect = firstSet.IntersectWith(secondSet);

            Console.Write("Intersect: ");
            PrintSet(intersect);
        }
Beispiel #28
0
        public void TestIfAddingNewValueWorksCorrectly()
        {
            var firstList = new List <string>()
            {
                "alabala",
                "gruhgruh",
                "tintirimintiri",
                "ivichka e vyrhyt",
                "koki"
            };

            var firstSet = new CustomHashSet <string>(firstList);

            firstSet.Add("trilalal");
            firstSet.Add("tophrop");
            firstSet.Add("trimtirim");

            Assert.AreEqual(8, firstSet.Count);
        }
Beispiel #29
0
        public void TestIfAddingNewValueWorksCorrectly()
        {
            var firstList = new List<string>()
            {
                "alabala",
                "gruhgruh",
                "tintirimintiri",
                "ivichka e vyrhyt",
                "koki"
            };

            var firstSet = new CustomHashSet<string>(firstList);

            firstSet.Add("trilalal");
            firstSet.Add("tophrop");
            firstSet.Add("trimtirim");

            Assert.AreEqual(8, firstSet.Count);
        }
        public static void Main()
        {
            CustomHashSet<int> firstSet = new CustomHashSet<int>();

            for (int i = 0; i < 20; i++)
            {
                firstSet.Add(i);
            }

            CustomHashSet<int> secondSet = new CustomHashSet<int>();

            for (int i = 10; i < 30; i++)
            {
                secondSet.Add(i);
            }

            CustomHashSet<int> resultUnion = firstSet.Intersect(secondSet);

            foreach (var item in resultUnion)
            {
                Console.WriteLine(item);
            }
        }
 public void ClearShouldEmptyTheSet()
 {
     var testSet = new CustomHashSet<int> { 1, 2, 3 };
     testSet.Clear();
     Assert.AreEqual(0, testSet.Count);
 }
 public void RemoveShouldReturnFalseWhenValueIsNotFound()
 {
     var testSet = new CustomHashSet<int> { 1, 2, 3 };
     bool isRemoved = testSet.Remove(5);
     Assert.IsFalse(isRemoved);
 }
Beispiel #33
0
 public void TestConstructorAsItShuoldCreateEmptyHashSet()
 {
     var set = new CustomHashSet<string>();
     Assert.AreEqual(0, set.Count);
 }
Beispiel #34
0
        public void TestIfRemovingValueWorksCorrectly()
        {
            var firstList = new List<string>()
            {
                "alabala",
                "gruhgruh",
                "tintirimintiri",
                "ivichka e vyrhyt",
                "koki"
            };

            var firstSet = new CustomHashSet<string>(firstList);
            firstSet.Remove("koki");

            Assert.AreEqual(4, firstSet.Count);
        }
        public void UnionShouldWorkProperly()
        {
            var firstSet = new CustomHashSet<string> { "Perl", "Java", "C#", "SQL", "PHP" };
            var secondSet = new CustomHashSet<string> { "Oracle", "SQL", "MySQL" };
            var union = firstSet.UnionWith(secondSet);

            Assert.AreEqual(7, union.Count);
        }
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            // Problem 1: Write a program that counts in a given array of double values the number of occurrences of each value. Use Dictionary<TKey,TValue>.
            Console.WriteLine(new string('-', 20));
            Console.WriteLine("Problem 1:");
            Console.WriteLine(new string('-', 20));
            dynamic[] data = { 3, 4, 4, -2.5, 3, 3, 4, 3, -2.5 };
            Dictionary <dynamic, int> groupedData = GroupByOccurence(data);

            PrintDictionary(groupedData);

            // Problem 2: Write a program that extracts from a given sequence of strings all elements that present in it odd number of times.
            Console.WriteLine();
            Console.WriteLine(new string('-', 20));
            Console.WriteLine("Problem 2:");
            Console.WriteLine(new string('-', 20));
            string[] strings = { "C#", "SQL", "PHP", "PHP", "SQL", "SQL" };
            Dictionary <dynamic, int> groupedStrings = GroupByOccurence(strings);

            foreach (var key in groupedStrings)
            {
                if (key.Value % 2 != 0)
                {
                    Console.WriteLine(key.Key + " --> " + key.Value);
                }
            }

            // Problem 3: Write a program that counts how many times each word from given text file words.txt appears in it.
            // The character casing differences should be ignored. The result words should be ordered by their number of occurrences in the text.
            Console.WriteLine();
            Console.WriteLine(new string('-', 20));
            Console.WriteLine("Problem 3: ");
            Console.WriteLine(new string('-', 20));
            string[] text = ReadText();
            Dictionary <dynamic, int> wordsOccurences = GroupByOccurence(text);
            var sortedDict = from word in wordsOccurences
                             orderby word.Value ascending
                             select word;

            foreach (var word in sortedDict)
            {
                Console.WriteLine("{0} --> {1}", word.Key, word.Value);
            }

            // Problems 4 & 5:
            Console.WriteLine();
            Console.WriteLine(new string('-', 20));
            Console.WriteLine("Problems 4 and 5: ");
            Console.WriteLine(new string('-', 20));
            var firstSet = new CustomHashSet <string> {
                "Perl", "Java", "C#", "SQL", "PHP"
            };
            var secondSet = new CustomHashSet <string> {
                "Oracle", "SQL", "MySQL"
            };

            DisplayUnionIntersect(firstSet, secondSet);

            // Problem 6: (*) A text file phones.txt holds information about people, their town and phone number.
            // Duplicates can occur in people names, towns and phone numbers. Write a program to read the phones
            // file and execute a sequence of commands given in the file commands.txt
            Console.WriteLine(new string('-', 20));
            Console.WriteLine("Problems 6: ");
            Console.WriteLine(new string('-', 20));
            var phoneBook = new Dictionary <string, List <Details> >();

            using (var fileReader = new StreamReader(@"..\..\phones.txt"))
            {
                while (!fileReader.EndOfStream)
                {
                    var line       = fileReader.ReadLine();
                    var components = line.Split('|');
                    if (!phoneBook.ContainsKey(components[0].Trim()))
                    {
                        phoneBook.Add(components[0].Trim(), new List <Details> {
                            new Details
                            {
                                Town        = components[1].Trim(),
                                PhoneNumber = components[2].Trim()
                            }
                        });
                    }
                    else
                    {
                        phoneBook[components[0].Trim()].Add(new Details
                        {
                            Town        = components[1].Trim(),
                            PhoneNumber = components[2].Trim()
                        });
                    }
                }
            }

            using (var fileReader = new StreamReader(@"..\..\commands.txt"))
            {
                while (!fileReader.EndOfStream)
                {
                    var command = fileReader.ReadLine();
                    Console.WriteLine("Command: {0} ", command);
                    int leftBracketIndex  = command.IndexOf('(');
                    int rightBracketIndex = command.IndexOf(')');
                    var commandParams     =
                        command.Substring(leftBracketIndex + 1, rightBracketIndex - leftBracketIndex - 1).Split(',');

                    IEnumerable <KeyValuePair <string, List <Details> > > result;

                    if (commandParams.Length > 1)
                    {
                        result =
                            phoneBook.Where(x => x.Key.Contains(commandParams[0]) && x.Value[0].Town == commandParams[1].Trim());
                    }
                    else
                    {
                        result =
                            phoneBook.Where(x => x.Key.Contains(commandParams[0]));
                    }

                    Console.WriteLine("Result: ");

                    foreach (var line in result)
                    {
                        Console.Write(line.Key + ": ");
                        foreach (var entry in line.Value)
                        {
                            Console.WriteLine("Town: " + entry.Town + "; Phone number: " + entry.PhoneNumber);
                        }
                    }
                }
            }
        }
Beispiel #37
0
        public void TestIfIntersectWokscorrectly()
        {
            var firstList = new List<string>()
            {
                "alabala",
                "gruhgruh",
                "tintirimintiri",
                "ivichka e vyrhyt",
                "koki"
            };
            var secondList = new List<string>()
            {
                "trilalal",
                "tophrop",
                "trimtirim",
                "ivichka e vyrhyt",
                "koki"
            };

            var firstSet = new CustomHashSet<string>(firstList);
            var secondSet = new CustomHashSet<string>(secondList);

            var resultList = firstSet.Intersect(secondList);

            var resultSet = firstSet.Intersect(secondSet);

            foreach (var entry in resultList)
            {
                var result = resultSet.Contains(entry);
                Assert.AreEqual(true, result);
            }

            Assert.AreEqual(resultList.Count(), resultSet.Count);
        }
Beispiel #38
0
        public void TestConstructorAsItShuoldCreateEmptyHashSet()
        {
            var set = new CustomHashSet <string>();

            Assert.AreEqual(0, set.Count);
        }