コード例 #1
0
ファイル: TestResources.cs プロジェクト: stuarthillary/Sage-1
        public void TestMaterialConduits()
        {
            Model model = new Model("Conduit Testing Model...");

            _Debug.WriteLine("Test results of replenishable material inventories.");

            Hashtable            materialInventory1 = new Hashtable();
            Hashtable            materialInventory2 = new Hashtable();
            Hashtable            materialInventory3 = new Hashtable();
            MaterialType         WaterType          = new MaterialType(model, "Water", Guid.NewGuid(), 1.0, 1.0, MaterialState.Liquid);
            MaterialType         NaClType           = new MaterialType(model, "SodiumChloride", Guid.NewGuid(), 1.2, 1.8, MaterialState.Solid);
            MaterialResourceItem WaterItem          = new MaterialResourceItem(model, WaterType, 500, 20, 1000);
            MaterialResourceItem NaClItem           = new MaterialResourceItem(model, NaClType, 100, 20, 250);

            _Debug.WriteLine("Setting up an inventory of 500 liters Water, capacity of 1000 liters in materialInventory1.");
            materialInventory1.Add(WaterType, WaterItem);

            _Debug.WriteLine("Setting up an inventory of 100 liters SodiumChloride, capacity of 250 liters in materialInventory1.");
            materialInventory1.Add(NaClType, NaClItem);

            _Debug.WriteLine("Setting up an inventory of 750 liters Water, capacity of 1500 liters in materialInventory2.");
            materialInventory2.Add(WaterType, new MaterialResourceItem(model, WaterType, 750, 20, 1500));

            _Debug.WriteLine("Setting up an inventory of 400 liters SodiumChloride, capacity of 800 liters in materialInventory3.");
            materialInventory3.Add(NaClType, new MaterialResourceItem(model, NaClType, 400, 20, 800));

            // AEL, not sure why thest lines don't matter in the test. I probably miss something.
//			MaterialConduitManager mcm = new MaterialConduitManager(materialInventory1);
//			mcm.AddConduit(materialInventory2,WaterType);
//			mcm.AddConduit(materialInventory3,NaClType);

            Enum augment = MaterialResourceRequest.Direction.Augment;
            Enum deplete = MaterialResourceRequest.Direction.Deplete;

            object[,] tests = new object[, ] {
                { WaterType, 150, augment, true }
                , { WaterType, 250, deplete, true }
                , { WaterType, 350, augment, true }
                , { NaClType, 200, deplete, false }
                , { WaterType, 100, deplete, true }
                , { NaClType, 300, augment, false }
                , { WaterType, 200, deplete, true }
                , { NaClType, 300, augment, false }
                , { WaterType, 100, deplete, true }
                , { NaClType, 250, deplete, false }
                , { NaClType, 1000, augment, false }
            };
            MaterialResourceRequest mrr;

            _Debug.WriteLine("");
            for (int i = 0; i < tests.GetLength(0); i++)
            {
                #region >>> Set up test parameters from array. <<<
                MaterialType mt       = (MaterialType)tests[i, 0];
                double       quantity = Convert.ToDouble(tests[i, 1]);
                MaterialResourceRequest.Direction direction = (MaterialResourceRequest.Direction)tests[i, 2];
                string itemName           = (mt.Equals(WaterType)?"WaterItem":"NaClItem");
                MaterialResourceItem item = (mt.Equals(WaterType)?WaterItem:NaClItem);
                bool expected             = (bool)tests[i, 3];
                #endregion

                string testDescription = "Test " + (i + 1) + ": Trying to " + (direction.Equals(augment)?"augment":"deplete") + " " + quantity + " liters of " + itemName + ".";
                _Debug.WriteLine(testDescription);
                _Debug.WriteLine("Before - " + itemName + " has " + item.Available + " liters, and a capacity of " + item.Capacity + ".");
                mrr = new MaterialResourceRequest(mt, quantity, direction);
                MaterialResourceItem mri = (MaterialResourceItem)materialInventory1[mt];
                bool result = mri.Acquire(mrr, false);
                _Debug.Write((result?"Request honored.":"Request denied."));
                _Debug.Assert(result == expected, "This test is a failure");
                _Debug.WriteLine(((result == expected)?" - this was expected.":" - THIS IS A TEST FAILURE!"));
                _Debug.Assert(result == expected, testDescription);
                _Debug.WriteLine("After - " + itemName + " has " + item.Available + " liters, and a capacity of " + item.Capacity + ".");
                _Debug.WriteLine("");
            }
        }
