Example #1
0
        public void TheoremTest1()
        {
            // Suppes p. 62
            // No Episcopalian (A) or Presbyterian (B) is a Unitarian (C). John was a Unitarian. Therefore, he was
            // not an Episcopalian.
            var pred1 = new ForTypePredicate <T>((T x) => !(x.A && x.C));
            var pred2 = new ForTypePredicate <T>((T x) => !(x.B && x.C));
            var a     = new T()
            {
                C = true
            };
            Func <bool> pro = () => !a.A;

            Assert.IsTrue(pred1(a) && pred2(a) && pro());

            // All scientists (A) are rationalists (B). No British (C) philosophers (D) are rationalists. Therefore,
            // no British philosophers are scientists.
            pred1 = new ForTypePredicate <T>((T x) => !x.A || x.B);
            pred2 = new ForTypePredicate <T>((T x) => !(x.C && x.D) || !x.B);
            var counter = new ForTypePredicate <T>((T x) => !(x.C && x.D) || !x.A);
            var s       = new T()
            {
                C = true, D = true, A = true
            };

            Assert.IsTrue(!pred1(s) && !pred2(s)); // PAROU: Why failing?
            Assert.IsTrue(!pred1(s) && !pred2(s) && !counter(s));
            Assert.IsTrue(!counter(s));
        }
Example #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)));
        }
Example #3
0
 public static Predicate ToPredicate <T>(this ForTypePredicate <T> forTypePred)
 {
     // Must be satisfiable for an element of the specified type only.
     return(new Predicate((object e) => !(e is T) || forTypePred((T)e)));
 }