Esempio n. 1
0
        public void Quantifiers_All()
        {
            // Arrange
            var products = FakeProduct.Data.Generate(5);

            // Act
            var result = _quantifiers.All(products);

            // Assert
            Assert.True(result);
        }
Esempio n. 2
0
        public void PredicateConversionTest()
        {
            var coll = new object[] { 1, 2 };
            var pred = Predicates.ElementTypePredicate <int>();

            Assert.IsTrue(Quantifiers.All(pred)(coll));
            var pred2 = pred.ToPredicate();

            Assert.IsTrue(Quantifiers.All(pred2)(coll));
            var pred3 = pred2.ToElementTypePredicate <double>();

            Assert.IsFalse(Quantifiers.All(pred3)(coll));
            var pred3b = pred2.ToElementTypePredicate <int>();

            Assert.IsTrue(Quantifiers.All(pred3b)(coll));
        }
Esempio n. 3
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. 4
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)));
        }