Got nunit tests running in windows. Reorganized Test case directories.
[mono.git] / mcs / class / corlib / Test / System / Int16Test.cs
1 // Int16Test.cs - NUnit Test Cases for the System.Int16 struct
2 //
3 // Mario Martinez (mariom925@home.om)
4 //
5 // (C) Ximian, Inc.  http://www.ximian.com
6 // 
7
8 using NUnit.Framework;
9 using System;
10 using System.Globalization;
11
12 namespace MonoTests.System
13 {
14
15 public class Int16Test : TestCase
16 {
17         private const Int16 MyInt16_1 = -42;
18         private const Int16 MyInt16_2 = -32768;
19         private const Int16 MyInt16_3 = 32767;
20         private const string MyString1 = "-42";
21         private const string MyString2 = "-32768";
22         private const string MyString3 = "32767";
23         private string[] Formats1 = {"c", "d", "e", "f", "g", "n", "p", "x" };
24         private string[] Formats2 = {"c5", "d5", "e5", "f5", "g5", "n5", "p5", "x5" };
25         private string[] Results1 = {"($32,768.00)", "-32768", "-3.276800e+004", "-32768.00",
26                                           "-32768", "-32,768.00", "-3,276,800.00 %", "8000"};
27         private string[] Results2 = {"$32,767.00000", "32767", "3.27670e+004", "32767.00000",
28                                           "32767", "32,767.00000", "3,276,700.00000 %", "07fff"};
29         private string[] ResultsNfi1 = {"($32,768.00)", "-32768", "-3.276800e+004", "-32768.00",
30                                           "-32768", "(32,768.00)", "-3,276,800.00 %", "8000"};
31         private string[] ResultsNfi2 = {"$32,767.00000", "32767", "3.27670e+004", "32767.00000",
32                                           "32767", "32,767.00000", "3,276,700.00000 %", "07fff"};
33         private NumberFormatInfo Nfi = NumberFormatInfo.InvariantInfo;
34         
35         public Int16Test(string name) : base(name) {}
36
37         protected override void SetUp() 
38         {
39         }
40
41         public static ITest Suite {
42                 get { 
43                         return new TestSuite(typeof(Int16Test)); 
44                 }
45         }
46     
47         public void TestMinMax()
48         {
49                 
50                 AssertEquals(Int16.MinValue, MyInt16_2);
51                 AssertEquals(Int16.MaxValue, MyInt16_3);
52         }
53         
54         public void TestCompareTo()
55         {
56                 Assert(MyInt16_3.CompareTo(MyInt16_2) > 0);
57                 Assert(MyInt16_2.CompareTo(MyInt16_2) == 0);
58                 Assert(MyInt16_1.CompareTo((Int16)(-42)) == 0);
59                 Assert(MyInt16_2.CompareTo(MyInt16_3) < 0);
60                 try {
61                         MyInt16_2.CompareTo(100);
62                         Fail("Should raise a System.ArgumentException");
63                 }
64                 catch (Exception e) {
65                         Assert(typeof(ArgumentException) == e.GetType());
66                 }
67         }
68
69         public void TestEquals()
70         {
71                 Assert(MyInt16_1.Equals(MyInt16_1));
72                 Assert(MyInt16_1.Equals((Int16)(-42)));
73                 Assert(MyInt16_1.Equals((SByte)(-42)) == false);
74                 Assert(MyInt16_1.Equals(MyInt16_2) == false);
75         }
76         
77         public void TestGetHashCode()
78         {
79                 try {
80                         MyInt16_1.GetHashCode();
81                         MyInt16_2.GetHashCode();
82                         MyInt16_3.GetHashCode();
83                 }
84                 catch {
85                         Fail("GetHashCode should not raise an exception here");
86                 }
87         }
88         
89         public void TestParse()
90         {
91                 //test Parse(string s)
92                 Assert(MyInt16_1 == Int16.Parse(MyString1));
93                 Assert(MyInt16_2 == Int16.Parse(MyString2));
94                 Assert(MyInt16_3 == Int16.Parse(MyString3));
95                 try {
96                         Int16.Parse(null);
97                         Fail("Should raise a System.ArgumentNullException");
98                 }
99                 catch (Exception e) {
100                         Assert(typeof(ArgumentNullException) == e.GetType());
101                 }
102                 try {
103                         Int16.Parse("not-a-number");
104                         Fail("Should raise a System.FormatException");
105                 }
106                 catch (Exception e) {
107                         Assert(typeof(FormatException) == e.GetType());
108                 }
109                 try {
110                         int OverInt = Int16.MaxValue + 1;
111                         Int16.Parse(OverInt.ToString());
112                         Fail("Should raise a System.OverflowException");
113                 }
114                 catch (Exception e) {
115                         Assert(typeof(OverflowException) == e.GetType());
116                 }
117                 //test Parse(string s, NumberStyles style)
118                 Assert(42 == Int16.Parse(" $42 ", NumberStyles.Currency));
119                 try {
120                         Int16.Parse("$42", NumberStyles.Integer);
121                         Fail("Should raise a System.FormatException");
122                 }
123                 catch (Exception e) {
124                         Assert(typeof(FormatException) == e.GetType());
125                 }
126                 //test Parse(string s, IFormatProvider provider)
127                 Assert(-42 == Int16.Parse(" -42 ", Nfi));
128                 try {
129                         Int16.Parse("%42", Nfi);
130                         Fail("Should raise a System.FormatException");
131                 }
132                 catch (Exception e) {
133                         Assert(typeof(FormatException) == e.GetType());
134                 }
135                 //test Parse(string s, NumberStyles style, IFormatProvider provider)
136                 Assert(16 == Int16.Parse(" 10 ", NumberStyles.HexNumber, Nfi));
137                 try {
138                         Int16.Parse("$42", NumberStyles.Integer, Nfi);
139                         Fail("Should raise a System.FormatException");
140                 }
141                 catch (Exception e) {
142                         Assert(typeof(FormatException) == e.GetType());
143                 }
144         }
145         
146         public void TestToString()
147         {
148                 //test ToString()
149                 Assert(String.Compare(MyString1, MyInt16_1.ToString()) == 0);
150                 Assert(String.Compare(MyString2, MyInt16_2.ToString()) == 0);
151                 Assert(String.Compare(MyString3, MyInt16_3.ToString()) == 0);
152                 //test ToString(string format)
153                 for (int i=0; i < Formats1.Length; i++) {
154                         Assert(String.Compare(Results1[i], MyInt16_2.ToString(Formats1[i])) == 0);
155                         Assert(String.Compare(Results2[i], MyInt16_3.ToString(Formats2[i])) == 0);
156                 }
157                 //test ToString(string format, IFormatProvider provider);
158                 for (int i=0; i < Formats1.Length; i++) {
159                         Assert(String.Compare(ResultsNfi1[i], MyInt16_2.ToString(Formats1[i], Nfi)) == 0);
160                         Assert(String.Compare(ResultsNfi2[i], MyInt16_3.ToString(Formats2[i], Nfi)) == 0);
161                 }
162                 try {
163                         MyInt16_1.ToString("z");
164                         Fail("Should raise a System.FormatException");
165                 }
166                 catch (Exception e) {
167                         Assert(typeof(FormatException) == e.GetType());
168                 }
169         }
170 }
171
172 }