DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SqlNumberTests.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2014 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 using System;
17 
18 using NUnit.Framework;
19 
20 namespace Deveel.Data.Sql.Objects {
21  [TestFixture]
22  [Category("SQL Objects")]
23  [Category("Numbers")]
24  public class SqlNumberTests {
25  [Test]
26  public void Create_FromInteger() {
27  var value = new SqlNumber((int) 45993);
28  Assert.IsFalse(value.IsNull);
29  Assert.IsTrue(value.CanBeInt32);
30  Assert.IsTrue(value.CanBeInt64);
31  Assert.AreEqual(0, value.Scale);
32  Assert.AreEqual(5, value.Precision);
33  Assert.AreEqual(NumericState.None, value.State);
34  Assert.AreEqual(1, value.Sign);
35  }
36 
37  [Test]
38  public void Create_FromBigInt() {
39  var value = new SqlNumber(4599356655L);
40  Assert.IsFalse(value.IsNull);
41  Assert.IsFalse(value.CanBeInt32);
42  Assert.IsTrue(value.CanBeInt64);
43  Assert.AreEqual(0, value.Scale);
44  Assert.AreEqual(10, value.Precision);
45  Assert.AreEqual(NumericState.None, value.State);
46  Assert.AreEqual(1, value.Sign);
47  }
48 
49  [Test]
50  public void Create_FromDouble() {
51  var value = new SqlNumber(459935.9803d);
52  Assert.IsFalse(value.IsNull);
53  Assert.IsFalse(value.CanBeInt32);
54  Assert.IsFalse(value.CanBeInt64);
55  Assert.AreEqual(28, value.Scale);
56  Assert.AreEqual(34, value.Precision);
57  Assert.AreEqual(NumericState.None, value.State);
58  Assert.AreEqual(1, value.Sign);
59  }
60 
61  [Test]
62  public void Parse_BigDecimal() {
63  var value = new SqlNumber();
64  Assert.DoesNotThrow(() => value = SqlNumber.Parse("98356278.911288837773848500069994933229238e45789"));
65  Assert.IsFalse(value.IsNull);
66  Assert.IsFalse(value.CanBeInt32);
67  Assert.IsFalse(value.CanBeInt64);
68  Assert.Greater(value.Precision, 40);
69  }
70 
71  [Test]
72  public void Convert_ToBoolean_Success() {
73  var value = SqlNumber.One;
74  var b = new SqlBoolean();
75  Assert.DoesNotThrow(() => b = (SqlBoolean)Convert.ChangeType(value, typeof(SqlBoolean)));
76  Assert.IsTrue(b);
77  }
78 
79  [Test]
80  public void Integer_Greater_True() {
81  var value1 = new SqlNumber(76);
82  var value2 = new SqlNumber(54);
83 
84  Assert.IsTrue(value1 > value2);
85  }
86 
87  [Test]
88  public static void BigNumber_Greater_True() {
89  var value1 = SqlNumber.Parse("98356278.911288837773848500069994933229238e45789");
90  var value2 = SqlNumber.Parse("348299.01991828833333333333488888388829911182227373738488847112349928");
91 
92  Assert.IsTrue(value1 > value2);
93  }
94  }
95 }
NumericState
Lists all the possible special states of a number.
Definition: NumericState.cs:21
static readonly SqlNumber One
Definition: SqlNumber.cs:30
Deveel.Data.Sql.Objects.SqlBoolean SqlBoolean
Definition: DataObject.cs:26
static SqlNumber Parse(string s)
Definition: SqlNumber.cs:738