Пример #1
0
        private static List<PuzzleName> BuildPuzzleNames(IEnumerable<string> names)
        {
            // Iterate through the list of names and build a List of PuzzleName objects.
            //
            // Note: The first PuzzleName object should have a Position property value of 1.
            // The second is 2 and so on.
            // Position is 1 based and not zero based.

            int position = 0;
            List<PuzzleName> puzzleNames = new List<PuzzleName>();
            try
            {
                foreach (string name in names)
                {
                    position += 1;
                    var puzzle = new PuzzleName(name, position);
                    puzzleNames.Add(puzzle);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            //TODO: remove this code and add your implementation here
            return puzzleNames;
        }
Пример #2
0
        public void ShouldSolvePuzzle()
        {
            //arrange
            PuzzleName puzzle= new PuzzleName("ABDUL",1);
            PuzzleName puzzleScore= new PuzzleName("AGNES", 43);
            List<PuzzleName> puzzleNames = new List<PuzzleName> {puzzle, puzzleScore };

            int position = 1;
            PuzzleName puzzleName = puzzleNames.ElementAt(position);

            //act
            string puzzleAnswer = PuzzleSolver.Solve();

            //assert
            Assert.AreEqual(puzzleAnswer, puzzleName.Name + puzzleName.Score);
        }
Пример #3
0
        private static List<PuzzleName> BuildPuzzleNames(IEnumerable<string> names)
        {
            // Iterate through the list of names and build a List of PuzzleName objects.
            //
            // Note: The first PuzzleName object should have a Position property value of 1.
            // The second is 2 and so on.
            // Position is 1 based and not zero based.

            //TODO: remove this code and add your implementation here
            //return names.Select(n => new PuzzleName(n, -999)).ToList();

            /*
             * Yobe     - 14/10/2015
             *
             * Build list of puzzle objects
             *
             */
            List<PuzzleName> puzzleNames = new List<PuzzleName>();

            // Convert to generic list
            List<string> sNames = names.ToList();

            // Sort the list alphabetically
            sNames.Sort();

            // Loop through the list and build puzzle objects
            for (int i = 0; i <= sNames.Count - 1; i++)
            {
                // Get current name
                string name = sNames[i];

                // Get position of the name in list
                int iPosition = sNames.IndexOf(name);

                // Add 1 so Position is not zero based
                iPosition += 1;

                // New object
                PuzzleName puzzleName = new PuzzleName(name, iPosition);

                puzzleNames.Add(puzzleName);
            }

            return puzzleNames;
        }