Exemplo n.º 1
0
        public void SingleCase()
        {
            var data     = StaticTestData.GetTestCase("Simple");
            var game     = new StringReader(data.Script);
            var compiler = Compiler.Compile("unknown", game, Console.Out);

            Assert.IsTrue(compiler.Success, data.Title);
            compiler.Model.Execute("1", data.Inputs);
            Assert.IsTrue(compiler.Success, data.Title);
        }
Exemplo n.º 2
0
        public void SettingColour()
        {
            var setup =
                "(pre):background_color green;" +
                "@(win):;";
            var testcase = StaticTestData.GetTestCase("PRBG", "PRBG bare", setup);
            var engine   = SetupEngine(testcase);

            // assume default palette
            Assert.AreEqual(0xbe2633, engine.GameDef.GetRGB(8));
            Assert.AreEqual(0x44891a, engine.GameDef.GetRGB(16));
            Assert.AreEqual(0x44891a, engine.GameDef.GetColour(OptionSetting.background_color, 0));
        }
Exemplo n.º 3
0
        // compile the script
        protected Compiler DoCompile(string name, string title, string setup)
        {
            var testcase = StaticTestData.GetTestCase(name, title, setup);

            Logger.Level = 0;
            var game     = new StringReader(testcase.Script);
            var compiler = Compiler.Compile(testcase.Title, game, Console.Out);

            Logger.Level = 2;
            Assert.IsTrue(compiler.Success, compiler.Message);
            compiler.Model.AcceptInputs("level 0");
            return(compiler);
        }
Exemplo n.º 4
0
 void DoTests(string title, string variations, string template, string[,] tests, [CallerMemberName] string method = "")
 {
     foreach (var variation in variations.Split(';'))
     {
         var setup    = String.Format(template, variation);
         var testcase = StaticTestData.GetTestCase("PRBG", title + ":" + method, setup);
         var engine   = SetupEngine(testcase);
         for (int i = 0; i < tests.GetLength(0); i++)
         {
             DoTest(engine, tests[i, 0], tests[i, 1], variation);
         }
     }
 }
Exemplo n.º 5
0
 void DoExpansionTests(string testbase, string template, int count, Func <int, string> expecteds, Func <int, string> actuals,
                       [CallerMemberName] string method = "")
 {
     for (int i = 0; i < count; i++)
     {
         var nexp  = expecteds(i).Split(';').Length;
         var tcexp = StaticTestData.GetTestCase(testbase, testbase + ":" + method, template.Fmt(expecteds(i)));
         var exp   = GetRuleExpansions(tcexp);
         var tcact = StaticTestData.GetTestCase(testbase, testbase + ":" + method, template.Fmt(actuals(i)));
         var act   = GetRuleExpansions(tcact);
         Assert.AreEqual(nexp, exp.Count, actuals(i));
         Assert.AreEqual(nexp, act.Count, actuals(i));
         for (var j = 0; j < nexp; j++)
         {
             Assert.AreEqual(exp[j].After(":"), act[j].After(":"), actuals(i));
         }
     }
 }
Exemplo n.º 6
0
        public void BasicLegend()
        {
            var setup =
                "(rul):[> p|r]->[> p|> r];" +
                "@(leg):. = Background;a = R and K;o = R or G or B or Y;" +
                "[ = r; | = b; ] = g;" +
                "@(lev):.P.[|].;" +
                "@(win):;";
            var tests = new string[, ] {
                { "restart", "0; right; 1  12 1  13 14 15 1 end" },
            };

            var testcase = StaticTestData.GetTestCase("PRBG", "PRBG bare", setup);
            var engine   = SetupEngine(testcase);

            for (int i = 0; i < tests.GetLength(0); i++)
            {
                DoTest(engine, tests[i, 0], tests[i, 1]);
            }
        }
