forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMathTests.cs
136 lines (116 loc) · 2.78 KB
/
MathTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
using System;
using System.Linq;
using System.Linq.Expressions;
using NHibernate.DomainModel.Northwind.Entities;
using NUnit.Framework;
namespace NHibernate.Test.Linq
{
[TestFixture]
public class MathTests : LinqTestCase
{
private IQueryable<OrderLine> _orderLines;
protected override void OnSetUp()
{
base.OnSetUp();
_orderLines = db.OrderLines
.OrderBy(ol => ol.Id)
.Take(10).ToList().AsQueryable();
}
[Test]
public void SignAllPositiveTest()
{
AssumeFunctionSupported("sign");
var signs = (from o in db.OrderLines
select Math.Sign(o.UnitPrice)).ToList();
Assert.That(signs.All(x => x == 1), Is.True);
}
[Test]
public void SignAllNegativeTest()
{
AssumeFunctionSupported("sign");
var signs = (from o in db.OrderLines
select Math.Sign(0m - o.UnitPrice)).ToList();
Assert.That(signs.All(x => x == -1), Is.True);
}
[Test]
public void SinTest()
{
AssumeFunctionSupported("sin");
Test(o => Math.Round(Math.Sin((double) o.UnitPrice), 5));
}
[Test]
public void CosTest()
{
AssumeFunctionSupported("cos");
Test(o => Math.Round(Math.Cos((double)o.UnitPrice), 5));
}
[Test]
public void TanTest()
{
AssumeFunctionSupported("tan");
Test(o => Math.Round(Math.Tan((double)o.Discount), 5));
}
[Test]
public void SinhTest()
{
AssumeFunctionSupported("sinh");
Test(o => Math.Round(Math.Sinh((double)o.Discount), 5));
}
[Test]
public void CoshTest()
{
AssumeFunctionSupported("cosh");
Test(o => Math.Round(Math.Cosh((double)o.Discount), 5));
}
[Test]
public void TanhTest()
{
AssumeFunctionSupported("tanh");
Test(o => Math.Round(Math.Tanh((double)o.Discount), 5));
}
[Test]
public void AsinTest()
{
AssumeFunctionSupported("asin");
Test(o => Math.Round(Math.Asin((double)o.Discount), 5));
}
[Test]
public void AcosTest()
{
AssumeFunctionSupported("acos");
Test(o => Math.Round(Math.Acos((double)o.Discount), 5));
}
[Test]
public void AtanTest()
{
AssumeFunctionSupported("atan");
Test(o => Math.Round(Math.Atan((double)o.UnitPrice), 5));
}
[Test]
public void Atan2Test()
{
AssumeFunctionSupported("atan2");
Test(o => Math.Round(Math.Atan2((double)o.Discount, 0.5d), 5));
}
[Test]
public void PowTest()
{
AssumeFunctionSupported("power");
Test(o => Math.Round(Math.Pow((double)o.Discount, 0.5d), 5));
}
private void Test(Expression<Func<OrderLine, double>> selector)
{
var expected = _orderLines
.Select(selector)
.ToList();
var actual = db.OrderLines
.OrderBy(ol => ol.Id)
.Select(selector)
.Take(10)
.ToList();
Assert.AreEqual(expected.Count, actual.Count);
for (var i = 0; i < expected.Count; i++)
Assert.AreEqual(expected[i], actual[i], 0.000001);
}
}
}