示例#1
0
        public void Item()
        {
            SpecificationFamily family = new SpecificationFamily();

            for (int x = 1; x < 6; x++)
            {
                int X = x;
                TemporalSpecification RItem = new Unless(G => G.dungeon.items.Count == X, G => G.dungeon.items.Count < X);
                family.add(RItem);
            }
            Assert.AreEqual(Judgement.RelevantlyValid, family.evaluate(testsuites, threshold));
        }
示例#2
0
        public void test_player_heal()
        {
            int l, c, m;

            for (int k = 1; k < 9; k++)
            {
                if (k < 5)
                {
                    l = 5;
                }
                else
                {
                    l = 10;
                }
                if (k % 2 == 0)
                {
                    c = 3;
                }
                else
                {
                    c = 2;
                }
                if (k == 3 || k == 4 || k == 7 || k == 8)
                {
                    m = 50;
                }
                else
                {
                    m = 30;
                }
                g        = new Game(l, c, m, true);
                gs       = new Gamestate(g);
                savegame = new Savegame(gs);
                for (int j = 1; j < 6; j++)
                {
                    int previousHP      = g.dungeon.player.HPbase;
                    int previousPotions = 0;
                    path = @"C:/Users/Gebruiker/Documents/GitHub/Software-Testing-Assignment-2/STVRogue/Gameplays/game" + k + "/game" + k + "_turn";
                    Unless unless = new Unless(G => G.dungeon.player.HP <= previousHP, G => G.dungeon.player.HP > previousHP && G.dungeon.player.bag.OfType <HealingPotion>().Count() == previousPotions - 1);
                    for (int i = 0; i < gameturns[k - 1]; i++)
                    {
                        data = savegame.OpenFile(i, path);
                        Gamestate gamestate = new Gamestate(g, data);
                        Assert.True(unless.test(g));
                        previousHP      = gamestate.g.dungeon.player.HP;
                        previousPotions = gamestate.g.dungeon.player.bag.OfType <HealingPotion>().Count();
                    }
                }
            }
        }
示例#3
0
        public void UnlessPredicate()
        {
            List <GamePlay> plays = loadSavedGamePlays(allReplays);

            foreach (GamePlay gp in plays)
            {
                // test that this specifation is respected by each game-play:
                int           M = (int)gp.numberOfMonsters;
                Specification S = new Unless(G => countMonsters(G) == M, G => countMonsters(G) < M);
                Console.WriteLine("Test");
                gp.replay(S);
                Assert.IsTrue(S.getVerdict());
            }
        }
示例#4
0
        public void Decay()
        {
            //RDecay: when the game has no item left(lying around in nodes nor in the player’s bag), the player’s HP can only decrease.

            int[] HPValues             = new int[] { 2, 4, 6, 8, 10 };
            SpecificationFamily family = new SpecificationFamily();

            foreach (int x in HPValues)
            {
                int X = x;
                TemporalSpecification RDecay = new Unless(G => G.player.HP == X && (G.dungeon.items.Count <= 0 && G.player.bag.Count <= 0), G => G.player.HP < X);
                family.add(RDecay);
            }
            Assert.AreEqual(Judgement.RelevantlyValid, family.evaluate(testsuites, threshold));
        }
示例#5
0
        public void When(When when, Act action, Unless unless = null)
        {
            foreach (var cw in Whens)
            {
                if (cw.When == when && cw.Action == action && cw.Unless == unless)
                {
                    return;
                }
            }
            WhenInfo wi = new WhenInfo();

            wi.When   = when;
            wi.Action = action;
            wi.Unless = unless;
            Whens.Add(wi);
        }
示例#6
0
        public void test_monsters_never_increase()
        {
            int l, c, m;

            for (int k = 1; k < 9; k++)
            {
                if (k < 5)
                {
                    l = 5;
                }
                else
                {
                    l = 10;
                }
                if (k % 2 == 0)
                {
                    c = 3;
                }
                else
                {
                    c = 2;
                }
                if (k == 3 || k == 4 || k == 7 || k == 8)
                {
                    m = 50;
                }
                else
                {
                    m = 30;
                }
                g        = new Game(l, c, m, true);
                gs       = new Gamestate(g);
                savegame = new Savegame(gs);
                for (int j = 1; j < 6; j++)
                {
                    path = @"C:/Users/Gebruiker/Documents/GitHub/Software-Testing-Assignment-2/STVRogue/Gameplays/game" + k + "/game" + k + "_turn";
                    Unless unless = new Unless(G => G.dungeon.numberOfMonsters > G.dungeon.countMonsters(), G => G.dungeon.numberOfMonsters == G.dungeon.countMonsters());
                    for (int i = 0; i < gameturns[k - 1]; i++)
                    {
                        data = savegame.OpenFile(i, path);
                        Gamestate gamestate = new Gamestate(g, data);
                        Assert.True(unless.test(g));
                    }
                }
            }
        }