コード例 #2
0
ファイル: TestResources.cs プロジェクト: stuarthillary/Sage-1
        public void TestConsumableResourceBasics()
        {
            Model model = new Model("Resource Testing Model...");

            _Debug.WriteLine("Test results of replenishable material inventories.");

            Hashtable materialInventory = new Hashtable();

            _Debug.WriteLine("Setting up an inventory of 500 liters Water, capacity of 1000 liters.");
            MaterialType         waterType = new MaterialType(model, "Water", Guid.NewGuid(), 1.0, 1.0, MaterialState.Liquid, 18.0);
            MaterialResourceItem waterItem = new MaterialResourceItem(model, waterType, 500, 20, 1000);

            _Debug.WriteLine("Setting up an inventory of 100 liters SodiumChloride, capacity of 250 liters.");
            MaterialType         NaClType = new MaterialType(model, "SodiumChloride", Guid.NewGuid(), 1.2, 1.8, MaterialState.Liquid);
            MaterialResourceItem NaClItem = new MaterialResourceItem(model, NaClType, 100, 20, 250);

            materialInventory.Add(waterType, waterItem);
            materialInventory.Add(NaClType, NaClItem);

            Enum augment = MaterialResourceRequest.Direction.Augment;
            Enum deplete = MaterialResourceRequest.Direction.Deplete;

            object[,] tests = new object[, ] {
                { waterType, 150, augment, true }
                , { waterType, 250, deplete, true }
                , { waterType, 350, augment, true }
                , { NaClType, 200, deplete, false }
                , { waterType, 100, deplete, true }
                , { NaClType, 300, augment, false }
                , { waterType, 200, deplete, true }
                , { NaClType, 300, augment, false }
                , { waterType, 100, deplete, true }
                , { NaClType, 250, deplete, false }
                , { NaClType, 1000, augment, false }
            };
            MaterialResourceRequest mrr;

            _Debug.WriteLine("");
            for (int i = 0; i < tests.GetLength(0); i++)
            {
                #region >>> Set up test parameters from array. <<<
                MaterialType mt       = (MaterialType)tests[i, 0];
                double       quantity = Convert.ToDouble(tests[i, 1]);
                MaterialResourceRequest.Direction direction = (MaterialResourceRequest.Direction)tests[i, 2];
                string itemName           = (mt.Equals(waterType)?"WaterItem":"NaClItem");
                MaterialResourceItem item = (mt.Equals(waterType)?waterItem:NaClItem);
                bool expected             = (bool)tests[i, 3];
                #endregion

                string testDescription = "Test " + (i + 1) + ": Trying to " + (direction.Equals(augment)?"augment":"deplete") + " " + quantity + " liters of " + itemName + ".";
                _Debug.WriteLine(testDescription);
                _Debug.WriteLine("Before - " + itemName + " has " + item.Available + " liters, and a capacity of " + item.Capacity + ".");
                mrr = new MaterialResourceRequest(mt, quantity, direction);
                MaterialResourceItem mri = (MaterialResourceItem)materialInventory[mt];
                bool result = mri.Acquire(mrr, false);
                _Debug.Write((result?"Request honored.":"Request denied."));
                _Debug.Assert(result == expected, "This test is a failure");
                _Debug.WriteLine(((result == expected)?" - this was expected.":" - THIS IS A TEST FAILURE!"));
                _Debug.Assert(expected == result, testDescription);
                _Debug.WriteLine("After - " + itemName + " has " + item.Available + " liters, and a capacity of " + item.Capacity + ".");
                _Debug.WriteLine("");
            }
        }