Esempio n. 1
0
        static void Main(string[] args)
        {
            PrintHeader();

            if (args.Length > 0)
            {
                HandleArgs(args);
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Started...");

            if (showTimer)
            {
                stopwatch = Stopwatch.StartNew();
            }

            // Read the contents of the SocialNetwork.txt file
            string[] fileContents = FileHelper.ReadFile("Resources/SocialNetwork.txt");
            if (fileContents == null)
            {
                PrintMissingFileError();
            }

            // Convert the file contents into a list of members
            members = MemberHelper.CreateMembers(fileContents);

            // Find the shortest path between the two specified members
            int shortestDistance = MemberHelper.GetShortestDistance(members, end, start);

            if (stopwatch != null)
            {
                stopwatch.Stop();
            }

            Console.WriteLine("Done!\n");
            Console.ResetColor();

            if (showTimer)
            {
                Console.WriteLine($"Elapsed: {stopwatch.Elapsed}");
            }

            PrintResult(shortestDistance);
        }
        public void CreatesMembersCorrectly()
        {
            string[] fileContents =
            {
                "PERSON_1,PERSON_2",
                "PERSON_1,PERSON_3",
                "PERSON_1,PERSON_4",
                "PERSON_2,PERSON_3",
                "PERSON_2,PERSON_4",
                "PERSON_3,PERSON_4",
            };

            Dictionary <string, HashSet <string> > members = MemberHelper.CreateMembers(fileContents);

            // Check that four members are created
            Assert.AreEqual(4, members.Count);

            // Make sure that PERSON_1 has 3 friends
            Assert.AreEqual(3, members["PERSON_1"].Count);
        }