Exemplo n.º 7
0
        public void BasicPush()
        {
            var setup =
                "(rul):[> p|r]->[> p|> r];" +
                "[< p|r]->[< p|< r];" +
                "[^ p|r]->[< p|> r];" +
                "[v p|r]->[  p|> r];" +
                "@(lev):..P.R..;" +
                "@(win):;";
            var tests = new string[, ] {
                { "restart", "0; right; 1 1  12 1  13 1  1 end" },
                { "restart,action", "0; right; 1 1  12 1  13 1  1 end" },
                { "restart,hover", "0; right; 1 1  12 1  13 1  1 end" },
                { "restart,fire1", "0; right; 1 1  12 1  13 1  1 end" },
                { "restart,fire2", "0; right; 1 1  12 1  13 1  1 end" },
                { "restart,fire3", "0; right; 1 1  12 1  13 1  1 end" },
                { "restart,up", "0; right; 1 1  12 1  13 1  1 end" },
                { "restart,down", "0; right; 1 1  12 1  13 1  1 end" },
                { "restart,left", "0; right; 1 12 1  1  13 1  1 end" },
                { "restart,right", "0; right; 1 1  1  12 13 1  1 end" },
                { "restart,right,right", "0; right; 1 1  1  1  12 13 1 end" },
                { "restart,right,right,right", "0; right; 1 1  1  1  1  12 13 end" },
                { "restart,right,right,right,right", "0; right; 1 1  1  1  1  12 13 end" },
                { "restart,right,left", "0; right; 1 1  12 13 1  1  1 end" },
                { "restart,right,left,left", "0; right; 1 12 13 1  1  1  1 end" },
                { "restart,right,up", "0; right; 1 1  12 1  1  13  1 end" },
                { "restart,right,up,up", "0; right; 1 1  12 1  1  13  1 end" },
                { "restart,right,down", "0; right; 1 1  1  12 1  13  1 end" },
                { "restart,right,down,down", "0; right; 1 1  1  12 1  13  1 end" },
            };

            var testcase = StaticTestData.GetTestCase("PRBG", "PRBG bare", setup);
            var engine   = SetupEngine(testcase);

            for (int i = 0; i < tests.GetLength(0); i++)
            {
                DoTest(engine, tests[i, 0], tests[i, 1]);
            }
        }
Exemplo n.º 8
0
        public void SpriteSizeText()
        {
            var setup =
                "(pre):;" +
                "@(obj):Background;black;;PLAYER P;white;;R;RED;;B;BLUE;;G;green;;Y;yellow;;K;Pink;;" +
                "obj2x2;Black White;.0;1.;;" +
                "obj8a;Black White Grey DarkGrey LightGrey Gray DarkGray LightGray;012;345;670;;" +
                "obj8b;Red DarkRed LightRed Brown DarkBrown LightBrown Orange Yellow;012;345;670;;" +
                "obj8c;Green DarkGreen LightGreen Blue LightBlue DarkBlue Purple Pink;012;345;670;;" +
                "objs left 0.5;Red;0.;.0;;" +
                "objt 0.5;Red green;message hello world!;;" +
                "@(col):Background;Y;Player,R,B,G;K;obj2x2,obj8a,obj8b,obj8c,objs,objt;" +
                "";

            var testcase = StaticTestData.GetTestCase("PRBG", "PRBG bare", setup);
            var engine   = SetupEngine(testcase);

            CheckObject(engine.GameDef.GetObject(1), "Background", 1, 1.0f, 1, "0", 0, null);
            CheckObject(engine.GameDef.GetObject(2), "PLAYER", 3, 1.0f, 1, "1", 1, null);
            CheckObject(engine.GameDef.GetObject(8), "obj2x2", 5, 1.0f, 2, "-1,0,1,-1", 1, null);
            CheckObject(engine.GameDef.GetObject(9), "obj8a", 5, 1.0f, 3, "0,1,2,3,4,5,6,7,0", 7, null);
            CheckObject(engine.GameDef.GetObject(12), "objs", 5, 0.5f, 2, "8,-1,-1,8", 8, null);
            CheckObject(engine.GameDef.GetObject(13), "objt", 5, 0.5f, 1, "8", 16, "hello world!");
        }