コード例 #1
0
ファイル: b12668.cs プロジェクト: CheneyWu/coreclr
        public static int Main(String[] args)
        {
            int successes = 0;
            int result;
            float area;

            baseObject[] aObjects = new baseObject[10];
            Rectangle rRectangle;
            Circle rCircle;

            aObjects[0] = new Rectangle((float)5.0, (float)7.0);

            result = aObjects[0].getId();
            if (result != 2)
            {
                return 1;
            }
            else successes = 1;

            area = aObjects[0].getArea();
            if (area != 35.0)
            {
                return 1;
            }
            else successes++;


            result = aObjects[0].readId();
            if (result != 1)
            {
                return 1;
            }
            else successes++;

            result = aObjects[0].readcount();
            if (result != 1)
            {
                return 1;
            }
            else successes++;

            aObjects[1] = new Circle((float)4.0);

            result = aObjects[1].getId();
            if (result != 3)
            {
                return 1;
            }
            else successes++;

            area = aObjects[1].getArea();
            if (area != (float)(4.0 * 4.0 * 3.14))
            {
                return 1;
            }
            else successes++;


            result = aObjects[1].readcount();
            if (result != 2)
            {
                return 1;
            }
            else successes++;

            rRectangle = (Rectangle)aObjects[0];
            result = Rectangle.count;
            if (result != 1)
            {
                return 1;
            }
            else successes++;

            rCircle = (Circle)aObjects[1];
            result = rCircle.count;
            if (result != 1)
            {
                return 1;
            }
            else successes++;

            bool ok = true;
            int tryvar = 1;
            try
            {
                aObjects[5] = new Rectangle((float)0.0, (float)7.0);
                tryvar = 2;
            }
            catch (ArgumentException /*ae*/  )
            {
                if (tryvar != 1)
                {
                    return 1;
                }
                tryvar = 3;
            }
            finally
            {
                ok = tryvar == 3;
            }
            if (!ok)
            {
                return 1;
            }

            tryvar = 1;
            try
            {
                aObjects[5] = new Circle((float)0.0);
                tryvar = 2;
            }
            catch (ArgumentException /*ae*/  )
            {
                if (tryvar != 1)
                {
                    return 1;
                }
                tryvar = 3;
            }
            finally
            {
                ok = tryvar == 3;
            }
            if (!ok)
            {
                return 1;
            }

            try
            {
                tryvar = 1;
                rRectangle.changeCount(-5);
            }
            catch (ArgumentException /*ae1*/ )
            {
                tryvar = 2;
            }
            finally
            {
                ok = tryvar == 2;
            }
            if (!ok)
            {
                return 1;
            }


            aObjects[2] = new Rectangle((float)2.0, (float)3.0);

            result = aObjects[2].getId();
            if (result != 2)
            {
                return 1;
            }
            else successes++;

            area = aObjects[2].getArea();
            if (area != 6.0)
            {
                return 1;
            }
            else successes++;


            result = aObjects[2].readId();
            if (result != 1)
            {
                return 1;
            }
            else successes++;

            result = aObjects[2].readcount();
            if (result != 3)
            {
                return 1;
            }
            else successes++;

            aObjects[3] = new Circle((float)8.0);
            result = aObjects[3].getId();
            if (result != 3)
            {
                return 1;
            }
            else successes++;

            area = aObjects[3].getArea();
            if (area != (float)(8.0 * 8.0 * 3.14))
            {
                return 1;
            }
            else successes++;


            result = aObjects[3].readcount();
            if (result != 4)
            {
                return 1;
            }
            else successes++;


            rRectangle = (Rectangle)aObjects[0];
            result = Rectangle.count;
            if (result != 2)
            {
                return 1;
            }
            else successes++;

            rCircle = (Circle)aObjects[3];
            result = rCircle.count;



            return 100;
        }  // end main()
