public void Do_ExampleInput_Output(string input, string output, int x, int y) { var c = input.ToCharArray(); var swap = new LetterSwap(x, y); swap.Do(ref c); Assert.AreEqual(output, c); }
private static List <IInstruction> GetInstructions(IEnumerable <string> instructionLines) { var instructions = new List <IInstruction>(); IInstruction instruction; foreach (var instructionLine in instructionLines) { instruction = null; var parts = GetParts(instructionLine); if (parts[0] == "swap") { if (parts[1] == "position") { instruction = new PositionSwap() { IndexX = int.Parse(parts[2]), IndexY = int.Parse(parts[5]) }; } else { instruction = new LetterSwap() { X = parts[2][0], Y = parts[5][0] }; } } else if (parts[0] == "rotate") { if (parts[1] == "based") { instruction = new RotatePos() { X = parts[6][0] }; } else { instruction = new Rotate() { Count = int.Parse(parts[2]) * (parts[1] == "right" ? -1 : 1) }; } } else if (parts[0] == "reverse") { instruction = new Reverse() { IndexX = int.Parse(parts[2]), IndexY = int.Parse(parts[4]) }; } else if (parts[0] == "move") { instruction = new Move() { IndexX = int.Parse(parts[2]), IndexY = int.Parse(parts[5]) }; } if (instruction == null) { throw new InvalidOperationException(); } instructions.Add(instruction); } return(instructions); }