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;
38 using System.Data.SqlTypes;
39 using System.Threading;
40 using System.Globalization;
42 namespace MonoTests.System.Data.SqlTypes
45 public class SqlSingleTest
49 public void GetReady()
51 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
58 SqlSingle Test= new SqlSingle ((float)34.87);
59 SqlSingle Test2 = 45.2f;
61 Assert.AreEqual (34.87f, Test.Value, "#A01");
62 Assert.AreEqual (45.2f, Test2.Value, "#A02");
64 Test = new SqlSingle (-9000.6543);
65 Assert.AreEqual (-9000.6543f, Test.Value, "#A03");
70 public void PublicFields()
72 Assert.AreEqual (3.40282346638528859E+38f,
73 SqlSingle.MaxValue.Value, "#B01");
74 Assert.AreEqual (-3.40282346638528859E+38f,
75 SqlSingle.MinValue.Value, "#B02");
76 Assert.IsTrue (SqlSingle.Null.IsNull, "#B03");
77 Assert.AreEqual (0f, SqlSingle.Zero.Value, "#B04");
82 public void Properties()
84 SqlSingle Test = new SqlSingle (5443e12f);
85 SqlSingle Test1 = new SqlSingle (1);
87 Assert.IsTrue (SqlSingle.Null.IsNull, "#C01");
88 Assert.AreEqual (5443e12f, Test.Value, "#C02");
89 Assert.AreEqual ((float)1, Test1.Value, "#C03");
95 public void ArithmeticMethods()
97 SqlSingle Test0 = new SqlSingle (0);
98 SqlSingle Test1 = new SqlSingle (15E+18);
99 SqlSingle Test2 = new SqlSingle (-65E+6);
100 SqlSingle Test3 = new SqlSingle (5E+30);
101 SqlSingle Test4 = new SqlSingle (5E+18);
102 SqlSingle TestMax = new SqlSingle (SqlSingle.MaxValue.Value);
105 Assert.AreEqual (15E+18f, SqlSingle.Add (Test1, Test0).Value, "#D01A");
106 Assert.AreEqual (1.5E+19f, SqlSingle.Add (Test1, Test2).Value, "#D02A");
109 SqlSingle test = SqlSingle.Add (SqlSingle.MaxValue,
111 Assert.Fail ("#D03A");
112 } catch (Exception e) {
113 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#D04A");
117 Assert.AreEqual ((SqlSingle)3, SqlSingle.Divide (Test1, Test4), "#D01B");
118 Assert.AreEqual (-1.3E-23f, SqlSingle.Divide (Test2, Test3).Value, "#D02B");
121 SqlSingle test = SqlSingle.Divide(Test1, Test0).Value;
122 Assert.Fail ("#D03B");
123 } catch(Exception e) {
124 Assert.AreEqual (typeof (DivideByZeroException),
125 e.GetType (), "#D04B");
129 Assert.AreEqual ((float)(7.5E+37),
130 SqlSingle.Multiply (Test1, Test4).Value, "#D01D");
131 Assert.AreEqual ((float)0, SqlSingle.Multiply (Test1, Test0).Value, "#D02D");
134 SqlSingle test = SqlSingle.Multiply (TestMax, Test1);
135 Assert.Fail ("#D03D");
136 } catch (Exception e) {
137 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#D04D");
142 Assert.AreEqual ((float)(-5E+30),
143 SqlSingle.Subtract (Test1, Test3).Value, "#D01F");
146 SqlSingle test = SqlSingle.Subtract(
147 SqlSingle.MinValue, SqlSingle.MaxValue);
148 Assert.Fail ("D02F");
149 } catch (Exception e) {
150 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#D03F");
155 public void CompareTo()
157 SqlSingle Test1 = new SqlSingle (4E+30);
158 SqlSingle Test11 = new SqlSingle (4E+30);
159 SqlSingle Test2 = new SqlSingle (-9E+30);
160 SqlSingle Test3 = new SqlSingle (10000);
161 SqlString TestString = new SqlString ("This is a test");
163 Assert.IsTrue (Test1.CompareTo (Test3) > 0, "#E01");
164 Assert.IsTrue (Test2.CompareTo (Test3) < 0, "#E02");
165 Assert.IsTrue (Test1.CompareTo (Test11) == 0, "#E03");
166 Assert.IsTrue (Test11.CompareTo (SqlSingle.Null) > 0, "#E04");
169 Test1.CompareTo (TestString);
171 } catch(Exception e) {
172 Assert.AreEqual (typeof (ArgumentException), e.GetType (), "#E06");
177 public void EqualsMethods()
179 SqlSingle Test0 = new SqlSingle (0);
180 SqlSingle Test1 = new SqlSingle (1.58e30);
181 SqlSingle Test2 = new SqlSingle (1.8e32);
182 SqlSingle Test22 = new SqlSingle (1.8e32);
184 Assert.IsTrue (!Test0.Equals (Test1), "#F01");
185 Assert.IsTrue (!Test1.Equals (Test2), "#F02");
186 Assert.IsTrue (!Test2.Equals (new SqlString ("TEST")), "#F03");
187 Assert.IsTrue (Test2.Equals (Test22), "#F04");
189 // Static Equals()-method
190 Assert.IsTrue (SqlSingle.Equals (Test2, Test22).Value, "#F05");
191 Assert.IsTrue (!SqlSingle.Equals (Test1, Test2).Value, "#F06");
195 public void GetHashCodeTest()
197 SqlSingle Test15 = new SqlSingle (15);
199 // FIXME: Better way to test HashCode
200 Assert.AreEqual (Test15.GetHashCode (), Test15.GetHashCode (), "#G01");
204 public void GetTypeTest()
206 SqlSingle Test = new SqlSingle (84);
207 Assert.AreEqual ("System.Data.SqlTypes.SqlSingle",
208 Test.GetType ().ToString (), "#H01");
209 Assert.AreEqual ("System.Single", Test.Value.GetType ().ToString (), "#H02");
213 public void Greaters()
215 SqlSingle Test1 = new SqlSingle (1e10);
216 SqlSingle Test11 = new SqlSingle (1e10);
217 SqlSingle Test2 = new SqlSingle (64e14);
220 Assert.IsTrue (!SqlSingle.GreaterThan (Test1, Test2).Value, "#I01");
221 Assert.IsTrue (SqlSingle.GreaterThan (Test2, Test1).Value, "#I02");
222 Assert.IsTrue (!SqlSingle.GreaterThan (Test1, Test11).Value, "#I03");
224 // GreaterTharOrEqual ()
225 Assert.IsTrue (!SqlSingle.GreaterThanOrEqual (Test1, Test2).Value, "#I04");
226 Assert.IsTrue (SqlSingle.GreaterThanOrEqual (Test2, Test1).Value, "#I05");
227 Assert.IsTrue (SqlSingle.GreaterThanOrEqual (Test1, Test11).Value, "#I06");
231 public void Lessers()
233 SqlSingle Test1 = new SqlSingle(1.8e10);
234 SqlSingle Test11 = new SqlSingle (1.8e10);
235 SqlSingle Test2 = new SqlSingle (64e14);
238 Assert.IsTrue (!SqlSingle.LessThan (Test1, Test11).Value, "#J01");
239 Assert.IsTrue (!SqlSingle.LessThan (Test2, Test1).Value, "#J02");
240 Assert.IsTrue (SqlSingle.LessThan (Test11, Test2).Value, "#J03");
242 // LessThanOrEqual ()
243 Assert.IsTrue (SqlSingle.LessThanOrEqual (Test1, Test2).Value, "#J04");
244 Assert.IsTrue (!SqlSingle.LessThanOrEqual (Test2, Test1).Value, "#J05");
245 Assert.IsTrue (SqlSingle.LessThanOrEqual (Test11, Test1).Value, "#J06");
246 Assert.IsTrue (SqlSingle.LessThanOrEqual (Test11, SqlSingle.Null).IsNull, "#J07");
250 public void NotEquals()
252 SqlSingle Test1 = new SqlSingle (12800000000001);
253 SqlSingle Test2 = new SqlSingle (128e10);
254 SqlSingle Test22 = new SqlSingle (128e10);
256 Assert.IsTrue (SqlSingle.NotEquals (Test1, Test2).Value, "#K01");
257 Assert.IsTrue (SqlSingle.NotEquals (Test2, Test1).Value, "#K02");
258 Assert.IsTrue (SqlSingle.NotEquals (Test22, Test1).Value, "#K03");
259 Assert.IsTrue (!SqlSingle.NotEquals (Test22, Test2).Value, "#K04");
260 Assert.IsTrue (!SqlSingle.NotEquals (Test2, Test22).Value, "#K05");
261 Assert.IsTrue (SqlSingle.NotEquals (SqlSingle.Null, Test22).IsNull, "#K06");
262 Assert.IsTrue (SqlSingle.NotEquals (SqlSingle.Null, Test22).IsNull, "#K07");
269 SqlSingle.Parse (null);
270 Assert.Fail ("#L01");
271 } catch (Exception e) {
272 Assert.AreEqual (typeof (ArgumentNullException), e.GetType (), "#L02");
276 SqlSingle.Parse ("not-a-number");
277 Assert.Fail ("#L03");
278 } catch (Exception e) {
279 Assert.AreEqual (typeof (FormatException), e.GetType (), "#L04");
283 SqlSingle.Parse ("9e44");
284 Assert.Fail ("#L05");
285 } catch (Exception e) {
286 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#L06");
289 Assert.AreEqual((float)150, SqlSingle.Parse ("150").Value, "#L07");
293 public void Conversions()
295 SqlSingle Test0 = new SqlSingle (0);
296 SqlSingle Test1 = new SqlSingle (250);
297 SqlSingle Test2 = new SqlSingle (64E+16);
298 SqlSingle Test3 = new SqlSingle (64E+30);
299 SqlSingle TestNull = SqlSingle.Null;
302 Assert.IsTrue (Test1.ToSqlBoolean ().Value, "#M01A");
303 Assert.IsTrue (!Test0.ToSqlBoolean ().Value, "#M02A");
304 Assert.IsTrue (TestNull.ToSqlBoolean ().IsNull, "#M03A");
307 Assert.AreEqual ((byte)250, Test1.ToSqlByte ().Value, "#M01B");
308 Assert.AreEqual ((byte)0, Test0.ToSqlByte ().Value, "#M02B");
311 SqlByte b = (byte)Test2.ToSqlByte ();
312 Assert.Fail ("#M03B");
313 } catch (Exception e) {
314 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#M04B");
318 Assert.AreEqual (250.00000000000000M, Test1.ToSqlDecimal ().Value, "#M01C");
319 Assert.AreEqual ((decimal)0, Test0.ToSqlDecimal ().Value, "#M02C");
322 SqlDecimal test = Test3.ToSqlDecimal ().Value;
323 Assert.Fail ("#M03C");
324 } catch (Exception e) {
325 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#M04C");
329 Assert.AreEqual ((short)250, Test1.ToSqlInt16 ().Value, "#M01D");
330 Assert.AreEqual ((short)0, Test0.ToSqlInt16 ().Value, "#M02D");
333 SqlInt16 test = Test2.ToSqlInt16().Value;
334 Assert.Fail ("#M03D");
335 } catch (Exception e) {
336 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#M04D");
340 Assert.AreEqual ((int)250, Test1.ToSqlInt32 ().Value, "#M01E");
341 Assert.AreEqual ((int)0, Test0.ToSqlInt32 ().Value, "#M02E");
344 SqlInt32 test = Test2.ToSqlInt32 ().Value;
345 Assert.Fail ("#M03E");
346 } catch (Exception e) {
347 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#M04E");
351 Assert.AreEqual ((long)250, Test1.ToSqlInt64 ().Value, "#M01F");
352 Assert.AreEqual ((long)0, Test0.ToSqlInt64 ().Value, "#M02F");
355 SqlInt64 test = Test3.ToSqlInt64 ().Value;
356 Assert.Fail ("#M03F");
357 } catch (Exception e) {
358 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#M04F");
362 Assert.AreEqual (250.0000M, Test1.ToSqlMoney ().Value, "#M01G");
363 Assert.AreEqual ((decimal)0, Test0.ToSqlMoney ().Value, "#M02G");
366 SqlMoney test = Test3.ToSqlMoney ().Value;
367 Assert.Fail ("#M03G");
368 } catch (Exception e) {
369 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#M04G");
374 Assert.AreEqual ("250", Test1.ToSqlString ().Value, "#M01H");
375 Assert.AreEqual ("0", Test0.ToSqlString ().Value, "#M02H");
376 Assert.AreEqual ("6.4E+17", Test2.ToSqlString ().Value, "#M03H");
379 Assert.AreEqual ("250", Test1.ToString (), "#M01I");
380 Assert.AreEqual ("0", Test0.ToString (), "#M02I");
381 Assert.AreEqual ("6.4E+17", Test2.ToString (), "#M03I");
387 public void ArithmeticOperators()
389 SqlSingle Test0 = new SqlSingle (0);
390 SqlSingle Test1 = new SqlSingle (24E+11);
391 SqlSingle Test2 = new SqlSingle (64E+32);
392 SqlSingle Test3 = new SqlSingle (12E+11);
393 SqlSingle Test4 = new SqlSingle (1E+10);
394 SqlSingle Test5 = new SqlSingle (2E+10);
397 Assert.AreEqual ((SqlSingle)3E+10, Test4 + Test5, "#N01");
400 SqlSingle test = SqlSingle.MaxValue + SqlSingle.MaxValue;
401 Assert.Fail ("#N02");
402 } catch (Exception e) {
403 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#N03");
407 SqlSingle test = SqlSingle.MaxValue + SqlSingle.MaxValue;
408 } catch (Exception e) {
409 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#N03a");
413 Assert.AreEqual ((SqlSingle)2, Test1 / Test3, "#N04");
416 SqlSingle test = Test3 / Test0;
417 Assert.Fail ("#N05");
418 } catch (Exception e) {
419 Assert.AreEqual (typeof (DivideByZeroException), e.GetType (), "#N06");
423 Assert.AreEqual ((SqlSingle)2E+20, Test4 * Test5, "#N07");
426 SqlSingle test = SqlSingle.MaxValue * Test1;
427 Assert.Fail ("#N08");
428 } catch (Exception e) {
429 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#N09");
433 Assert.AreEqual ((SqlSingle)12e11, Test1 - Test3, "#N10");
436 SqlSingle test = SqlSingle.MinValue - SqlSingle.MaxValue;
437 Assert.Fail ("#N11");
438 } catch (Exception e) {
439 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#N12");
444 public void ThanOrEqualOperators()
446 SqlSingle Test1 = new SqlSingle (1.0E+14f);
447 SqlSingle Test2 = new SqlSingle (9.7E+11);
448 SqlSingle Test22 = new SqlSingle (9.7E+11);
449 SqlSingle Test3 = new SqlSingle (2.0E+22f);
452 Assert.IsTrue ((Test2 == Test22).Value, "#O01");
453 Assert.IsTrue (!(Test1 == Test2).Value, "#O02");
454 Assert.IsTrue ((Test1 == SqlSingle.Null).IsNull, "#O03");
457 Assert.IsTrue (!(Test2 != Test22).Value, "#O04");
458 Assert.IsTrue ((Test2 != Test3).Value, "#O05");
459 Assert.IsTrue ((Test1 != Test3).Value, "#O06");
460 Assert.IsTrue ((Test1 != SqlSingle.Null).IsNull, "#O07");
463 Assert.IsTrue ((Test1 > Test2).Value, "#O08");
464 Assert.IsTrue (!(Test1 > Test3).Value, "#O09");
465 Assert.IsTrue (!(Test2 > Test22).Value, "#O10");
466 Assert.IsTrue ((Test1 > SqlSingle.Null).IsNull, "#O11");
469 Assert.IsTrue (!(Test1 >= Test3).Value, "#O12");
470 Assert.IsTrue ((Test3 >= Test1).Value, "#O13");
471 Assert.IsTrue ((Test2 >= Test22).Value, "#O14");
472 Assert.IsTrue ((Test1 >= SqlSingle.Null).IsNull, "#O15");
475 Assert.IsTrue (!(Test1 < Test2).Value, "#O16");
476 Assert.IsTrue ((Test1 < Test3).Value, "#O17");
477 Assert.IsTrue (!(Test2 < Test22).Value, "#O18");
478 Assert.IsTrue ((Test1 < SqlSingle.Null).IsNull, "#O19");
481 Assert.IsTrue ((Test1 <= Test3).Value, "#O20");
482 Assert.IsTrue (!(Test3 <= Test1).Value, "#O21");
483 Assert.IsTrue ((Test2 <= Test22).Value, "#O22");
484 Assert.IsTrue ((Test1 <= SqlSingle.Null).IsNull, "#O23");
488 public void UnaryNegation()
490 SqlSingle Test = new SqlSingle (2000000001);
491 SqlSingle TestNeg = new SqlSingle (-3000);
493 SqlSingle Result = -Test;
494 Assert.AreEqual ((float)(-2000000001), Result.Value, "#P01");
497 Assert.AreEqual ((float)3000, Result.Value, "#P02");
501 public void SqlBooleanToSqlSingle()
503 SqlBoolean TestBoolean = new SqlBoolean (true);
506 Result = (SqlSingle)TestBoolean;
508 Assert.AreEqual ((float)1, Result.Value, "#Q01");
510 Result = (SqlSingle)SqlBoolean.Null;
511 Assert.IsTrue (Result.IsNull, "#Q02");
515 public void SqlDoubleToSqlSingle()
517 SqlDouble Test = new SqlDouble (12e12);
518 SqlSingle TestSqlSingle = (SqlSingle)Test;
519 Assert.AreEqual (12e12f, TestSqlSingle.Value, "R01");
523 public void SqlSingleToSingle()
525 SqlSingle Test = new SqlSingle (12e12);
526 Single Result = (Single)Test;
527 Assert.AreEqual (12e12f, Result, "#S01");
531 public void SqlStringToSqlSingle()
533 SqlString TestString = new SqlString ("Test string");
534 SqlString TestString100 = new SqlString ("100");
536 Assert.AreEqual ((float)100, ((SqlSingle)TestString100).Value, "#T01");
539 SqlSingle test = (SqlSingle)TestString;
540 Assert.Fail ("#T02");
541 } catch(Exception e) {
542 Assert.AreEqual (typeof (FormatException), e.GetType (), "#T03");
547 public void ByteToSqlSingle()
549 short TestShort = 14;
550 Assert.AreEqual ((float)14, ((SqlSingle)TestShort).Value, "#U01");
554 public void SqlDecimalToSqlSingle()
556 SqlDecimal TestDecimal64 = new SqlDecimal (64);
558 Assert.AreEqual ((float)64, ((SqlSingle)TestDecimal64).Value, "#V01");
559 Assert.AreEqual (SqlSingle.Null, ((SqlSingle)SqlDecimal.Null), "#V02");
563 public void SqlIntToSqlSingle()
565 SqlInt16 Test64 = new SqlInt16 (64);
566 SqlInt32 Test640 = new SqlInt32 (640);
567 SqlInt64 Test64000 = new SqlInt64 (64000);
568 Assert.AreEqual ((float)64, ((SqlSingle)Test64).Value, "#W01");
569 Assert.AreEqual ((float)640, ((SqlSingle)Test640).Value, "#W02");
570 Assert.AreEqual ((float)64000, ((SqlSingle)Test64000).Value, "#W03");
574 public void SqlMoneyToSqlSingle()
576 SqlMoney TestMoney64 = new SqlMoney(64);
577 Assert.AreEqual ((float)64, ((SqlSingle)TestMoney64).Value, "#X01");
581 public void SingleToSqlSingle()
583 Single TestSingle64 = 64;
584 Assert.AreEqual ((float)64, ((SqlSingle)TestSingle64).Value, "#Y01");
587 public void GetXsdTypeTest ()
589 XmlQualifiedName qualifiedName = SqlSingle.GetXsdType (null);
590 NUnit.Framework.Assert.AreEqual ("float", qualifiedName.Name, "#A01");