Esempio n. 1
0
        public void MPCQuantityTest()
        {
            var coll  = new ManyPredicateCollection();
            var pred  = Predicates.ElementTypePredicate <int>();
            var quant = Quantifiers.Count(pred, 2);

            Assert.ThrowsException <InvalidPredicateException>(() => coll.AddQuant(quant));
            coll.Add(1);
            Assert.ThrowsException <InvalidPredicateException>(() => coll.AddQuant(quant));
            coll.Add(2);
            coll.AddQuant(quant);
            Assert.IsTrue(new int[] { 1, 2 }.SequenceEqual(coll.Get(pred)));
            coll.Add(1, 2); // Repeated elements, ok
            Assert.ThrowsException <InvalidElementException>(() => coll.Add(3));
            Assert.IsTrue(new int[] { 1, 2 }.SequenceEqual(coll.Get(pred)));
        }
Esempio n. 2
0
        public void MPCPropertyTest1()
        {
            var coll = new ManyPredicateCollection();

            var typePred  = Predicates.ElementTypePredicate <CustomType1 <int> >();
            var typeQuant = Quantifiers.All(typePred);

            // Two equivalent predicates. The second one is converted to the first one.
            var propPred1 = new Predicate((object elem) => !(elem is CustomType1 <int>) ||
                                          ((CustomType1 <int>)elem).Value == 2);
            var propQuant1 = Quantifiers.All(propPred1);

            var propPred1Typed = new ForTypePredicate <CustomType1 <int> >((CustomType1 <int> elem) => elem.Value == 2)
                                 .ToPredicate();
            var propQuant1Typed = Quantifiers.All(propPred1Typed);

            var propPred2  = new Predicate((object elem) => ((CustomType1 <int>)elem).Prop);
            var propQuant2 = Quantifiers.All(propPred2);

            coll.AddQuant(typeQuant);
            coll.AddQuant(propQuant1);
            coll.AddQuant(propQuant2);

            Assert.ThrowsException <InvalidElementException>(() => coll.Add(1));
            Assert.ThrowsException <InvalidElementException>(() => coll.Add(new CustomType1 <int>()
            {
                Value = 2, Prop = false
            }));
            Assert.ThrowsException <InvalidElementException>(() => coll.Add(new CustomType1 <int>()
            {
                Value = 1, Prop = true
            }));
            coll.Add(new CustomType1 <int>()
            {
                Value = 2, Prop = true
            });

            // Typed get and predicate
            Assert.IsTrue(new CustomType1 <int>[] { new CustomType1 <int>()
                                                    {
                                                        Value = 2, Prop = true
                                                    } }
                          .SequenceEqual(coll.Get(typePred)));
        }
Esempio n. 3
0
        public void MPCBasicTest()
        {
            var coll = new ManyPredicateCollection();

            // The element predicate
            var pred = Predicates.ElementTypePredicate <int>();

            // The quantifier
            var quant = Quantifiers.All(pred);

            coll.Add(1);
            coll.AddQuant(quant);
            coll.AddQuant(quant); // Ignored

            // Invalid element
            Assert.ThrowsException <InvalidElementException>(() => coll.Add("a"));

            Assert.IsTrue(new int[] { 1 }.SequenceEqual(coll.Get(pred)));
        }