forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMathFTests.cs
140 lines (120 loc) · 3.22 KB
/
MathFTests.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
137
138
139
140
#if NETCOREAPP2_0_OR_GREATER
using System;
using System.Linq;
using System.Linq.Expressions;
using NHibernate.DomainModel.Northwind.Entities;
using NUnit.Framework;
namespace NHibernate.Test.Linq
{
// [TestFixture] is omitted on purpose: it is not required by NUnit. It is used by the async generator
// to generated async tests. Async tests cannot works for this fixture due to using a non NHibernate
// queryable which will not be supported by NHibernate ToListAsync.
public class MathFTests : 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 MathF.Sign((float) 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 MathF.Sign(0f - (float) o.UnitPrice)).ToList();
Assert.That(signs.All(x => x == -1), Is.True);
}
[Test]
public void SinTest()
{
AssumeFunctionSupported("sin");
Test(o => MathF.Round(MathF.Sin((float) o.UnitPrice), 5));
}
[Test]
public void CosTest()
{
AssumeFunctionSupported("cos");
Test(o => MathF.Round(MathF.Cos((float)o.UnitPrice), 5));
}
[Test]
public void TanTest()
{
AssumeFunctionSupported("tan");
Test(o => MathF.Round(MathF.Tan((float)o.Discount), 5));
}
[Test]
public void SinhTest()
{
AssumeFunctionSupported("sinh");
Test(o => MathF.Round(MathF.Sinh((float)o.Discount), 5));
}
[Test]
public void CoshTest()
{
AssumeFunctionSupported("cosh");
Test(o => MathF.Round(MathF.Cosh((float)o.Discount), 5));
}
[Test]
public void TanhTest()
{
AssumeFunctionSupported("tanh");
Test(o => MathF.Round(MathF.Tanh((float)o.Discount), 5));
}
[Test]
public void AsinTest()
{
AssumeFunctionSupported("asin");
Test(o => MathF.Round(MathF.Asin((float)o.Discount), 5));
}
[Test]
public void AcosTest()
{
AssumeFunctionSupported("acos");
Test(o => MathF.Round(MathF.Acos((float)o.Discount), 5));
}
[Test]
public void AtanTest()
{
AssumeFunctionSupported("atan");
Test(o => MathF.Round(MathF.Atan((float)o.UnitPrice), 5));
}
[Test]
public void Atan2Test()
{
AssumeFunctionSupported("atan2");
Test(o => MathF.Round(MathF.Atan2((float)o.Discount, 0.5f), 5));
}
[Test]
public void PowTest()
{
AssumeFunctionSupported("power");
Test(o => MathF.Round(MathF.Pow((float)o.Discount, 0.5f), 5));
}
private void Test(Expression<Func<OrderLine, float>> 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);
}
}
}
#endif