Example #1
0
        public void HandleInputsAndOutputs()
        {
            StringBuilder stringToRead = new StringBuilder();

            stringToRead.AppendLine("1");
            stringToRead.AppendLine("a");

            using (StringReader reader = new StringReader(stringToRead.ToString()))
            {
                Assert.Equal("a1", BefungeInterpreter.Interpret("&~,.@", null, reader));
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Befunge World!");
            //Console.WriteLine(BefungeInterpreter.Interpret(">987v>.v\nv456<  :\n>321 ^ _@"));
            //BefungeInterpreter.Interpret("2>:3g\" \"-!v\\  g30          <\n |!`\"&\":+1_:.:03p>03g+:\"&\"`|\n @               ^  p3\\\" \":<\n2 2345678901234567890123456789012345678");
            //Console.WriteLine(BefungeInterpreter.Interpret(">v \n>?<\n ^ \n"));
            //BefungeInterpreter.Interpret(" v>>>>>v\n  12345 \n ^?^    \n> ? ?^  \n  v?v   \n  678@  \n  >>>> v\n ^    .<");
            //BefungeInterpreter.Interpret(">1.v   >4.\n   >2.>?<\n       >3.@");
            //BefungeInterpreter.Interpret("v\n> ^@");

            using (StreamWriter sw = new StreamWriter("befunge_output.txt"))
            {
                //BefungeInterpreter.Interpret(">.@");
                //BefungeInterpreter.Interpret("v\n> ^@");
                //BefungeInterpreter.Interpret(">7 : 1v1:<\n      `  .\n      !  :\n    @._2/^ ");

                // Power Of 2
                BefungeInterpreter.Interpret(">& : 2v2:    <\n      `      /\n      !      2 \n@,\"t\" _  :2%!|\n             >\"f\",@");

                // Ask for an integer and character
                //BefungeInterpreter.Interpret("&~,.@");
            }
        }
Example #3
0
 public void DetermineOddOrEven(int i)
 {
     Assert.Equal((i % 2).ToString(), BefungeInterpreter.Interpret(">" + i.ToString() + " 2%v\n  @.1_0.@"));
 }
Example #4
0
        public void HandleQuine()
        {
            string befungeCode = "01->1# +# :# 0# g# ,# :# 5# 8# *# 4# +# -# _@";

            Assert.Equal("01->1# +# :# 0# g# ,# :# 5# 8# *# 4# +# -# _@", BefungeInterpreter.Interpret(befungeCode));
        }
Example #5
0
        public void HandleSieve()
        {
            string befungeCode = "2>:3g\" \"-!v\\  g30          <\n |!`\"&\":+1_:.:03p>03g+:\"&\"`|\n @               ^  p3\\\" \":<\n2 2345678901234567890123456789012345678";

            Assert.Equal("23571113171923293137", BefungeInterpreter.Interpret(befungeCode));
        }
Example #6
0
        public void HandleRandomDirection()
        {
            string output = BefungeInterpreter.Interpret("v@.<\n >1^\n>?<^\n >2^");

            Assert.True("1" == output || "2" == output);
        }
Example #7
0
 public void PrintHelloWorld()
 {
     Assert.Equal("Hello World!\n", BefungeInterpreter.Interpret(">25*\"!dlroW olleH\":v\n                v:,_@\n                >  ^"));
     Assert.Equal("Hello World!", BefungeInterpreter.Interpret("v>  ,,,,,,,,,,,,@\n<^\"Hello World!\""));
 }
Example #8
0
 public void HandleLogicalNot()
 {
     Assert.Equal("0", BefungeInterpreter.Interpret("9!.@"));
     Assert.Equal("1", BefungeInterpreter.Interpret("0!.@"));
 }
Example #9
0
 public void HandleFactorial()
 {
     Assert.Equal("40320", BefungeInterpreter.Interpret("08>:1-:v v *_$.@ \n  ^    _$>\\:^  ^    _$>\\:^"));
 }
Example #10
0
 public void HandleDirectionChanges()
 {
     Assert.Equal("123456789", BefungeInterpreter.Interpret(">987v>.v\nv456<  :\n>321 ^ _@"));
 }
Example #11
0
 public void HandleMultipleInstructions(string testInput, string expectedOutput)
 {
     Assert.Equal(expectedOutput, BefungeInterpreter.Interpret(testInput));
 }
Example #12
0
 public void AddTwoNumbers()
 {
     Assert.Equal("3", BefungeInterpreter.Interpret("21+.@"));
 }
Example #13
0
 public void ReadAndReturnANumber()
 {
     Assert.Equal("9", BefungeInterpreter.Interpret("9.@"));
 }
Example #14
0
 public void HandlePowerOf2(int i, string res)
 {
     Assert.Equal(res, BefungeInterpreter.Interpret(">" + i + " : 2v2:    <\n      `      /\n      !      2 \n@,\"t\" _  :2%!|\n             >\"f\",@"));
 }
Example #15
0
 /// <summary>
 /// A befunge interpreter function that takes a string of befungeCode and returns any output
 /// </summary>
 /// <param name="inputBefungeCode"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public string FunctionHandler(string inputBefungeCode, ILambdaContext context)
 {
     return(BefungeInterpreter.Interpret(inputBefungeCode));
 }