2 // SqlSingleTest.cs - NUnit Test Cases for System.Data.SqlTypes.SqlSingle
5 // Ville Palo (vi64pa@koti.soon.fi)
6 // Martin Willemoes Hansen (mwh@sysrq.dk)
9 // (C) 2003 Martin Willemoes Hansen
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using NUnit.Framework;
37 using System.Data.SqlTypes;
38 using System.Threading;
39 using System.Globalization;
41 namespace MonoTests.System.Data.SqlTypes
44 public class SqlSingleTest
48 public void GetReady()
50 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
57 SqlSingle Test= new SqlSingle ((float)34.87);
58 SqlSingle Test2 = 45.2f;
60 Assert.AreEqual (34.87f, Test.Value, "#A01");
61 Assert.AreEqual (45.2f, Test2.Value, "#A02");
63 Test = new SqlSingle (-9000.6543);
64 Assert.AreEqual (-9000.6543f, Test.Value, "#A03");
69 public void PublicFields()
71 Assert.AreEqual (3.40282346638528859E+38f,
72 SqlSingle.MaxValue.Value, "#B01");
73 Assert.AreEqual (-3.40282346638528859E+38f,
74 SqlSingle.MinValue.Value, "#B02");
75 Assert.IsTrue (SqlSingle.Null.IsNull, "#B03");
76 Assert.AreEqual (0f, SqlSingle.Zero.Value, "#B04");
81 public void Properties()
83 SqlSingle Test = new SqlSingle (5443e12f);
84 SqlSingle Test1 = new SqlSingle (1);
86 Assert.IsTrue (SqlSingle.Null.IsNull, "#C01");
87 Assert.AreEqual (5443e12f, Test.Value, "#C02");
88 Assert.AreEqual ((float)1, Test1.Value, "#C03");
94 public void ArithmeticMethods()
96 SqlSingle Test0 = new SqlSingle (0);
97 SqlSingle Test1 = new SqlSingle (15E+18);
98 SqlSingle Test2 = new SqlSingle (-65E+6);
99 SqlSingle Test3 = new SqlSingle (5E+30);
100 SqlSingle Test4 = new SqlSingle (5E+18);
101 SqlSingle TestMax = new SqlSingle (SqlSingle.MaxValue.Value);
104 Assert.AreEqual (15E+18f, SqlSingle.Add (Test1, Test0).Value, "#D01A");
105 Assert.AreEqual (1.5E+19f, SqlSingle.Add (Test1, Test2).Value, "#D02A");
108 SqlSingle test = SqlSingle.Add (SqlSingle.MaxValue,
110 Assert.Fail ("#D03A");
111 } catch (Exception e) {
112 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#D04A");
116 Assert.AreEqual ((SqlSingle)3, SqlSingle.Divide (Test1, Test4), "#D01B");
117 Assert.AreEqual (-1.3E-23f, SqlSingle.Divide (Test2, Test3).Value, "#D02B");
120 SqlSingle test = SqlSingle.Divide(Test1, Test0).Value;
121 Assert.Fail ("#D03B");
122 } catch(Exception e) {
123 Assert.AreEqual (typeof (DivideByZeroException),
124 e.GetType (), "#D04B");
128 Assert.AreEqual ((float)(7.5E+37),
129 SqlSingle.Multiply (Test1, Test4).Value, "#D01D");
130 Assert.AreEqual ((float)0, SqlSingle.Multiply (Test1, Test0).Value, "#D02D");
133 SqlSingle test = SqlSingle.Multiply (TestMax, Test1);
134 Assert.Fail ("#D03D");
135 } catch (Exception e) {
136 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#D04D");
141 Assert.AreEqual ((float)(-5E+30),
142 SqlSingle.Subtract (Test1, Test3).Value, "#D01F");
145 SqlSingle test = SqlSingle.Subtract(
146 SqlSingle.MinValue, SqlSingle.MaxValue);
147 Assert.Fail ("D02F");
148 } catch (Exception e) {
149 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#D03F");
154 public void CompareTo()
156 SqlSingle Test1 = new SqlSingle (4E+30);
157 SqlSingle Test11 = new SqlSingle (4E+30);
158 SqlSingle Test2 = new SqlSingle (-9E+30);
159 SqlSingle Test3 = new SqlSingle (10000);
160 SqlString TestString = new SqlString ("This is a test");
162 Assert.IsTrue (Test1.CompareTo (Test3) > 0, "#E01");
163 Assert.IsTrue (Test2.CompareTo (Test3) < 0, "#E02");
164 Assert.IsTrue (Test1.CompareTo (Test11) == 0, "#E03");
165 Assert.IsTrue (Test11.CompareTo (SqlSingle.Null) > 0, "#E04");
168 Test1.CompareTo (TestString);
170 } catch(Exception e) {
171 Assert.AreEqual (typeof (ArgumentException), e.GetType (), "#E06");
176 public void EqualsMethods()
178 SqlSingle Test0 = new SqlSingle (0);
179 SqlSingle Test1 = new SqlSingle (1.58e30);
180 SqlSingle Test2 = new SqlSingle (1.8e32);
181 SqlSingle Test22 = new SqlSingle (1.8e32);
183 Assert.IsTrue (!Test0.Equals (Test1), "#F01");
184 Assert.IsTrue (!Test1.Equals (Test2), "#F02");
185 Assert.IsTrue (!Test2.Equals (new SqlString ("TEST")), "#F03");
186 Assert.IsTrue (Test2.Equals (Test22), "#F04");
188 // Static Equals()-method
189 Assert.IsTrue (SqlSingle.Equals (Test2, Test22).Value, "#F05");
190 Assert.IsTrue (!SqlSingle.Equals (Test1, Test2).Value, "#F06");
194 public void GetHashCodeTest()
196 SqlSingle Test15 = new SqlSingle (15);
198 // FIXME: Better way to test HashCode
199 Assert.AreEqual (Test15.GetHashCode (), Test15.GetHashCode (), "#G01");
203 public void GetTypeTest()
205 SqlSingle Test = new SqlSingle (84);
206 Assert.AreEqual ("System.Data.SqlTypes.SqlSingle",
207 Test.GetType ().ToString (), "#H01");
208 Assert.AreEqual ("System.Single", Test.Value.GetType ().ToString (), "#H02");
212 public void Greaters()
214 SqlSingle Test1 = new SqlSingle (1e10);
215 SqlSingle Test11 = new SqlSingle (1e10);
216 SqlSingle Test2 = new SqlSingle (64e14);
219 Assert.IsTrue (!SqlSingle.GreaterThan (Test1, Test2).Value, "#I01");
220 Assert.IsTrue (SqlSingle.GreaterThan (Test2, Test1).Value, "#I02");
221 Assert.IsTrue (!SqlSingle.GreaterThan (Test1, Test11).Value, "#I03");
223 // GreaterTharOrEqual ()
224 Assert.IsTrue (!SqlSingle.GreaterThanOrEqual (Test1, Test2).Value, "#I04");
225 Assert.IsTrue (SqlSingle.GreaterThanOrEqual (Test2, Test1).Value, "#I05");
226 Assert.IsTrue (SqlSingle.GreaterThanOrEqual (Test1, Test11).Value, "#I06");
230 public void Lessers()
232 SqlSingle Test1 = new SqlSingle(1.8e10);
233 SqlSingle Test11 = new SqlSingle (1.8e10);
234 SqlSingle Test2 = new SqlSingle (64e14);
237 Assert.IsTrue (!SqlSingle.LessThan (Test1, Test11).Value, "#J01");
238 Assert.IsTrue (!SqlSingle.LessThan (Test2, Test1).Value, "#J02");
239 Assert.IsTrue (SqlSingle.LessThan (Test11, Test2).Value, "#J03");
241 // LessThanOrEqual ()
242 Assert.IsTrue (SqlSingle.LessThanOrEqual (Test1, Test2).Value, "#J04");
243 Assert.IsTrue (!SqlSingle.LessThanOrEqual (Test2, Test1).Value, "#J05");
244 Assert.IsTrue (SqlSingle.LessThanOrEqual (Test11, Test1).Value, "#J06");
245 Assert.IsTrue (SqlSingle.LessThanOrEqual (Test11, SqlSingle.Null).IsNull, "#J07");
249 public void NotEquals()
251 SqlSingle Test1 = new SqlSingle (12800000000001);
252 SqlSingle Test2 = new SqlSingle (128e10);
253 SqlSingle Test22 = new SqlSingle (128e10);
255 Assert.IsTrue (SqlSingle.NotEquals (Test1, Test2).Value, "#K01");
256 Assert.IsTrue (SqlSingle.NotEquals (Test2, Test1).Value, "#K02");
257 Assert.IsTrue (SqlSingle.NotEquals (Test22, Test1).Value, "#K03");
258 Assert.IsTrue (!SqlSingle.NotEquals (Test22, Test2).Value, "#K04");
259 Assert.IsTrue (!SqlSingle.NotEquals (Test2, Test22).Value, "#K05");
260 Assert.IsTrue (SqlSingle.NotEquals (SqlSingle.Null, Test22).IsNull, "#K06");
261 Assert.IsTrue (SqlSingle.NotEquals (SqlSingle.Null, Test22).IsNull, "#K07");
268 SqlSingle.Parse (null);
269 Assert.Fail ("#L01");
270 } catch (Exception e) {
271 Assert.AreEqual (typeof (ArgumentNullException), e.GetType (), "#L02");
275 SqlSingle.Parse ("not-a-number");
276 Assert.Fail ("#L03");
277 } catch (Exception e) {
278 Assert.AreEqual (typeof (FormatException), e.GetType (), "#L04");
282 SqlSingle.Parse ("9e44");
283 Assert.Fail ("#L05");
284 } catch (Exception e) {
285 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#L06");
288 Assert.AreEqual((float)150, SqlSingle.Parse ("150").Value, "#L07");
292 public void Conversions()
294 SqlSingle Test0 = new SqlSingle (0);
295 SqlSingle Test1 = new SqlSingle (250);
296 SqlSingle Test2 = new SqlSingle (64E+16);
297 SqlSingle Test3 = new SqlSingle (64E+30);
298 SqlSingle TestNull = SqlSingle.Null;
301 Assert.IsTrue (Test1.ToSqlBoolean ().Value, "#M01A");
302 Assert.IsTrue (!Test0.ToSqlBoolean ().Value, "#M02A");
303 Assert.IsTrue (TestNull.ToSqlBoolean ().IsNull, "#M03A");
306 Assert.AreEqual ((byte)250, Test1.ToSqlByte ().Value, "#M01B");
307 Assert.AreEqual ((byte)0, Test0.ToSqlByte ().Value, "#M02B");
310 SqlByte b = (byte)Test2.ToSqlByte ();
311 Assert.Fail ("#M03B");
312 } catch (Exception e) {
313 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#M04B");
317 Assert.AreEqual (250.00000000000000M, Test1.ToSqlDecimal ().Value, "#M01C");
318 Assert.AreEqual ((decimal)0, Test0.ToSqlDecimal ().Value, "#M02C");
321 SqlDecimal test = Test3.ToSqlDecimal ().Value;
322 Assert.Fail ("#M03C");
323 } catch (Exception e) {
324 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#M04C");
328 Assert.AreEqual ((short)250, Test1.ToSqlInt16 ().Value, "#M01D");
329 Assert.AreEqual ((short)0, Test0.ToSqlInt16 ().Value, "#M02D");
332 SqlInt16 test = Test2.ToSqlInt16().Value;
333 Assert.Fail ("#M03D");
334 } catch (Exception e) {
335 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#M04D");
339 Assert.AreEqual ((int)250, Test1.ToSqlInt32 ().Value, "#M01E");
340 Assert.AreEqual ((int)0, Test0.ToSqlInt32 ().Value, "#M02E");
343 SqlInt32 test = Test2.ToSqlInt32 ().Value;
344 Assert.Fail ("#M03E");
345 } catch (Exception e) {
346 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#M04E");
350 Assert.AreEqual ((long)250, Test1.ToSqlInt64 ().Value, "#M01F");
351 Assert.AreEqual ((long)0, Test0.ToSqlInt64 ().Value, "#M02F");
354 SqlInt64 test = Test3.ToSqlInt64 ().Value;
355 Assert.Fail ("#M03F");
356 } catch (Exception e) {
357 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#M04F");
361 Assert.AreEqual (250.0000M, Test1.ToSqlMoney ().Value, "#M01G");
362 Assert.AreEqual ((decimal)0, Test0.ToSqlMoney ().Value, "#M02G");
365 SqlMoney test = Test3.ToSqlMoney ().Value;
366 Assert.Fail ("#M03G");
367 } catch (Exception e) {
368 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#M04G");
373 Assert.AreEqual ("250", Test1.ToSqlString ().Value, "#M01H");
374 Assert.AreEqual ("0", Test0.ToSqlString ().Value, "#M02H");
375 Assert.AreEqual ("6.4E+17", Test2.ToSqlString ().Value, "#M03H");
378 Assert.AreEqual ("250", Test1.ToString (), "#M01I");
379 Assert.AreEqual ("0", Test0.ToString (), "#M02I");
380 Assert.AreEqual ("6.4E+17", Test2.ToString (), "#M03I");
386 public void ArithmeticOperators()
388 SqlSingle Test0 = new SqlSingle (0);
389 SqlSingle Test1 = new SqlSingle (24E+11);
390 SqlSingle Test2 = new SqlSingle (64E+32);
391 SqlSingle Test3 = new SqlSingle (12E+11);
392 SqlSingle Test4 = new SqlSingle (1E+10);
393 SqlSingle Test5 = new SqlSingle (2E+10);
396 Assert.AreEqual ((SqlSingle)3E+10, Test4 + Test5, "#N01");
399 SqlSingle test = SqlSingle.MaxValue + SqlSingle.MaxValue;
400 Assert.Fail ("#N02");
401 } catch (Exception e) {
402 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#N03");
406 SqlSingle test = SqlSingle.MaxValue + SqlSingle.MaxValue;
407 } catch (Exception e) {
408 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#N03a");
412 Assert.AreEqual ((SqlSingle)2, Test1 / Test3, "#N04");
415 SqlSingle test = Test3 / Test0;
416 Assert.Fail ("#N05");
417 } catch (Exception e) {
418 Assert.AreEqual (typeof (DivideByZeroException), e.GetType (), "#N06");
422 Assert.AreEqual ((SqlSingle)2E+20, Test4 * Test5, "#N07");
425 SqlSingle test = SqlSingle.MaxValue * Test1;
426 Assert.Fail ("#N08");
427 } catch (Exception e) {
428 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#N09");
432 Assert.AreEqual ((SqlSingle)12e11, Test1 - Test3, "#N10");
435 SqlSingle test = SqlSingle.MinValue - SqlSingle.MaxValue;
436 Assert.Fail ("#N11");
437 } catch (Exception e) {
438 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#N12");
443 public void ThanOrEqualOperators()
445 SqlSingle Test1 = new SqlSingle (1.0E+14f);
446 SqlSingle Test2 = new SqlSingle (9.7E+11);
447 SqlSingle Test22 = new SqlSingle (9.7E+11);
448 SqlSingle Test3 = new SqlSingle (2.0E+22f);
451 Assert.IsTrue ((Test2 == Test22).Value, "#O01");
452 Assert.IsTrue (!(Test1 == Test2).Value, "#O02");
453 Assert.IsTrue ((Test1 == SqlSingle.Null).IsNull, "#O03");
456 Assert.IsTrue (!(Test2 != Test22).Value, "#O04");
457 Assert.IsTrue ((Test2 != Test3).Value, "#O05");
458 Assert.IsTrue ((Test1 != Test3).Value, "#O06");
459 Assert.IsTrue ((Test1 != SqlSingle.Null).IsNull, "#O07");
462 Assert.IsTrue ((Test1 > Test2).Value, "#O08");
463 Assert.IsTrue (!(Test1 > Test3).Value, "#O09");
464 Assert.IsTrue (!(Test2 > Test22).Value, "#O10");
465 Assert.IsTrue ((Test1 > SqlSingle.Null).IsNull, "#O11");
468 Assert.IsTrue (!(Test1 >= Test3).Value, "#O12");
469 Assert.IsTrue ((Test3 >= Test1).Value, "#O13");
470 Assert.IsTrue ((Test2 >= Test22).Value, "#O14");
471 Assert.IsTrue ((Test1 >= SqlSingle.Null).IsNull, "#O15");
474 Assert.IsTrue (!(Test1 < Test2).Value, "#O16");
475 Assert.IsTrue ((Test1 < Test3).Value, "#O17");
476 Assert.IsTrue (!(Test2 < Test22).Value, "#O18");
477 Assert.IsTrue ((Test1 < SqlSingle.Null).IsNull, "#O19");
480 Assert.IsTrue ((Test1 <= Test3).Value, "#O20");
481 Assert.IsTrue (!(Test3 <= Test1).Value, "#O21");
482 Assert.IsTrue ((Test2 <= Test22).Value, "#O22");
483 Assert.IsTrue ((Test1 <= SqlSingle.Null).IsNull, "#O23");
487 public void UnaryNegation()
489 SqlSingle Test = new SqlSingle (2000000001);
490 SqlSingle TestNeg = new SqlSingle (-3000);
492 SqlSingle Result = -Test;
493 Assert.AreEqual ((float)(-2000000001), Result.Value, "#P01");
496 Assert.AreEqual ((float)3000, Result.Value, "#P02");
500 public void SqlBooleanToSqlSingle()
502 SqlBoolean TestBoolean = new SqlBoolean (true);
505 Result = (SqlSingle)TestBoolean;
507 Assert.AreEqual ((float)1, Result.Value, "#Q01");
509 Result = (SqlSingle)SqlBoolean.Null;
510 Assert.IsTrue (Result.IsNull, "#Q02");
514 public void SqlDoubleToSqlSingle()
516 SqlDouble Test = new SqlDouble (12e12);
517 SqlSingle TestSqlSingle = (SqlSingle)Test;
518 Assert.AreEqual (12e12f, TestSqlSingle.Value, "R01");
522 public void SqlSingleToSingle()
524 SqlSingle Test = new SqlSingle (12e12);
525 Single Result = (Single)Test;
526 Assert.AreEqual (12e12f, Result, "#S01");
530 public void SqlStringToSqlSingle()
532 SqlString TestString = new SqlString ("Test string");
533 SqlString TestString100 = new SqlString ("100");
535 Assert.AreEqual ((float)100, ((SqlSingle)TestString100).Value, "#T01");
538 SqlSingle test = (SqlSingle)TestString;
539 Assert.Fail ("#T02");
540 } catch(Exception e) {
541 Assert.AreEqual (typeof (FormatException), e.GetType (), "#T03");
546 public void ByteToSqlSingle()
548 short TestShort = 14;
549 Assert.AreEqual ((float)14, ((SqlSingle)TestShort).Value, "#U01");
553 public void SqlDecimalToSqlSingle()
555 SqlDecimal TestDecimal64 = new SqlDecimal (64);
557 Assert.AreEqual ((float)64, ((SqlSingle)TestDecimal64).Value, "#V01");
558 Assert.AreEqual (SqlSingle.Null, ((SqlSingle)SqlDecimal.Null), "#V02");
562 public void SqlIntToSqlSingle()
564 SqlInt16 Test64 = new SqlInt16 (64);
565 SqlInt32 Test640 = new SqlInt32 (640);
566 SqlInt64 Test64000 = new SqlInt64 (64000);
567 Assert.AreEqual ((float)64, ((SqlSingle)Test64).Value, "#W01");
568 Assert.AreEqual ((float)640, ((SqlSingle)Test640).Value, "#W02");
569 Assert.AreEqual ((float)64000, ((SqlSingle)Test64000).Value, "#W03");
573 public void SqlMoneyToSqlSingle()
575 SqlMoney TestMoney64 = new SqlMoney(64);
576 Assert.AreEqual ((float)64, ((SqlSingle)TestMoney64).Value, "#X01");
580 public void SingleToSqlSingle()
582 Single TestSingle64 = 64;
583 Assert.AreEqual ((float)64, ((SqlSingle)TestSingle64).Value, "#Y01");