ToFourDigitYear() public method

public ToFourDigitYear ( int year ) : int
year int
return int
コード例 #1
0
        public void PosTest3()
        {
            System.Globalization.Calendar kC = new KoreanCalendar();
            int twoDigitMax = kC.TwoDigitYearMax;
            int lBound = twoDigitMax - 99;
            int rBound = twoDigitMax;
            int twoDigitYear = _generator.GetInt16(-55) % 100;
            int expectedValue;
            if (twoDigitYear < (lBound % 100))
            {
                expectedValue = (lBound / 100 + 1) * 100 + twoDigitYear;
            }
            else
            {
                expectedValue = (lBound / 100) * 100 + twoDigitYear;
            }

            int actualValue = kC.ToFourDigitYear(twoDigitYear);
            Assert.Equal(expectedValue, actualValue);
        }
コード例 #2
0
ファイル: CalendarTest.cs プロジェクト: GirlD/mono
	public void TestToFourDigitYear2 ()
	{
		GregorianCalendar gc = new GregorianCalendar ();
		Assert.AreEqual (2029, gc.ToFourDigitYear (29), "#1-1");
		Assert.AreEqual (1930, gc.ToFourDigitYear (30), "#1-2");
		Assert.AreEqual (2029, gc.ToFourDigitYear (2029), "#1-3");
		Assert.AreEqual (2030, gc.ToFourDigitYear (2030), "#1-4");

		HebrewCalendar hbc = new HebrewCalendar ();
		Assert.AreEqual (5790, hbc.ToFourDigitYear (90), "#2-1");
		Assert.AreEqual (5691, hbc.ToFourDigitYear (91), "#2-2");
		Assert.AreEqual (5790, hbc.ToFourDigitYear (5790), "#2-3");
		Assert.AreEqual (5691, hbc.ToFourDigitYear (5691), "#2-4");
		Assert.AreEqual (5999, hbc.ToFourDigitYear (5999), "#2-5");
		// LAMESPEC: .NET fails to throw an exception unlike documented
		/*
		try {
			hbc.ToFourDigitYear (6000);
			Assert.Fail ("#2-6");
		} catch (ArgumentOutOfRangeException) {
		}
		*/

		ThaiBuddhistCalendar tc = new ThaiBuddhistCalendar ();
		Assert.AreEqual (2572, tc.ToFourDigitYear (72), "#3-1");
		Assert.AreEqual (2473, tc.ToFourDigitYear (73), "#3-2");
		Assert.AreEqual (2572, tc.ToFourDigitYear (2572), "#3-3");
		Assert.AreEqual (2573, tc.ToFourDigitYear (2573), "#3-4");
		Assert.AreEqual (9999, tc.ToFourDigitYear (9999), "#3-5");
		// LAMESPEC: .NET fails to throw an exception unlike documented
		/*
		try {
			tc.ToFourDigitYear (10000);
			Assert.Fail ("#3-6");
		} catch (ArgumentOutOfRangeException) {
		}
		*/

		KoreanCalendar kc = new KoreanCalendar ();
		Assert.AreEqual (4362, kc.ToFourDigitYear (62), "#4-1");
		Assert.AreEqual (4263, kc.ToFourDigitYear (63), "#4-2");
		Assert.AreEqual (4362, kc.ToFourDigitYear (4362), "#4-3");
		Assert.AreEqual (4363, kc.ToFourDigitYear (4363), "#4-4");
	}
コード例 #3
0
 public void NegTest1()
 {
     System.Globalization.Calendar kC = new KoreanCalendar();
     int actualValue;
     Assert.Throws<ArgumentOutOfRangeException>(() =>
     {
         actualValue = kC.ToFourDigitYear(100);
     });
 }
コード例 #4
0
 public void NegTest3()
 {
     System.Globalization.Calendar kC = new KoreanCalendar();
     int actualValue;
     // it stands to reason that if we're looking to throw an exception then it might be a good idea
     // to ensure the value passed into the method is one that will actual cause the exception to be
     // thrown
     // 100-2333  throw exception
     // 2334-12332 no exception
     // 12333 or more throw exception
     Assert.Throws<ArgumentOutOfRangeException>(() =>
     {
         actualValue = kC.ToFourDigitYear(12333);
     });
 }