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