public void SetUp() { _inputReader = new FileInputReader(new ArgumentManager(new Options() { Input = "input.txt" })); }
static void Main(string[] args) { FileInputReader reader = new FileInputReader(); DiscTowerFactory factory = new DiscTowerFactory(reader); DiscTower tower = factory.CreateFromInput("Inputs/day-7.txt"); // Part one Console.WriteLine(tower.GetRootDisc().Name); // Part two Console.WriteLine(tower.FindBalancingProgramWeight()); }
static void Main(string[] args) { CPU cpu = new CPU(); FileInputReader reader = new FileInputReader(); InstructionProcessor processor = new InstructionProcessor(cpu, reader); processor.ProcessInstructions("Inputs/day-8.txt"); // Part one Console.WriteLine(processor.GetCurrentLargestValue()); // Part two Console.WriteLine(processor.GetHistoricalLargestValue()); }
public void Simple() { var examplePath = "../../../Input/example.kju"; var inputReader = new FileInputReader(examplePath); var data = inputReader.Read(); Assert.AreEqual("fun kju():Unit{\n var x:Int={\n 5;\n }\n}\n"+ KJU.Core.Constants.EndOfInput, string.Concat(data.Select(kvp => kvp.Value))); Assert.AreEqual(1, ((KJU.Core.Input.FileLocation)data[0].Key).Line); Assert.AreEqual(1, ((KJU.Core.Input.FileLocation)data[0].Key).Column); Assert.AreEqual(examplePath, ((KJU.Core.Input.FileLocation)data[0].Key).FileName); Assert.AreEqual(1, ((KJU.Core.Input.FileLocation)data[1].Key).Line); Assert.AreEqual(2, ((KJU.Core.Input.FileLocation)data[1].Key).Column); Assert.AreEqual(examplePath, ((KJU.Core.Input.FileLocation)data[1].Key).FileName); }
static void Main(string[] args) { /** * I used the following extremely well-written guide by Amit Patel (Red Blob Games) * to understand how a hexogonal grid can be represented and how one traverses it: * * https://www.redblobgames.com/grids/hexagons * * It's one of the most nicely-presented resources on game development that I've * ever seen! */ FileInputReader reader = new FileInputReader(); HexWalker walker = new HexWalker(reader); // Part one Console.WriteLine(walker.ShortestDistanceFromStart("Inputs/day-11.txt")); // Part two Console.WriteLine(walker.FarthestDistanceFromStart("Inputs/day-11.txt")); }
public void TestWithFileInput() { string filename = GetFullPathToFile(Path.Combine("Integration", "pseudoJSONSample.txt")); /* * Input from file: * * "[ {\"2Ws8P0wYj\": -17, \"dbV\": true,\"B5b0BofwT\": -13.607189896949151 }, [], \tnull, [], \n{\n\"NwAssf8pU\":null }\n ]" */ var tokenCategories = new List <KeyValuePair <FileTestCategory, string> > { new KeyValuePair <FileTestCategory, string>(FileTestCategory.Brace, "{|}"), new KeyValuePair <FileTestCategory, string>(FileTestCategory.Bracket, "\\[|\\]"), new KeyValuePair <FileTestCategory, string>(FileTestCategory.Colon, ":"), new KeyValuePair <FileTestCategory, string>(FileTestCategory.Comma, ","), new KeyValuePair <FileTestCategory, string>(FileTestCategory.Minus, "[\\-]"), new KeyValuePair <FileTestCategory, string>(FileTestCategory.Number, "[1-9][0-9]*|[1-9][0-9]*.[0-9][0-9]*|0.[0-9][0-9]*"), new KeyValuePair <FileTestCategory, string>(FileTestCategory.Boolean, "true|false"), new KeyValuePair <FileTestCategory, string>(FileTestCategory.Null, "null"), new KeyValuePair <FileTestCategory, string>(FileTestCategory.QuotedString, "\"[a-zA-Z0-9_]*\""), new KeyValuePair <FileTestCategory, string>(FileTestCategory.Whitespace, "[ \n\r\t\v][ \n\r\t\v]*") }; var expectedTokens = new List <Token <FileTestCategory> > { CreateToken(FileTestCategory.Bracket, "[", new FileLocation(filename, 1, 1), new FileLocation(filename, 1, 2)), CreateToken(FileTestCategory.Whitespace, " ", new FileLocation(filename, 1, 2), new FileLocation(filename, 1, 3)), CreateToken(FileTestCategory.Brace, "{", new FileLocation(filename, 1, 3), new FileLocation(filename, 1, 4)), CreateToken(FileTestCategory.QuotedString, "\"2Ws8P0wYj\"", new FileLocation(filename, 1, 4), new FileLocation(filename, 1, 15)), CreateToken(FileTestCategory.Colon, ":", new FileLocation(filename, 1, 15), new FileLocation(filename, 1, 16)), CreateToken(FileTestCategory.Whitespace, " ", new FileLocation(filename, 1, 16), new FileLocation(filename, 1, 18)), CreateToken(FileTestCategory.Minus, "-", new FileLocation(filename, 1, 18), new FileLocation(filename, 1, 19)), CreateToken(FileTestCategory.Number, "17", new FileLocation(filename, 1, 19), new FileLocation(filename, 1, 21)), CreateToken(FileTestCategory.Comma, ",", new FileLocation(filename, 1, 21), new FileLocation(filename, 1, 22)), CreateToken(FileTestCategory.Whitespace, " ", new FileLocation(filename, 1, 22), new FileLocation(filename, 1, 23)), CreateToken(FileTestCategory.QuotedString, "\"dbV\"", new FileLocation(filename, 1, 23), new FileLocation(filename, 1, 28)), CreateToken(FileTestCategory.Colon, ":", new FileLocation(filename, 1, 28), new FileLocation(filename, 1, 29)), CreateToken(FileTestCategory.Whitespace, " ", new FileLocation(filename, 1, 29), new FileLocation(filename, 1, 32)), CreateToken(FileTestCategory.Boolean, "true", new FileLocation(filename, 1, 32), new FileLocation(filename, 1, 36)), CreateToken(FileTestCategory.Comma, ",", new FileLocation(filename, 1, 36), new FileLocation(filename, 1, 37)), CreateToken(FileTestCategory.QuotedString, "\"B5b0BofwT\"", new FileLocation(filename, 1, 37), new FileLocation(filename, 1, 48)), CreateToken(FileTestCategory.Colon, ":", new FileLocation(filename, 1, 48), new FileLocation(filename, 1, 49)), CreateToken(FileTestCategory.Whitespace, " ", new FileLocation(filename, 1, 49), new FileLocation(filename, 1, 51)), CreateToken(FileTestCategory.Minus, "-", new FileLocation(filename, 1, 51), new FileLocation(filename, 1, 52)), CreateToken(FileTestCategory.Number, "13.607189896949151", new FileLocation(filename, 1, 52), new FileLocation(filename, 1, 70)), CreateToken(FileTestCategory.Whitespace, " ", new FileLocation(filename, 1, 70), new FileLocation(filename, 1, 71)), CreateToken(FileTestCategory.Brace, "}", new FileLocation(filename, 1, 71), new FileLocation(filename, 1, 72)), CreateToken(FileTestCategory.Comma, ",", new FileLocation(filename, 1, 72), new FileLocation(filename, 1, 73)), CreateToken(FileTestCategory.Whitespace, " ", new FileLocation(filename, 1, 73), new FileLocation(filename, 1, 74)), CreateToken(FileTestCategory.Bracket, "[", new FileLocation(filename, 1, 74), new FileLocation(filename, 1, 75)), CreateToken(FileTestCategory.Bracket, "]", new FileLocation(filename, 1, 75), new FileLocation(filename, 1, 76)), CreateToken(FileTestCategory.Comma, ",", new FileLocation(filename, 1, 76), new FileLocation(filename, 1, 77)), CreateToken(FileTestCategory.Whitespace, " \t", new FileLocation(filename, 1, 77), new FileLocation(filename, 1, 79)), CreateToken(FileTestCategory.Null, "null", new FileLocation(filename, 1, 79), new FileLocation(filename, 1, 83)), CreateToken(FileTestCategory.Comma, ",", new FileLocation(filename, 1, 83), new FileLocation(filename, 1, 84)), CreateToken(FileTestCategory.Whitespace, " ", new FileLocation(filename, 1, 84), new FileLocation(filename, 1, 88)), CreateToken(FileTestCategory.Bracket, "[", new FileLocation(filename, 1, 88), new FileLocation(filename, 1, 89)), CreateToken(FileTestCategory.Bracket, "]", new FileLocation(filename, 1, 89), new FileLocation(filename, 1, 90)), CreateToken(FileTestCategory.Comma, ",", new FileLocation(filename, 1, 90), new FileLocation(filename, 1, 91)), CreateToken(FileTestCategory.Whitespace, " \n", new FileLocation(filename, 1, 91), new FileLocation(filename, 2, 1)), CreateToken(FileTestCategory.Brace, "{", new FileLocation(filename, 2, 1), new FileLocation(filename, 2, 2)), CreateToken(FileTestCategory.Whitespace, "\n ", new FileLocation(filename, 2, 2), new FileLocation(filename, 3, 3)), CreateToken(FileTestCategory.QuotedString, "\"NwAssf8pU\"", new FileLocation(filename, 3, 3), new FileLocation(filename, 3, 14)), CreateToken(FileTestCategory.Colon, ":", new FileLocation(filename, 3, 14), new FileLocation(filename, 3, 15)), CreateToken(FileTestCategory.Null, "null", new FileLocation(filename, 3, 15), new FileLocation(filename, 3, 19)), CreateToken(FileTestCategory.Whitespace, " ", new FileLocation(filename, 3, 19), new FileLocation(filename, 3, 21)), CreateToken(FileTestCategory.Brace, "}", new FileLocation(filename, 3, 21), new FileLocation(filename, 3, 22)), CreateToken(FileTestCategory.Whitespace, "\n ", new FileLocation(filename, 3, 22), new FileLocation(filename, 4, 3)), CreateToken(FileTestCategory.Bracket, "]", new FileLocation(filename, 4, 3), new FileLocation(filename, 4, 4)), CreateToken(FileTestCategory.Whitespace, "\n", new FileLocation(filename, 4, 4), new FileLocation(filename, 5, 1)), CreateToken(FileTestCategory.Eof, null, null, null) }; IInputReader inputReader = new FileInputReader(filename); var resolver = new ConflictResolver <FileTestCategory>(FileTestCategory.None); var lexer = new Lexer <FileTestCategory>(tokenCategories, FileTestCategory.Eof, FileTestCategory.None, resolver.ResolveWithMaxValue); var outputTokens = lexer.Scan(inputReader.Read(), null); var expectedText = string.Join(",\n", expectedTokens); var actualText = string.Join(",\n", outputTokens); Assert.IsTrue(outputTokens.SequenceEqual(expectedTokens, new TokenComparer <FileTestCategory>()), $"Expected:\n{expectedText}\nactual:\n{actualText}"); }
public static Artifacts RunOnFile(this ICompiler compiler, string path, IDiagnostics diag) { var fileInputReader = new FileInputReader(path); return(compiler.RunOnInputReader(fileInputReader, diag)); }