Пример #1
0
        public void Put_SameEvent()
        {
            var store = Sim.FilterStore <int>(Env);

            Env.Process(StorePutter_SameEvent(store));
            Env.Run(until: 100);
        }
Пример #2
0
        SimEvents Simple_PEM()
        {
            var filterStore = Sim.FilterStore <string>(Env, 2);
            var getEv       = filterStore.Get(i => i == "b");

            yield return(filterStore.Put("a"));

            Assert.False(getEv.Succeeded);
            yield return(filterStore.Put("b"));

            Assert.True(getEv.Succeeded);
        }
Пример #3
0
        public void ProducerConsumer_OneProducer_OneConsumer_UnboundedCapacity()
        {
            var store = Sim.FilterStore <int>(Env);

            Env.Process(StorePutter(store, 10, 1));
            Env.Process(StoreGetter(store, 10, 1));
            Env.Run(until: 100);
            Assert.AreEqual(0, store.Count);
            Assert.AreEqual(0, store.ItemQueue.Count());
            Assert.AreEqual(int.MaxValue, store.Capacity);
            Assert.IsEmpty(store.GetQueue);
            Assert.IsEmpty(store.PutQueue);
        }
Пример #4
0
        public void ProducerConsumer_OneProducer_OneConsumer_BoundedCapacity()
        {
            var store = Sim.FilterStore <int>(Env, 50);

            Env.Process(StorePutter(store, 100, 1));
            Env.Process(StoreGetter(store, 10, 10));
            Env.Run(until: 1000);
            Assert.AreEqual(50, store.Count);
            Assert.AreEqual(50, store.ItemQueue.Count());
            Assert.AreEqual(50, store.Capacity);
            Assert.IsEmpty(store.GetQueue);
            Assert.True(store.PutQueue.Count() == 1);
        }
Пример #5
0
        public void LastItemGoodForFilter()
        {
            var filterStore = Sim.FilterStore <int>(Env, 10);

            filterStore.Put(1);
            filterStore.Put(3);
            filterStore.Put(5);
            filterStore.Put(2);
            var getEv = filterStore.Get(i => i % 2 == 0);

            Env.Run();
            Assert.True(getEv.Succeeded);
            Assert.AreEqual(2, getEv.Value);
        }
Пример #6
0
        public void Put_InfiniteCapacity(int putCount)
        {
            var store = Sim.FilterStore <int>(Env);

            Assert.AreEqual(WaitPolicy.FIFO, store.ItemPolicy);
            Assert.AreEqual(WaitPolicy.FIFO, store.GetPolicy);
            Assert.AreEqual(WaitPolicy.FIFO, store.PutPolicy);
            Env.Process(StorePutter(store, putCount, 0));
            Env.Run(until: 100);
            Assert.AreEqual(putCount, store.Count);
            Assert.AreEqual(putCount, store.ItemQueue.Count());
            Assert.AreEqual(int.MaxValue, store.Capacity);
            Assert.IsEmpty(store.GetQueue);
            Assert.IsEmpty(store.PutQueue);
        }
Пример #7
0
        public void Put_BoundedCapacity(int putCount, int capacity)
        {
            Debug.Assert(putCount >= capacity);
            var store = Sim.FilterStore <int>(Env, capacity);

            Assert.AreEqual(WaitPolicy.FIFO, store.ItemPolicy);
            Assert.AreEqual(WaitPolicy.FIFO, store.GetPolicy);
            Assert.AreEqual(WaitPolicy.FIFO, store.PutPolicy);
            Env.Process(StorePutter(store, putCount, 0));
            Env.Run(until: 100);
            Assert.AreEqual(capacity, store.Count);
            Assert.AreEqual(capacity, store.ItemQueue.Count());
            Assert.AreEqual(capacity, store.Capacity);
            Assert.IsEmpty(store.GetQueue);
            Assert.True(store.PutQueue.Count() == 1);
        }
Пример #8
0
        public void ItemPolicy_Priority_Decreasing(int eventCount)
        {
            var store = Sim.FilterStore <int>(Env, eventCount, WaitPolicy.FIFO, WaitPolicy.FIFO, WaitPolicy.Priority);

            for (var i = 0; i < eventCount; ++i)
            {
                store.Put(i, 0, -i);
            }
            var list = new List <int>();

            for (var i = 0; i < eventCount; ++i)
            {
                store.Get().Callbacks.Add(e => list.Add(e.Value));
            }
            Env.Run();
            for (var i = 0; i < eventCount; ++i)
            {
                Assert.AreEqual(eventCount - i - 1, list[i]);
            }
        }
Пример #9
0
        public void ItemPolicy_Fifo(int eventCount)
        {
            var store = Sim.FilterStore <int>(Env, eventCount);

            for (var i = 0; i < eventCount; ++i)
            {
                store.Put(i);
            }
            var list = new List <int>();

            for (var i = 0; i < eventCount; ++i)
            {
                store.Get().Callbacks.Add(e => list.Add(e.Value));
            }
            Env.Run();
            for (var i = 0; i < eventCount; ++i)
            {
                Assert.AreEqual(i, list[i]);
            }
        }
Пример #10
0
        public void GetPolicy_Priority_Decreasing(int eventCount)
        {
            var store = Sim.FilterStore <int>(Env, eventCount, WaitPolicy.Priority, WaitPolicy.FIFO);
            var list  = new List <Tuple <int, int> >();

            for (var i = 0; i < eventCount; ++i)
            {
                var tmpI = i;
                store.Get(-i).Callbacks.Add(e => list.Add(Tuple.Create(tmpI, e.Value)));
            }
            for (var i = 0; i < eventCount; ++i)
            {
                store.Put(i);
            }
            Env.Run();
            Assert.AreEqual(eventCount, list.Count);
            for (var i = 0; i < eventCount; ++i)
            {
                Assert.AreEqual(i, list[eventCount - i - 1].Item1);
                Assert.AreEqual(i, list[i].Item2);
            }
        }
Пример #11
0
        public void PutPolicy_Priority_Increasing(int eventCount)
        {
            var store = Sim.FilterStore <int>(Env, eventCount, WaitPolicy.FIFO, WaitPolicy.Priority);
            var list  = new List <int>();

            for (var i = 0; i < eventCount; ++i)
            {
                store.Put(i);
            }
            for (var i = 0; i < eventCount; ++i)
            {
                store.Put(i, i).Callbacks.Add(e => list.Add(e.Item));
            }
            for (var i = 0; i < eventCount; ++i)
            {
                store.Get();
            }
            Env.Run();
            Assert.AreEqual(eventCount, list.Count);
            for (var i = 0; i < eventCount; ++i)
            {
                Assert.AreEqual(i, list[i]);
            }
        }
Пример #12
0
 public void Construction_RightType()
 {
     Assert.IsInstanceOf(typeof(FilterStore <int>), Sim.FilterStore <int>(Env));
 }