示例#1
0
        public void TestSink()
        {
            DataDictionary init = new DataDictionary
            {
                { "resource_id", "coal" },
                { "consumption", 75.0f }
            };
            var jm2 = new JM2Sink(init);

            Assert.AreEqual("sink", jm2.Id);
            Allocate("coal", 100.0f);

            jm2.DescribeDemand(_time, _demand);
            Assert.AreEqual(75.0f, _demand["coal"]);

            jm2.Step(_stocks, _time, _allocator, _cell, _output);

            Assert.AreEqual(25.0f, _stocks["coal"]);
            Assert.AreEqual(1.0f, jm2.Efficiency);

            // One more time: reach 0 stock
            // Note that we allocate more than what is available, it's OK, the code is robust enough
            jm2.Step(_stocks, _time, _allocator, _cell, _output);
            Assert.AreEqual(0.0f, _stocks["coal"]);
            Assert.AreEqual(25.0f / 75.0f, jm2.Efficiency);
        }
示例#2
0
        public void TestSinkWithLimit()
        {
            DataDictionary init = new DataDictionary
            {
                { "resource_id", "coal" },
                { "limit", 50 },
                { "consumption", 100.0f }
            };
            var jm2 = new JM2Sink(init);

            Assert.AreEqual("sink", jm2.Id);
            Allocate("coal", 50.0f);

            jm2.Step(_stocks, _time, _allocator, _cell, _output);

            Assert.AreEqual(50.0f, _stocks["coal"]); // Because we reached the limit
            Assert.AreEqual(0.5f, jm2.Efficiency);
        }
示例#3
0
        public void TestSinkWithLowAllocation()
        {
            DataDictionary init = new DataDictionary
            {
                { "resource_id", "coal" },
                { "consumption", 100.0f }
            };
            var jm2 = new JM2Sink(init);

            Assert.AreEqual("sink", jm2.Id);
            Allocate("coal", 50.0f);

            jm2.DescribeDemand(_time, _demand);
            Assert.AreEqual(100.0f, _demand["coal"]);

            jm2.Step(_stocks, _time, _allocator, _cell, _output);

            Assert.AreEqual(50.0f, _stocks["coal"]);
            Assert.AreEqual(0.5f, jm2.Efficiency);
        }