Esempio n. 1
0
        void test6()
        {
            Mammal a = new Mammal();

            if (a.SampleMethod() != 3)
            {
                Contract.Assert(false);
            }
        }
Esempio n. 2
0
        public static int test3_Bugged()
        {
            // mammal
            // dog
            Mammal m = new Mammal();


            int old_hair = m.hair;
            int hair     = m.GrowHair();

            if (m is Dog)
            {
                Contract.Assert(old_hair * old_hair == hair);
            }
            else if (m is Mammal)
            {
                Contract.Assert(old_hair + 1 == hair);
            }
            else
            {
                Contract.Assert(false);
            }

            m = new Dog();

            old_hair = m.hair;
            hair     = m.GrowHair();

            if (m is Dog)
            {
                Contract.Assert(old_hair * old_hair == hair);
            }
            else if (m is Mammal)
            {
                Contract.Assert(old_hair + 1 == hair);
            }
            else
            {
                Contract.Assert(false);
            }

            Contract.Assert(false);

            return(hair);
        }
Esempio n. 3
0
        public static int test1_Bugged()
        {
            // correct order of checks
            // fist check mammal
            // second check reptil
            // third abstract version animal

            Animal a = new Mammal();

            int old_oxy = a.oxygen;
            int oxy     = a.Breathe();

            if (a is Mammal)
            {
                Contract.Assert(oxy == old_oxy * 2);
            }
            else if (a is Reptile)
            {
                Contract.Assert(oxy == old_oxy + 1);
            }
            else
            {
                Contract.Assert(false);
            }

            a = new Dog();

            old_oxy = a.oxygen;
            oxy     = a.Breathe();

            if (a is Mammal)
            {
                Contract.Assert(oxy == old_oxy * 2);
            }
            else if (a is Reptile)
            {
                Contract.Assert(oxy == old_oxy + 1);
            }
            else
            {
                Contract.Assert(false);
            }

            a       = new Reptile();
            old_oxy = a.oxygen;
            oxy     = a.Breathe();

            if (a is Mammal)
            {
                Contract.Assert(oxy == old_oxy * 2);
            }
            else if (a is Reptile)
            {
                Contract.Assert(oxy == old_oxy + 1);
            }
            else
            {
                Contract.Assert(false);
            }

            Contract.Assert(false);

            return(oxy);
        }