示例#7
0
        public void monsterHP()
        {
            //RMonster: The HP of every monster can only decrease, and it never leaves its zone.

            SpecificationFamily family = new SpecificationFamily();


            for (int I = 1; I < 5; I++)
            {
                int    i   = I;
                string mid = "M" + i;
                for (int x = 1; x < 6; x += 2) //max hp = 5, player attack = 2 of 4
                {
                    int X = x;
                    TemporalSpecification RMonster1 = new Unless(G => G.getMonster(mid) != null && G.getMonster(mid).HP == X, G => G.getMonster(mid).HP < X);
                    family.add(RMonster1);
                }
            }
            Assert.AreEqual(Judgement.RelevantlyValid, family.evaluate(testsuites, threshold));
        }
示例#8
0
 public static void SetupBuiltins(SymbolSpace space)
 {
     globalSpace = space;
     Unless.Setup();
     When.Setup();
     If.Setup();
     Let.Setup();
     Equal.Setup();
     Bind.Setup();
     DerefSymbol.Setup();
     Evaluate.Setup();
     In.Setup();
     Print.Setup();
     Negate.Setup();
     Quote.Setup();
     Unquote.Setup();
     MakeSpace.Setup();
     Def.Setup();
     Get.Setup();
     Add.Setup();
     Defn.Setup();
 }
示例#9
0
        public void Alive()
        {
            TemporalSpecification RAlive = new Unless(G => G.player.HP > 0, G => G.player.inCombat);

            Assert.AreEqual(Judgement.RelevantlyValid, RAlive.evaluate(testsuites, threshold));
        }
示例#10
0
        static void Main(string[] args)
        {
            Console.Write("=== "); Console.Write("Cake", ConsoleColor.Red); Console.Write("Lang", ConsoleColor.White); Console.WriteLine(" Demo ===");

            Console.WriteLine("For version: " + CakeLang.CakeLang.Version.ToString() + '\n', ConsoleColor.DarkYellow);

            // --- Data Pack Code -----------------------------------------

            DataPack demoPack = new DataPack("Demo Pack", "A demonstration of CakeLang!", "demopack");

            string message = "Hello friend";

            demoPack.Functions.Add(new Function("fun2",
                                                AsAt("s", Run(
                                                         Tellraw('s', JSON.Text(message, JSON.StyleFormattings.Color(Colors.Aqua), JSON.StyleFormattings.Bold))
                                                         ))
                                                ));
            demoPack.Functions.Add(new Function("flying",
                                                If.Block("~ ~-1 ~", Namespace("air"),
                                                         Run(
                                                             Tellraw('s', JSON.Text("Bro, you're flying!", JSON.StyleFormattings.Color(Colors.Yellow), JSON.StyleFormattings.Italic))
                                                             )
                                                         ),
                                                Unless.Block("~ ~-1 ~", Namespace("air"),
                                                             Run(
                                                                 Tellraw('s', JSON.Text("Nah, not flyin' yet", JSON.StyleFormattings.Color(Colors.Yellow), JSON.StyleFormattings.Underlined))
                                                                 )
                                                             )
                                                ));

            ArgumentsFunction introduce = new ArgumentsFunction("introduce", new System.Collections.Generic.Dictionary <string, Type>()
            {
                ["name"]     = typeof(string),
                ["position"] = typeof(float[])
            },
                                                                Tellraw(Selector.Executor, JSON.ArrayBuilder(
                                                                            JSON.Text("My name is ", JSON.StyleFormattings.Bold, JSON.StyleFormattings.Color(Colors.Gold)),
                                                                            JSON.FunctionVariable("introduce", "name", JSON.StyleFormattings.Italic, JSON.StyleFormattings.Color(Colors.Yellow)),
                                                                            JSON.Text(", I'm at ", JSON.StyleFormattings.Bold, JSON.StyleFormattings.Color(Colors.Gold)),
                                                                            JSON.FunctionVariable("introduce", "position[0]", JSON.StyleFormattings.Italic, JSON.StyleFormattings.Color(Colors.Yellow)),
                                                                            JSON.Text(" "),
                                                                            JSON.FunctionVariable("introduce", "position[1]", JSON.StyleFormattings.Italic, JSON.StyleFormattings.Color(Colors.Yellow)),
                                                                            JSON.Text(" "),
                                                                            JSON.FunctionVariable("introduce", "position[2]", JSON.StyleFormattings.Italic, JSON.StyleFormattings.Color(Colors.Yellow)),
                                                                            JSON.Text(" "),
                                                                            JSON.Text("!", JSON.StyleFormattings.Bold, JSON.StyleFormattings.Color(Colors.Gold))
                                                                            ))
                                                                );

            demoPack.Functions.Add(introduce);

            demoPack.Functions.Add(new Function("introducePeople",
                                                introduce.Call("Jeff", new[] { 0.5f, 2f, -4f }),
                                                introduce.Call("Monica", new[] { 0, 0, 0 }),
                                                introduce.Call("Boobo", new[] { 6, 6, 9, -2 })
                                                ));

            // --- Data Pack Code -----------------------------------------

            try
            {
                demoPack.CompileAndInject("CakeLang Demo");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message, ConsoleColor.Red);
            }
        }