コード例 #2
0
        public static int Main(String[] args)
        {
            int   successes = 0;
            int   result;
            float area;

            baseObject[] aObjects = new baseObject[10];
            Rectangle    rRectangle;
            Circle       rCircle;

            aObjects[0] = new Rectangle((float)5.0, (float)7.0);

            result = aObjects[0].getId();
            if (result != 2)
            {
                return(1);
            }
            else
            {
                successes = 1;
            }

            area = aObjects[0].getArea();
            if (area != 35.0)
            {
                return(1);
            }
            else
            {
                successes++;
            }


            result = aObjects[0].readId();
            if (result != 1)
            {
                return(1);
            }
            else
            {
                successes++;
            }

            result = aObjects[0].readcount();
            if (result != 1)
            {
                return(1);
            }
            else
            {
                successes++;
            }

            aObjects[1] = new Circle((float)4.0);

            result = aObjects[1].getId();
            if (result != 3)
            {
                return(1);
            }
            else
            {
                successes++;
            }

            area = aObjects[1].getArea();
            if (area != (float)(4.0 * 4.0 * 3.14))
            {
                return(1);
            }
            else
            {
                successes++;
            }


            result = aObjects[1].readcount();
            if (result != 2)
            {
                return(1);
            }
            else
            {
                successes++;
            }

            rRectangle = (Rectangle)aObjects[0];
            result     = Rectangle.count;
            if (result != 1)
            {
                return(1);
            }
            else
            {
                successes++;
            }

            rCircle = (Circle)aObjects[1];
            result  = rCircle.count;
            if (result != 1)
            {
                return(1);
            }
            else
            {
                successes++;
            }

            bool ok     = true;
            int  tryvar = 1;

            try
            {
                aObjects[5] = new Rectangle((float)0.0, (float)7.0);
                tryvar      = 2;
            }
            catch (ArgumentException /*ae*/)
            {
                if (tryvar != 1)
                {
                    return(1);
                }
                tryvar = 3;
            }
            finally
            {
                ok = tryvar == 3;
            }
            if (!ok)
            {
                return(1);
            }

            tryvar = 1;
            try
            {
                aObjects[5] = new Circle((float)0.0);
                tryvar      = 2;
            }
            catch (ArgumentException /*ae*/)
            {
                if (tryvar != 1)
                {
                    return(1);
                }
                tryvar = 3;
            }
            finally
            {
                ok = tryvar == 3;
            }
            if (!ok)
            {
                return(1);
            }

            try
            {
                tryvar = 1;
                rRectangle.changeCount(-5);
            }
            catch (ArgumentException /*ae1*/)
            {
                tryvar = 2;
            }
            finally
            {
                ok = tryvar == 2;
            }
            if (!ok)
            {
                return(1);
            }


            aObjects[2] = new Rectangle((float)2.0, (float)3.0);

            result = aObjects[2].getId();
            if (result != 2)
            {
                return(1);
            }
            else
            {
                successes++;
            }

            area = aObjects[2].getArea();
            if (area != 6.0)
            {
                return(1);
            }
            else
            {
                successes++;
            }


            result = aObjects[2].readId();
            if (result != 1)
            {
                return(1);
            }
            else
            {
                successes++;
            }

            result = aObjects[2].readcount();
            if (result != 3)
            {
                return(1);
            }
            else
            {
                successes++;
            }

            aObjects[3] = new Circle((float)8.0);
            result      = aObjects[3].getId();
            if (result != 3)
            {
                return(1);
            }
            else
            {
                successes++;
            }

            area = aObjects[3].getArea();
            if (area != (float)(8.0 * 8.0 * 3.14))
            {
                return(1);
            }
            else
            {
                successes++;
            }


            result = aObjects[3].readcount();
            if (result != 4)
            {
                return(1);
            }
            else
            {
                successes++;
            }


            rRectangle = (Rectangle)aObjects[0];
            result     = Rectangle.count;
            if (result != 2)
            {
                return(1);
            }
            else
            {
                successes++;
            }

            rCircle = (Circle)aObjects[3];
            result  = rCircle.count;



            return(100);
        } // end main()