public void TestHelloWorld(string instructions) { BrainfuckInterpreter bi = new BrainfuckInterpreter(); string result = bi.Interpret(instructions); Assert.Equal("Hello World!\n", result); }
public void Test_CreateInterpreter_IsInitialized() { InputOutputMock ioMock = new InputOutputMock(); BrainfuckInterpreter interpreter = BrainfuckInterpreter.Create(ioMock); string input = "+++++--"; char[] inputChars = input.ToCharArray(); using (ICpu cpu = interpreter.CreateCpu(input)) { Assert.IsNotNull(cpu.IO); Assert.Equals(cpu.IO, ioMock); Assert.IsNotNull(cpu.Rom); Assert.IsNotNull(cpu.IO); Assert.IsTrue(cpu.Rom.Address == 0); Assert.IsTrue(cpu.Rom.Size == input.Length); Assert.IsTrue(cpu.Memory.Address == 0); int i = 0; foreach (byte b in cpu.Rom.Dump()) { Assert.IsTrue(inputChars[i] == (char)b); i++; } } }
static async Task Main(string[] args) { var brainfuck = BrainfuckInterpreter.Create(); ICpu cpu = brainfuck.CreateCpu("++++++++++[>+>+++>+++<<<-]>>++>++++++++++++>+[>+>+<<-]>+++++++++[<<<.>>>-]>[<<<.>>>-]<<<<<.>>>+++[>+>+<<-]>++++++[<<<.>>>-]>[<<<.>>>-]<<<<<.>>>+++++[>+>+<<-]>+++[<<<.>>>-]>[<<<.>>>-]<<<<<.>>>+++++++[>+>+<<-]>[<<<.>>>-]>[<<<.>>>-]<<<<<.>>>++++++++++[>++++++<-]>+++++<<<...>>>+++++.-.+++++++.---.+++++++++++++++++.<<<.>>>------------.-------------.+++++++++++++++++++++.-------------------.+++++++++++.<<<.>>>-----------.+++++++++++++++.------------.---."); await cpu.Process(); Console.ReadKey(); // dump the memory in screen. int i = 0; foreach (var @byte in cpu.Memory.Dump()) { Console.Write($"[{i}] {@byte}"); if (i == cpu.Memory.Address) { Console.Write("*"); } Console.WriteLine(); i++; } Console.WriteLine("Finished."); Console.ReadKey(); }
public void TestEmptyString() { BrainfuckInterpreter bi = new BrainfuckInterpreter(); string result = bi.Interpret(""); Assert.Equal("", result); }
public MainPage() { _brainfuck = BrainfuckInterpreter.Create(this); this.InitializeComponent(); RichEditBox richEditBox = BrainfuckInputRichTextBox; richEditBox.CharacterReceived += RichEditBox_CharacterReceived; }
static void Main(string[] args) { BrainfuckInterpreter bi = new BrainfuckInterpreter(); //Console.WriteLine(bi.Interpret("++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.")); Console.WriteLine(bi.Interpret(@" >++++++++[<+++++++++>-]<.>>+>+>++>[-]+<[>[->+<<++++>]<<]>.+++++++..+++.>>+++++++.<<<[[-]<[-]>]<+++++++++++++++.>>.+++.------.--------.>>+.>++++. ")); }
private void WriteTest(string name, Instruction[] instructions, string input, CacheBuilder inputCache, string output, CacheBuilder outputCache, int?nopBreakpointId) { Trace.WriteLine(name); // generate sourcecode var cw = new CodeWriter(new StringWriter()); cw.EmitDebugInfo = DebugEnabled; cw.EmitDebugBreakpoint = DebugEnabled && nopBreakpointId == null; // cw.Begin(); // cache initialized by cache builder foreach (var insn in instructions) { if (insn.Prototype == InstructionPrototypes.Nop && insn.Get(0) == nopBreakpointId) { cw.Write(new Instruction(InstructionPrototypes.Breakpoint)); } cw.Write(insn); } cw.End(); Trace.WriteLine(cw.Writer); this.DumpInfo("Input ", input, inputCache.Build(), inputCache.CachePointer); this.DumpInfo("Expected", output, outputCache.Build(), outputCache.CachePointer); // run code var intptr = new BrainfuckInterpreter(cw.Writer.ToString(), inputCache.Build()); intptr.Input = new StringReader(input); intptr.Output = new StringWriter(); intptr.CachePointer = inputCache.CachePointer; if (nopBreakpointId != null) { intptr.NextBreakpoint(); Assert.IsFalse(intptr.Terminated, "terminated"); } else { intptr.Run(); } this.DumpInfo("Actual ", intptr.Output.ToString(), intptr.Cache, intptr.CachePointer); // asserts var prefix = $"\nTestcase: {name}\n"; outputCache.CacheSize = inputCache.CacheSize; CollectionAssert.AreEqual(outputCache.Build(), intptr.Cache, prefix + "cache"); Assert.AreEqual(outputCache.CachePointer, intptr.CachePointer, prefix + "cache pointer"); Assert.AreEqual(output, intptr.Output.ToString(), prefix + "output"); }
static void Main(string[] args) { var interpreter = new BrainfuckInterpreter(); interpreter.Process(HelloWorld); }
public OutputEventArgs(BrainfuckInterpreter interpreter, long value) { Interpreter = interpreter; Value = value.ToString(CultureInfo.InvariantCulture); }
public OutputEventArgs(BrainfuckInterpreter interpreter, char value) { Interpreter = interpreter; Value = value.ToString(); }
/// <summary> /// Standard Constructor /// </summary> /// <param name="message">Message</param> /// <param name="position">Position (zero based) in source code</param> public ExecutionException(string message, Exception innerException, BrainfuckInterpreter interpreter) : base(message, innerException) { Interpreter = interpreter; }