Merge pull request #924 from marcusva/master
[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 #if NET_2_0
31
32 using NUnit.Framework;
33 using System;
34 using System.Collections.Generic;
35 using System.Globalization;
36 using System.IO;
37
38 namespace MonoTests.System.Globalization
39 {
40         [TestFixture]
41         public class EastAsianLunisolarCalendarTest
42         {
43                 static ChineseLunisolarCalendar cn = new ChineseLunisolarCalendar ();
44                 static JapaneseLunisolarCalendar jp = new JapaneseLunisolarCalendar ();
45                 static TaiwanLunisolarCalendar tw = new TaiwanLunisolarCalendar ();
46                 static KoreanLunisolarCalendar kr = new KoreanLunisolarCalendar ();
47
48                 [Test]
49                 [Category ("NotWorking")]
50                 public void ToDateTime ()
51                 {
52                         Assert.AreEqual (new DateTime (2000, 2, 5), cn.ToDateTime (2000, 1, 1, 0, 0, 0, 0), "cn1");
53                         Assert.AreEqual (new DateTime (2000, 2, 5), jp.ToDateTime (12, 1, 1, 0, 0, 0, 0), "jp1"); // since 1988 (current epoch)
54                         Assert.AreEqual (new DateTime (2000, 2, 5), tw.ToDateTime (89, 1, 1, 0, 0, 0, 0), "tw1"); // since 1912 (current epoch)
55                         Assert.AreEqual (new DateTime (2000, 2, 5), kr.ToDateTime (2000, 1, 1, 0, 0, 0, 0), "kr1");
56
57                         Assert.AreEqual (new DateTime (2001, 1, 24), cn.ToDateTime (2001, 1, 1, 0, 0, 0, 0), "cn2");
58                         Assert.AreEqual (new DateTime (2001, 1, 24), jp.ToDateTime (13, 1, 1, 0, 0, 0, 0), "jp2");
59                         Assert.AreEqual (new DateTime (2001, 1, 24), tw.ToDateTime (90, 1, 1, 0, 0, 0, 0), "tw2");
60                         Assert.AreEqual (new DateTime (2001, 1, 24), kr.ToDateTime (2001, 1, 1, 0, 0, 0, 0), "kr2");
61
62                         Assert.AreEqual (new DateTime (2002, 2, 12), cn.ToDateTime (2002, 1, 1, 0, 0, 0, 0), "cn3");
63                         Assert.AreEqual (new DateTime (2002, 2, 12), jp.ToDateTime (14, 1, 1, 0, 0, 0, 0), "jp3");
64                         Assert.AreEqual (new DateTime (2002, 2, 12), tw.ToDateTime (91, 1, 1, 0, 0, 0, 0), "tw3");
65                         Assert.AreEqual (new DateTime (2002, 2, 12), kr.ToDateTime (2002, 1, 1, 0, 0, 0, 0), "kr3");
66
67                         // actually it is 5th month which is leap, but that
68                         // does not afffect on resulting DateTime
69                         Assert.AreEqual (new DateTime (2001, 5, 23), cn.ToDateTime (2001, 5, 1, 0, 0, 0, 0), "cn4");
70                         Assert.AreEqual (new DateTime (2001, 5, 23), jp.ToDateTime (13, 5, 1, 0, 0, 0, 0), "jp4");
71                         Assert.AreEqual (new DateTime (2001, 5, 23), tw.ToDateTime (90, 5, 1, 0, 0, 0, 0), "tw4");
72                         Assert.AreEqual (new DateTime (2001, 5, 23), kr.ToDateTime (2001, 5, 1, 0, 0, 0, 0), "kr4");
73
74                         // here the leap month works.
75                         Assert.AreEqual (new DateTime (2002, 2, 11), cn.ToDateTime (2001, 13, 30, 0, 0, 0, 0), "cn5");
76                         Assert.AreEqual (new DateTime (2002, 2, 11), jp.ToDateTime (13, 13, 30, 0, 0, 0, 0), "jp5");
77                         Assert.AreEqual (new DateTime (2002, 2, 11), tw.ToDateTime (90, 13, 30, 0, 0, 0, 0), "tw5");
78                         Assert.AreEqual (new DateTime (2002, 2, 11), kr.ToDateTime (2001, 13, 30, 0, 0, 0, 0), "kr5");
79
80                         Assert.AreEqual (cn.MinSupportedDateTime, cn.ToDateTime (1901, 1, 1, 0, 0, 0, 0), "cn6");
81                         Assert.AreEqual (jp.MinSupportedDateTime, jp.ToDateTime (35, 1, 1, 0, 0, 0, 0, 3), "jp6"); // 1960-1-1
82                         Assert.AreEqual (tw.MinSupportedDateTime, tw.ToDateTime (1, 1, 1, 0, 0, 0, 0), "tw6"); // 1912
83                         Assert.AreEqual (kr.MinSupportedDateTime, kr.ToDateTime (918, 1, 1, 0, 0, 0, 0), "kr6");
84
85                         Assert.AreEqual (jp.MinSupportedDateTime, cn.ToDateTime (1960, 1, 1, 0, 0, 0, 0), "jp-cn1");
86                 }
87
88                 [Test]
89                 [Category ("NotWorking")]
90                 public void ToDateTimeOutOfRange ()
91                 {
92                         try {
93                                 cn.ToDateTime (1900, 12, 29, 23, 59, 59, 0);
94                                 Assert.Fail ("#cn1");
95                         } catch (ArgumentOutOfRangeException) {
96                         }
97                         try { // non-leap
98                                 cn.ToDateTime (2000, 13, 29, 23, 59, 59, 0);
99                                 Assert.Fail ("#cn2");
100                         } catch (ArgumentOutOfRangeException) {
101                         }
102                 }
103
104                 [Test]
105                 [Category ("NotWorking")]
106                 public void GetYear ()
107                 {
108                         Assert.AreEqual (1901, cn.GetYear (new DateTime (1901, 2, 19, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#1");
109                         Assert.AreEqual (1901, cn.GetYear (new DateTime (1902, 2, 07, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#2");
110                         Assert.AreEqual (1902, cn.GetYear (new DateTime (1902, 2, 08, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#3");
111                         Assert.AreEqual (1902, cn.GetYear (new DateTime (1903, 1, 28, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#4");
112                         Assert.AreEqual (1903, cn.GetYear (new DateTime (1903, 1, 29, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#5");
113                         // there was a leap month
114                         Assert.AreEqual (1903, cn.GetYear (new DateTime (1904, 2, 15, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#6");
115                         Assert.AreEqual (1904, cn.GetYear (new DateTime (1904, 2, 16, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#7");
116                 }
117
118                 [Test]
119                 [Category ("NotWorking")]
120                 public void GetYear2 ()
121                 {
122                         Assert.AreEqual (1999, cn.GetYear (new DateTime (2000, 2, 4, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#1");
123                         Assert.AreEqual (2000, cn.GetYear (new DateTime (2000, 2, 5, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#2");
124                         Assert.AreEqual (11, jp.GetYear (new DateTime (2000, 2, 4, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#3");
125                         Assert.AreEqual (12, jp.GetYear (new DateTime (2000, 2, 5, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#4");
126                         Assert.AreEqual (88, tw.GetYear (new DateTime (2000, 2, 4, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#5");
127                         Assert.AreEqual (89, tw.GetYear (new DateTime (2000, 2, 5, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#6");
128                         Assert.AreEqual (1999, cn.GetYear (new DateTime (2000, 2, 4, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#7");
129                         Assert.AreEqual (2000, cn.GetYear (new DateTime (2000, 2, 5, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#8");
130                 }
131
132                 bool [] leapYears = new bool [] {
133                         false, true, false, false, true,
134                         false, true, false, false, true,
135                         false, false, true, false, true,
136                         false, false, true, false, // 19 years rotation
137                         };
138
139                 [Test]
140                 [Category ("NotWorking")]
141                 public void IsLeapYear ()
142                 {
143                         //Assert.IsFalse (cn.IsLeapYear (1901), "#cn1901");
144                         //Assert.AreEqual (0, cn.GetSexagenaryYear (cn.MinSupportedDateTime), "#60cn1");
145
146                         for (int i = 0; i < 60; i++)
147                                 Assert.AreEqual (leapYears [i % 19], cn.IsLeapYear (2000 + i), "cn" + i);
148                         for (int i = 0; i < 48; i++) // only 1-to-61 are allowed
149                                 Assert.AreEqual (leapYears [i % 19], jp.IsLeapYear (12 + i), "jp" + i);
150                         for (int i = 0; i < 50; i++)
151                                 Assert.AreEqual (leapYears [i % 19], tw.IsLeapYear (89 + i), "tw" + i);
152                         for (int i = 0; i < 50; i++)
153                                 Assert.AreEqual (leapYears [i % 19], kr.IsLeapYear (2000 + i), "kr" + i);
154
155                         // 2033 Rain-Water jieqi (usui) new year day is in
156                         // the leap month.
157                         Assert.IsTrue (cn.IsLeapYear (2033), "cn2033");
158                         Assert.IsFalse (cn.IsLeapYear (2034), "cn2034");
159                 }
160
161                 [Test]
162                 [Category ("NotWorking")]
163                 public void IsLeapMonth ()
164                 {
165                         Dictionary<int,int> d = new Dictionary<int,int> ();
166                         d [2001] = 5;
167                         d [2004] = 3;
168                         d [2006] = 8;
169                         d [2009] = 6;
170                         d [2012] = 5;
171                         d [2014] = 10;
172                         d [2017] = 7;
173                         d [2020] = 5;
174                         d [2023] = 3;
175                         d [2025] = 7; // hmm ...
176                         d [2028] = 6;
177                         d [2031] = 4; // hmmmm ...
178                         d [2033] = 12; // hmmmmmm ...
179                         d [2036] = 7;
180                         for (int y = 2000; y < 2038; y++)
181                                 for (int m = 1; m <= 12; m++)
182                                         Assert.AreEqual (d.ContainsKey (y) && d [y] == m, cn.IsLeapMonth (y, m), "cn" + y + "/" + m);
183
184                         d = new Dictionary<int,int> ();
185                         d [90] = 5;
186                         d [93] = 3;
187                         d [95] = 8;
188                         d [98] = 6;
189                         d [101] = 5;
190                         d [103] = 10;
191                         d [106] = 7;
192                         d [109] = 5;
193                         d [112] = 3;
194                         d [114] = 7;
195                         d [117] = 6;
196                         d [120] = 4;
197                         d [122] = 12;
198                         d [125] = 7;
199                         for (int y = 89; y < 127; y++)
200                                 for (int m = 1; m <= 12; m++)
201                                         Assert.AreEqual (d.ContainsKey (y) && d [y] == m, tw.IsLeapMonth (y, m), "tw" + y + "/" + m);
202
203                         d = new Dictionary<int,int> ();
204                         d [13] = 5;
205                         d [16] = 3;
206                         d [18] = 8;
207                         d [21] = 6;
208                         d [24] = 4;
209                         d [26] = 10;
210                         d [29] = 6;
211                         for (int y = 12; y < 32; y++)
212                                 for (int m = 1; m <= 12; m++)
213                                         Assert.AreEqual (d.ContainsKey (y) && d [y] == m, jp.IsLeapMonth (y, m), "jp" + y + "/" + m);
214
215                         d = new Dictionary<int,int> ();
216                         d [2001] = 5;
217                         d [2004] = 3;
218                         d [2006] = 8;
219                         d [2009] = 6;
220                         d [2012] = 4;
221                         d [2014] = 10;
222                         d [2017] = 6;
223                         for (int y = 2000; y < 2020; y++)
224                                 for (int m = 1; m <= 12; m++)
225                                         Assert.AreEqual (d.ContainsKey (y) && d [y] == m, kr.IsLeapMonth (y, m), "kr" + y + "/" + m);
226                 }
227         }
228 }
229
230 #endif