Exemplo n.º 1
0
        public void split_input_into_steps()
        {
            string input          = "UL";
            var    keypad         = new Mock <Keypad>();
            var    keypadFollower = new KeypadFollower(new Coordinate(1, 1), keypad.Object);

            keypadFollower.FollowPath(input, false);
            Assert.AreEqual("1", keypadFollower.CurrentValue());
        }
Exemplo n.º 2
0
        public void reuse_same_location()
        {
            string input          = "LRLDUD";
            var    keypad         = new Mock <Keypad>();
            var    keypadFollower = new KeypadFollower(new Coordinate(1, 1), keypad.Object);

            keypadFollower.FollowPath(input, false);
            Assert.AreEqual(0, keypadFollower.CurrentPosition.X);
            Assert.AreEqual(2, keypadFollower.CurrentPosition.Y);
        }
Exemplo n.º 3
0
        public void read_correct_final_location()
        {
            string input          = "ULL";
            var    keypad         = new Mock <Keypad>();
            var    keypadFollower = new KeypadFollower(new Coordinate(1, 1), keypad.Object);

            keypadFollower.FollowPath(input, false);
            Assert.AreEqual(new Coordinate(0, 0), keypadFollower.CurrentPosition);
            Assert.AreEqual(0, keypadFollower.CurrentPosition.X);
            Assert.AreEqual(0, keypadFollower.CurrentPosition.Y);
        }
Exemplo n.º 4
0
        public static void Part1()
        {
            var fileIo = new FileImporter <string>(new NullParser());
            var keypad = new Keypad();

            keypad.PrintKeypad();
            var keypadFollower = new KeypadFollower(new Coordinate(1, 1), keypad);
            var processor      = new KeypadProcessor(fileIo, keypadFollower);

            processor.Process("../../input.txt");
        }
Exemplo n.º 5
0
        public void reset_the_start_position()
        {
            string input          = "LURDL";
            var    keypad         = new Mock <Keypad>();
            var    keypadFollower = new KeypadFollower(new Coordinate(1, 2), keypad.Object);

            keypadFollower.FollowPath(input, false);
            keypadFollower.resetStart(new Coordinate(1, 2));
            Assert.AreEqual(1, keypadFollower.CurrentPosition.X);
            Assert.AreEqual(2, keypadFollower.CurrentPosition.Y);
            Assert.AreEqual(new Coordinate(1, 2), keypadFollower.CurrentPosition);
        }
Exemplo n.º 6
0
        public static void Part2()
        {
            var fileIo = new FileImporter <string>(new NullParser());
            var keypad = Keypad.DiamondKeypad();

            keypad.PrintKeypad();
            var keypadFollower = new KeypadFollower(new Coordinate(0, 3), keypad);
            var processor      = new KeypadProcessor(fileIo, keypadFollower);

            processor.Process("../../input.txt");
            Console.ReadKey();
        }
Exemplo n.º 7
0
        private static char[] GetCombination(char[,] keypad)
        {
            var follower = new KeypadFollower(keypad);

            string[] lines       = kInput.Split('\n');
            var      combination = new char[lines.Length];

            for (int i = 0; i < lines.Length; ++i)
            {
                char digit = follower.FindDigit(lines[i]);
                combination[i] = digit;
            }

            return(combination);
        }
Exemplo n.º 8
0
 public KeypadProcessor(FileImporter <string> importer, KeypadFollower keypadFollower) : base(importer)
 {
     _keypadFollower = keypadFollower;
 }