Ejemplo n.º 1
0
        public void transAndSortTest()
        {
            var names = new List <string> {
                "Janet Parsons", "Vaughn Lewis", "Adonis Julius Archer", "Shelby Nathan Yoder", "Marin Alvarez", "London Lindsey", "Beau Tristan Bentley", "Leo Gardner", "Hunter Uriah Mathew Clarke", "Mikayla Lopez", "Frankie Conner Ritter"
            };
            SortPerson    sort          = new SortPerson();
            List <Person> sortedPersons = sort.transAndSort(names);

            // check ordered person first name
            Assert.AreEqual(sortedPersons[0].lastName, "Alvarez");
            Assert.AreEqual(sortedPersons[1].lastName, "Archer");
            Assert.AreEqual(sortedPersons[2].lastName, "Bentley");
            Assert.AreEqual(sortedPersons[3].lastName, "Clarke");
            Assert.AreEqual(sortedPersons[4].lastName, "Gardner");
            Assert.AreEqual(sortedPersons[5].lastName, "Lewis");
            Assert.AreEqual(sortedPersons[6].lastName, "Lindsey");
            Assert.AreEqual(sortedPersons[7].lastName, "Lopez");
            Assert.AreEqual(sortedPersons[8].lastName, "Parsons");
            Assert.AreEqual(sortedPersons[9].lastName, "Ritter");
            Assert.AreEqual(sortedPersons[10].lastName, "Yoder");

            names.Clear();
            names = new List <string>();
            names.Add("Janet Yoder");
            names.Add("Vaughn Yoder");
            names.Add("Adonis Julius Yoder");
            names.Add("Shelby Nathan Yoder");
            sortedPersons.Clear();
            sortedPersons = sort.transAndSort(names);
            Assert.AreEqual(sortedPersons[0].firstNames[0], "Adonis");
            Assert.AreEqual(sortedPersons[1].firstNames[0], "Janet");
            Assert.AreEqual(sortedPersons[2].firstNames[0], "Shelby");
            Assert.AreEqual(sortedPersons[3].firstNames[0], "Vaughn");
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            string fileName = "unsorted-names-list.txt";
            string path     = Directory.GetCurrentDirectory();

            if (args.Length <= 0)
            {
                Console.WriteLine("please enter file name : ");
                fileName = Console.ReadLine();
            }
            else
            {
                fileName = args[0];
                path     = args[1].Replace("\"", "");
            }
            ReadFile read = new ReadFile();

            var readPath = Path.Combine(path, fileName);



            var           writePath     = Path.Combine(Directory.GetCurrentDirectory(), "sorted-names-list.txt");
            List <string> names         = read.readFileByLine(readPath);
            SortPerson    sortPersons   = new SortPerson();
            List <Person> sortedPersons = sortPersons.transAndSort(names);

            string[] sortedNames = new string[sortedPersons.Count];
            for (int idx = 0; idx < sortedPersons.Count; idx++)
            {
                //Console.WriteLine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
                Console.WriteLine(Person.transPersonToStr(sortedPersons.ElementAt(idx)));
                sortedNames[idx] = Person.transPersonToStr(sortedPersons.ElementAt(idx));
            }
            WriteFile write = new WriteFile();

            write.WriteFileByLine(writePath, sortedNames);
            Console.ReadLine();
        }