Ejemplo n.º 1
0
        public void CallTransactionFunctionOnCreditCardTest()
        {
            var lines = new List <string>();

            CreditCard card = _world.tingRunner.CreateTing <CreditCard> ("Visa", testDefaultCoordinate);

            //card.logger.AddListener (o => Console.WriteLine ("Card log: " + o));
            card.AddDataListener("dialogueLine", (string oldValue, string newValue) => {
                lines.Add(newValue);
                Console.WriteLine("Card said: " + newValue);
            });
            card.masterProgramName = "EvasCard";

            Computer financeComputer = _world.tingRunner.CreateTing <Computer>("FinanceComputer", testDefaultCoordinate);

            financeComputer.masterProgramName = "FinanceComputer";
            financeComputer.hasMemoryAPI      = true;
            financeComputer.masterProgram.Start();

            WorldTestHelper.UpdateWorld(_world, 3f);
            card.RunMakeTransactionFunction(-3.5f);
            WorldTestHelper.UpdateWorld(_world, 3f);

            Assert.AreEqual(1, lines.Count);
            Assert.AreEqual("Will make transaction: -3.5", lines[0]);

            Assert.AreEqual(false, card.containsBrokenPrograms);
            Assert.AreEqual(false, financeComputer.containsBrokenPrograms);
        }
Ejemplo n.º 2
0
        public void CallCheckBalanceFunctionOnCreditCardTest()
        {
            var lines = new List <string>();

            CreditCard card = _world.tingRunner.CreateTing <CreditCard> ("Visa", testDefaultCoordinate);

            card.logger.AddListener(o => Console.WriteLine("Card log: " + o));
            card.AddDataListener("dialogueLine", (string oldValue, string newValue) => {
                lines.Add(newValue);
                Console.WriteLine("Card said: " + newValue);
            });
            card.masterProgramName = "EvasCard";

            Computer financeComputer = _world.tingRunner.CreateTing <Computer>("FinanceComputer", testDefaultCoordinate);

            financeComputer.masterProgramName = "FinanceComputer";
            financeComputer.hasMemoryAPI      = true;
            financeComputer.masterProgram.Start();

            WorldTestHelper.UpdateWorld(_world, 3f);
            card.RunMakeTransactionFunction(100.0f);
            WorldTestHelper.UpdateWorld(_world, 3f);
            card.PushButton(null);
            WorldTestHelper.UpdateWorld(_world, 3f);

//			object cashAmount = null;
//			bool gotIt = financeComputer.memory.data.TryGetValue("Eva", out cashAmount);
//			Assert.IsTrue(cashAmount);

            Assert.AreEqual(5, lines.Count);
            Assert.AreEqual("Will make transaction: 100", lines[0]);
            Assert.AreEqual("", lines[1]);
            Assert.AreEqual("id = 0", lines[2]);
            Assert.AreEqual("", lines[3]);
            Assert.AreEqual("Balance: 100", lines[4]);

            Assert.AreEqual(false, card.containsBrokenPrograms);
            Assert.AreEqual(false, financeComputer.containsBrokenPrograms);
        }
Ejemplo n.º 3
0
        public void CheckBalance()
        {
            WorldCoordinate testDefaultCoordinate = new WorldCoordinate("Eden", IntPoint.Zero);

            WorldTestHelper.GenerateInitData();
            InitialSaveFileCreator i = new InitialSaveFileCreator();
            World world = new World(i.CreateRelay(WorldTestHelper.INIT_DATA_PATH));

            D.onDLog += o => Console.WriteLine("D.Log: " + o);
            world.dialogueRunner.AddOnSomeoneSaidSomethingListener(o => Console.WriteLine("Dialogue: " + o));

            CreditCard card = world.tingRunner.CreateTing <CreditCard> ("Visa", testDefaultCoordinate);

            card.logger.AddListener(o => Console.WriteLine("Card log: " + o));
            card.AddDataListener("dialogueLine", (string oldValue, string newValue) => {
                Console.WriteLine("Card said: " + newValue);
            });
            card.nameOfOwner       = "Eva";
            card.masterProgramName = "EvasCard";

            Computer financeComputer = world.tingRunner.CreateTing <Computer>("FinanceComputer", testDefaultCoordinate);

            financeComputer.masterProgramName = "FinanceComputer";
            financeComputer.hasMemoryAPI      = true;
            financeComputer.masterProgram.Start();

            WorldTestHelper.UpdateWorld(world, 3f);
            card.RunMakeTransactionFunction(100.0f);
            WorldTestHelper.UpdateWorld(world, 3f);

            Console.WriteLine("Evas card errors: ");
            foreach (var error in card.masterProgram.GetErrors())
            {
                Console.WriteLine(error.ToString());
            }

            Console.WriteLine("Finance computer errors: ");
            foreach (var error in financeComputer.masterProgram.GetErrors())
            {
                Console.WriteLine(error.ToString());
            }

            Console.WriteLine("Finance computer output: ");
            PrintOutput(financeComputer);

            Assert.IsNotNull(financeComputer.memory);
            Assert.IsNotNull(financeComputer.memory.data);

            object cashAmount = null;
            bool   gotIt      = financeComputer.memory.data.TryGetValue("Eva", out cashAmount);

            Assert.IsTrue(gotIt);
            Assert.AreEqual(typeof(float), cashAmount.GetType());
            Assert.AreEqual(100.0f, (float)cashAmount);

            card.RunMakeTransactionFunction(-20.0f);
            WorldTestHelper.UpdateWorld(world, 1.0f);

            Assert.IsNotNull(financeComputer.memory);
            Assert.IsNotNull(financeComputer.memory.data);

            object cashAmount2 = null;
            bool   gotIt2      = financeComputer.memory.data.TryGetValue("Eva", out cashAmount2);

            Assert.IsTrue(gotIt2);
            Assert.AreEqual(80.0f, (float)cashAmount2);
        }