Пример #1
0
        public Boolean Equals(ICountProperty countProperty)
        {
            CountWithMinAndMax countWithMinAndMax = countProperty as CountWithMinAndMax;

            if (countWithMinAndMax == null)
            {
                return(false);
            }
            return((this.min == countWithMinAndMax.min) && (this.max == countWithMinAndMax.max));
        }
        public void CountWithMinAndMaxParserTest()
        {
            CountWithMinAndMax countWithMinAndMaxA = new CountWithMinAndMax(1, 2);
            CountWithMinAndMax countWithMinAndMaxB = new CountWithMinAndMax(4, 9938);

            TestUtil.TestPropertyParser("1-2", countWithMinAndMaxA);
            TestUtil.TestPropertyParser("\t\t  1-2 \n\n \t", countWithMinAndMaxA);

            TestUtil.TestPropertyParser("4-9938", countWithMinAndMaxB);
            TestUtil.TestPropertyParser("\t\t  4-9938 \n\n \t", countWithMinAndMaxB);


            //
            // Test that it disallows certain min/max pairs
            //
            try
            {
                CountWithMinAndMax countWithMinAndMax = new CountWithMinAndMax(2, 1);
                Assert.Fail();
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(String.Format("Caught expected exception {0}", e));
            }
            try
            {
                CountWithMinAndMax countWithMinAndMax = new CountWithMinAndMax(999, 999);
                Assert.Fail();
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(String.Format("Caught expected exception {0}", e));
            }

            //
            // Test some larger values
            //
            for (UInt32 i = 1; i < 1000000; i += 95416)
            {
                for (UInt32 j = i + 1; j < 1000000; j += 95416)
                {
                    CountWithMinAndMax countWithMinAndMax = (CountWithMinAndMax)CountProperty.Parse(String.Format("{0}-{1}", i, j));
                    Assert.AreEqual(i, countWithMinAndMax.min);
                    Assert.AreEqual(j, countWithMinAndMax.max);
                }
            }
        }