[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / corlib / Test / System.Globalization / EastAsianLunisolarCalendarTest.cs
1 // EastAsianLunisolarCalendarTest.cs
2 //
3 // Author:
4 //      Atsushi Enomoto  <atsushi@ximian.com>
5 //
6 // Copyright (C) 2007 Novell, Inc.  http://www.novell.com
7 //
8
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30
31 using NUnit.Framework;
32 using System;
33 using System.Collections.Generic;
34 using System.Globalization;
35 using System.IO;
36
37 namespace MonoTests.System.Globalization
38 {
39         [TestFixture]
40         public class EastAsianLunisolarCalendarTest
41         {
42                 static ChineseLunisolarCalendar cn = new ChineseLunisolarCalendar ();
43                 static JapaneseLunisolarCalendar jp = new JapaneseLunisolarCalendar ();
44                 static TaiwanLunisolarCalendar tw = new TaiwanLunisolarCalendar ();
45                 static KoreanLunisolarCalendar kr = new KoreanLunisolarCalendar ();
46
47                 [Test]
48                 [Category ("NotWorking")]
49                 public void ToDateTime ()
50                 {
51                         Assert.AreEqual (new DateTime (2000, 2, 5), cn.ToDateTime (2000, 1, 1, 0, 0, 0, 0), "cn1");
52                         Assert.AreEqual (new DateTime (2000, 2, 5), jp.ToDateTime (12, 1, 1, 0, 0, 0, 0), "jp1"); // since 1988 (current epoch)
53                         Assert.AreEqual (new DateTime (2000, 2, 5), tw.ToDateTime (89, 1, 1, 0, 0, 0, 0), "tw1"); // since 1912 (current epoch)
54                         Assert.AreEqual (new DateTime (2000, 2, 5), kr.ToDateTime (2000, 1, 1, 0, 0, 0, 0), "kr1");
55
56                         Assert.AreEqual (new DateTime (2001, 1, 24), cn.ToDateTime (2001, 1, 1, 0, 0, 0, 0), "cn2");
57                         Assert.AreEqual (new DateTime (2001, 1, 24), jp.ToDateTime (13, 1, 1, 0, 0, 0, 0), "jp2");
58                         Assert.AreEqual (new DateTime (2001, 1, 24), tw.ToDateTime (90, 1, 1, 0, 0, 0, 0), "tw2");
59                         Assert.AreEqual (new DateTime (2001, 1, 24), kr.ToDateTime (2001, 1, 1, 0, 0, 0, 0), "kr2");
60
61                         Assert.AreEqual (new DateTime (2002, 2, 12), cn.ToDateTime (2002, 1, 1, 0, 0, 0, 0), "cn3");
62                         Assert.AreEqual (new DateTime (2002, 2, 12), jp.ToDateTime (14, 1, 1, 0, 0, 0, 0), "jp3");
63                         Assert.AreEqual (new DateTime (2002, 2, 12), tw.ToDateTime (91, 1, 1, 0, 0, 0, 0), "tw3");
64                         Assert.AreEqual (new DateTime (2002, 2, 12), kr.ToDateTime (2002, 1, 1, 0, 0, 0, 0), "kr3");
65
66                         // actually it is 5th month which is leap, but that
67                         // does not afffect on resulting DateTime
68                         Assert.AreEqual (new DateTime (2001, 5, 23), cn.ToDateTime (2001, 5, 1, 0, 0, 0, 0), "cn4");
69                         Assert.AreEqual (new DateTime (2001, 5, 23), jp.ToDateTime (13, 5, 1, 0, 0, 0, 0), "jp4");
70                         Assert.AreEqual (new DateTime (2001, 5, 23), tw.ToDateTime (90, 5, 1, 0, 0, 0, 0), "tw4");
71                         Assert.AreEqual (new DateTime (2001, 5, 23), kr.ToDateTime (2001, 5, 1, 0, 0, 0, 0), "kr4");
72
73                         // here the leap month works.
74                         Assert.AreEqual (new DateTime (2002, 2, 11), cn.ToDateTime (2001, 13, 30, 0, 0, 0, 0), "cn5");
75                         Assert.AreEqual (new DateTime (2002, 2, 11), jp.ToDateTime (13, 13, 30, 0, 0, 0, 0), "jp5");
76                         Assert.AreEqual (new DateTime (2002, 2, 11), tw.ToDateTime (90, 13, 30, 0, 0, 0, 0), "tw5");
77                         Assert.AreEqual (new DateTime (2002, 2, 11), kr.ToDateTime (2001, 13, 30, 0, 0, 0, 0), "kr5");
78
79                         Assert.AreEqual (cn.MinSupportedDateTime, cn.ToDateTime (1901, 1, 1, 0, 0, 0, 0), "cn6");
80                         Assert.AreEqual (jp.MinSupportedDateTime, jp.ToDateTime (35, 1, 1, 0, 0, 0, 0, 3), "jp6"); // 1960-1-1
81                         Assert.AreEqual (tw.MinSupportedDateTime, tw.ToDateTime (1, 1, 1, 0, 0, 0, 0), "tw6"); // 1912
82                         Assert.AreEqual (kr.MinSupportedDateTime, kr.ToDateTime (918, 1, 1, 0, 0, 0, 0), "kr6");
83
84                         Assert.AreEqual (jp.MinSupportedDateTime, cn.ToDateTime (1960, 1, 1, 0, 0, 0, 0), "jp-cn1");
85                 }
86
87                 [Test]
88                 [Category ("NotWorking")]
89                 public void ToDateTimeOutOfRange ()
90                 {
91                         try {
92                                 cn.ToDateTime (1900, 12, 29, 23, 59, 59, 0);
93                                 Assert.Fail ("#cn1");
94                         } catch (ArgumentOutOfRangeException) {
95                         }
96                         try { // non-leap
97                                 cn.ToDateTime (2000, 13, 29, 23, 59, 59, 0);
98                                 Assert.Fail ("#cn2");
99                         } catch (ArgumentOutOfRangeException) {
100                         }
101                 }
102
103                 [Test]
104                 [Category ("NotWorking")]
105                 public void GetYear ()
106                 {
107                         Assert.AreEqual (1901, cn.GetYear (new DateTime (1901, 2, 19, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#1");
108                         Assert.AreEqual (1901, cn.GetYear (new DateTime (1902, 2, 07, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#2");
109                         Assert.AreEqual (1902, cn.GetYear (new DateTime (1902, 2, 08, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#3");
110                         Assert.AreEqual (1902, cn.GetYear (new DateTime (1903, 1, 28, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#4");
111                         Assert.AreEqual (1903, cn.GetYear (new DateTime (1903, 1, 29, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#5");
112                         // there was a leap month
113                         Assert.AreEqual (1903, cn.GetYear (new DateTime (1904, 2, 15, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#6");
114                         Assert.AreEqual (1904, cn.GetYear (new DateTime (1904, 2, 16, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#7");
115                 }
116
117                 [Test]
118                 [Category ("NotWorking")]
119                 public void GetYear2 ()
120                 {
121                         Assert.AreEqual (1999, cn.GetYear (new DateTime (2000, 2, 4, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#1");
122                         Assert.AreEqual (2000, cn.GetYear (new DateTime (2000, 2, 5, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#2");
123                         Assert.AreEqual (11, jp.GetYear (new DateTime (2000, 2, 4, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#3");
124                         Assert.AreEqual (12, jp.GetYear (new DateTime (2000, 2, 5, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#4");
125                         Assert.AreEqual (88, tw.GetYear (new DateTime (2000, 2, 4, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#5");
126                         Assert.AreEqual (89, tw.GetYear (new DateTime (2000, 2, 5, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#6");
127                         Assert.AreEqual (1999, cn.GetYear (new DateTime (2000, 2, 4, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#7");
128                         Assert.AreEqual (2000, cn.GetYear (new DateTime (2000, 2, 5, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#8");
129                 }
130
131                 bool [] leapYears = new bool [] {
132                         false, true, false, false, true,
133                         false, true, false, false, true,
134                         false, false, true, false, true,
135                         false, false, true, false, // 19 years rotation
136                         };
137
138                 [Test]
139                 [Category ("NotWorking")]
140                 public void IsLeapYear ()
141                 {
142                         //Assert.IsFalse (cn.IsLeapYear (1901), "#cn1901");
143                         //Assert.AreEqual (0, cn.GetSexagenaryYear (cn.MinSupportedDateTime), "#60cn1");
144
145                         for (int i = 0; i < 60; i++)
146                                 Assert.AreEqual (leapYears [i % 19], cn.IsLeapYear (2000 + i), "cn" + i);
147                         for (int i = 0; i < 48; i++) // only 1-to-61 are allowed
148                                 Assert.AreEqual (leapYears [i % 19], jp.IsLeapYear (12 + i), "jp" + i);
149                         for (int i = 0; i < 50; i++)
150                                 Assert.AreEqual (leapYears [i % 19], tw.IsLeapYear (89 + i), "tw" + i);
151                         for (int i = 0; i < 50; i++)
152                                 Assert.AreEqual (leapYears [i % 19], kr.IsLeapYear (2000 + i), "kr" + i);
153
154                         // 2033 Rain-Water jieqi (usui) new year day is in
155                         // the leap month.
156                         Assert.IsTrue (cn.IsLeapYear (2033), "cn2033");
157                         Assert.IsFalse (cn.IsLeapYear (2034), "cn2034");
158                 }
159
160                 [Test]
161                 [Category ("NotWorking")]
162                 public void IsLeapMonth ()
163                 {
164                         Dictionary<int,int> d = new Dictionary<int,int> ();
165                         d [2001] = 5;
166                         d [2004] = 3;
167                         d [2006] = 8;
168                         d [2009] = 6;
169                         d [2012] = 5;
170                         d [2014] = 10;
171                         d [2017] = 7;
172                         d [2020] = 5;
173                         d [2023] = 3;
174                         d [2025] = 7; // hmm ...
175                         d [2028] = 6;
176                         d [2031] = 4; // hmmmm ...
177                         d [2033] = 12; // hmmmmmm ...
178                         d [2036] = 7;
179                         for (int y = 2000; y < 2038; y++)
180                                 for (int m = 1; m <= 12; m++)
181                                         Assert.AreEqual (d.ContainsKey (y) && d [y] == m, cn.IsLeapMonth (y, m), "cn" + y + "/" + m);
182
183                         d = new Dictionary<int,int> ();
184                         d [90] = 5;
185                         d [93] = 3;
186                         d [95] = 8;
187                         d [98] = 6;
188                         d [101] = 5;
189                         d [103] = 10;
190                         d [106] = 7;
191                         d [109] = 5;
192                         d [112] = 3;
193                         d [114] = 7;
194                         d [117] = 6;
195                         d [120] = 4;
196                         d [122] = 12;
197                         d [125] = 7;
198                         for (int y = 89; y < 127; y++)
199                                 for (int m = 1; m <= 12; m++)
200                                         Assert.AreEqual (d.ContainsKey (y) && d [y] == m, tw.IsLeapMonth (y, m), "tw" + y + "/" + m);
201
202                         d = new Dictionary<int,int> ();
203                         d [13] = 5;
204                         d [16] = 3;
205                         d [18] = 8;
206                         d [21] = 6;
207                         d [24] = 4;
208                         d [26] = 10;
209                         d [29] = 6;
210                         for (int y = 12; y < 32; y++)
211                                 for (int m = 1; m <= 12; m++)
212                                         Assert.AreEqual (d.ContainsKey (y) && d [y] == m, jp.IsLeapMonth (y, m), "jp" + y + "/" + m);
213
214                         d = new Dictionary<int,int> ();
215                         d [2001] = 5;
216                         d [2004] = 3;
217                         d [2006] = 8;
218                         d [2009] = 6;
219                         d [2012] = 4;
220                         d [2014] = 10;
221                         d [2017] = 6;
222                         for (int y = 2000; y < 2020; y++)
223                                 for (int m = 1; m <= 12; m++)
224                                         Assert.AreEqual (d.ContainsKey (y) && d [y] == m, kr.IsLeapMonth (y, m), "kr" + y + "/" + m);
225                 }
226         }
227 }
228