Mercurial > pub > bltoolkit
comparison UnitTests/Linq/MathFunctions.cs @ 0:f990fcb411a9
Копия текущей версии из github
author | cin |
---|---|
date | Thu, 27 Mar 2014 21:46:09 +0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f990fcb411a9 |
---|---|
1 using System; | |
2 using System.Linq; | |
3 using BLToolkit.Data.Linq; | |
4 using NUnit.Framework; | |
5 | |
6 using BLToolkit.Data.DataProvider; | |
7 | |
8 namespace Data.Linq | |
9 { | |
10 [TestFixture] | |
11 public class MathFunctions : TestBase | |
12 { | |
13 [Test] | |
14 public void Abs() | |
15 { | |
16 ForEachProvider(db => AreEqual( | |
17 from t in from p in Types select Math.Abs(p.MoneyValue) where t > 0 select t, | |
18 from t in from p in db.Types select Math.Abs(p.MoneyValue) where t > 0 select t)); | |
19 } | |
20 | |
21 [Test] | |
22 public void Acos() | |
23 { | |
24 ForEachProvider(new[] { ProviderName.Access }, db => AreEqual( | |
25 from t in from p in Types select Math.Floor(Math.Acos((double)p.MoneyValue / 15) * 15) where t != 0.1 select t, | |
26 from t in from p in db.Types select Math.Floor(Math.Acos((double)p.MoneyValue / 15) * 15) where t != 0.1 select t)); | |
27 } | |
28 | |
29 [Test] | |
30 public void Asin() | |
31 { | |
32 ForEachProvider(new[] { ProviderName.Access }, db => AreEqual( | |
33 from t in from p in Types select Math.Floor(Math.Asin((double)p.MoneyValue / 15) * 15) where t != 0.1 select t, | |
34 from t in from p in db.Types select Math.Floor(Math.Asin((double)p.MoneyValue / 15) * 15) where t != 0.1 select t)); | |
35 } | |
36 | |
37 [Test] | |
38 public void Atan() | |
39 { | |
40 ForEachProvider(db => AreEqual( | |
41 from t in from p in Types select Math.Floor(Math.Atan((double)p.MoneyValue / 15) * 15) where t != 0.1 select t, | |
42 from t in from p in db.Types select Math.Floor(Math.Atan((double)p.MoneyValue / 15) * 15) where t != 0.1 select t)); | |
43 } | |
44 | |
45 [Test] | |
46 public void Atan2() | |
47 { | |
48 ForEachProvider(new[] { ProviderName.Access }, db => AreEqual( | |
49 from t in from p in Types select Math.Floor(Math.Atan2((double)p.MoneyValue / 15, 0) * 15) where t != 0.1 select t, | |
50 from t in from p in db.Types select Math.Floor(Math.Atan2((double)p.MoneyValue / 15, 0) * 15) where t != 0.1 select t)); | |
51 } | |
52 | |
53 [Test] | |
54 public void Ceiling1() | |
55 { | |
56 ForEachProvider(db => AreEqual( | |
57 from t in from p in Types select Math.Ceiling(-(p.MoneyValue + 1)) where t != 0 select t, | |
58 from t in from p in db.Types select Math.Ceiling(-(p.MoneyValue + 1)) where t != 0 select t)); | |
59 } | |
60 | |
61 [Test] | |
62 public void Ceiling2() | |
63 { | |
64 ForEachProvider(db => AreEqual( | |
65 from t in from p in Types select Math.Ceiling(p.MoneyValue) where t != 0 select t, | |
66 from t in from p in db.Types select Math.Ceiling(p.MoneyValue) where t != 0 select t)); | |
67 } | |
68 | |
69 [Test] | |
70 public void Cos() | |
71 { | |
72 ForEachProvider(db => AreEqual( | |
73 from t in from p in Types select Math.Floor(Math.Cos((double)p.MoneyValue / 15) * 15) where t != 0.1 select t, | |
74 from t in from p in db.Types select Math.Floor(Math.Cos((double)p.MoneyValue / 15) * 15) where t != 0.1 select t)); | |
75 } | |
76 | |
77 [Test] | |
78 public void Cosh() | |
79 { | |
80 ForEachProvider(db => AreEqual( | |
81 from t in from p in Types select Math.Floor(Math.Cosh((double)p.MoneyValue / 15) * 15) where t != 0.1 select t, | |
82 from t in from p in db.Types select Math.Floor(Math.Cosh((double)p.MoneyValue / 15) * 15) where t != 0.1 select t)); | |
83 } | |
84 | |
85 [Test] | |
86 public void Cot() | |
87 { | |
88 ForEachProvider(db => AreEqual( | |
89 from t in from p in Types select Math.Floor(Sql.Cot((double)p.MoneyValue / 15).Value * 15) where t != 0.1 select t, | |
90 from t in from p in db.Types select Math.Floor(Sql.Cot((double)p.MoneyValue / 15).Value * 15) where t != 0.1 select t)); | |
91 } | |
92 | |
93 [Test] | |
94 public void Deegrees1() | |
95 { | |
96 ForEachProvider(db => AreEqual( | |
97 from t in from p in Types select Math.Floor(Sql.Degrees(p.MoneyValue).Value) where t != 0.1m select t, | |
98 from t in from p in db.Types select Math.Floor(Sql.Degrees(p.MoneyValue).Value) where t != 0.1m select t)); | |
99 } | |
100 | |
101 [Test] | |
102 public void Deegrees2() | |
103 { | |
104 ForEachProvider(db => AreEqual( | |
105 from t in from p in Types select Sql.Degrees((double)p.MoneyValue).Value where t != 0.1 select Math.Floor(t), | |
106 from t in from p in db.Types select Sql.Degrees((double)p.MoneyValue).Value where t != 0.1 select Math.Floor(t))); | |
107 } | |
108 | |
109 [Test] | |
110 public void Deegrees3() | |
111 { | |
112 ForEachProvider(db => AreEqual( | |
113 from t in from p in Types select Sql.Degrees((int)p.MoneyValue).Value where t != 0.1 select t, | |
114 from t in from p in db.Types select Sql.Degrees((int)p.MoneyValue).Value where t != 0.1 select t)); | |
115 } | |
116 | |
117 [Test] | |
118 public void Exp() | |
119 { | |
120 ForEachProvider(db => AreEqual( | |
121 from t in from p in Types select Math.Floor(Math.Exp((double)p.MoneyValue)) where t != 0.1 select t, | |
122 from t in from p in db.Types select Math.Floor(Math.Exp((double)p.MoneyValue)) where t != 0.1 select t)); | |
123 } | |
124 | |
125 [Test] | |
126 public void Floor() | |
127 { | |
128 ForEachProvider(db => AreEqual( | |
129 from t in from p in Types select Math.Floor(-(p.MoneyValue + 1)) where t != 0 select t, | |
130 from t in from p in db.Types select Math.Floor(-(p.MoneyValue + 1)) where t != 0 select t)); | |
131 } | |
132 | |
133 [Test] | |
134 public void Log() | |
135 { | |
136 ForEachProvider(db => AreEqual( | |
137 from t in from p in Types select Math.Floor(Math.Log((double)p.MoneyValue)) where t != 0.1 select t, | |
138 from t in from p in db.Types select Math.Floor(Math.Log((double)p.MoneyValue)) where t != 0.1 select t)); | |
139 } | |
140 | |
141 [Test] | |
142 public void Log2() | |
143 { | |
144 ForEachProvider(db => AreEqual( | |
145 from t in from p in Types select Math.Floor(Math.Log((double)p.MoneyValue, 2)) where t != 0.1 select t, | |
146 from t in from p in db.Types select Math.Floor(Math.Log((double)p.MoneyValue, 2)) where t != 0.1 select t)); | |
147 } | |
148 | |
149 [Test] | |
150 public void Log10() | |
151 { | |
152 ForEachProvider(db => AreEqual( | |
153 from t in from p in Types select Math.Floor(Math.Log10((double)p.MoneyValue)) where t != 0.1 select t, | |
154 from t in from p in db.Types select Math.Floor(Math.Log10((double)p.MoneyValue)) where t != 0.1 select t)); | |
155 } | |
156 | |
157 [Test] | |
158 public void Max() | |
159 { | |
160 ForEachProvider(db => AreEqual( | |
161 from t in from p in Types select Math.Max(p.MoneyValue, 5) where t != 0 select t, | |
162 from t in from p in db.Types select Math.Max(p.MoneyValue, 5) where t != 0 select t)); | |
163 } | |
164 | |
165 [Test] | |
166 public void Min() | |
167 { | |
168 ForEachProvider(db => AreEqual( | |
169 from t in from p in Types select Math.Min(p.MoneyValue, 5) where t != 0 select t, | |
170 from t in from p in db.Types select Math.Min(p.MoneyValue, 5) where t != 0 select t)); | |
171 } | |
172 | |
173 [Test] | |
174 public void Pow() | |
175 { | |
176 ForEachProvider(db => AreEqual( | |
177 from t in from p in Types select Math.Floor(Math.Pow((double)p.MoneyValue, 3)) where t != 0 select t, | |
178 from t in from p in db.Types select Math.Floor(Math.Pow((double)p.MoneyValue, 3)) where t != 0 select t)); | |
179 } | |
180 | |
181 [Test] | |
182 public void Round1() | |
183 { | |
184 ForEachProvider(db => AreEqual( | |
185 from t in from p in Types select Math.Round(p.MoneyValue) where t != 0 select t, | |
186 from t in from p in db.Types select Math.Round(p.MoneyValue) where t != 0 select t)); | |
187 } | |
188 | |
189 [Test] | |
190 public void Round2() | |
191 { | |
192 ForEachProvider(db => AreEqual( | |
193 from t in from p in Types select Math.Round((double)p.MoneyValue) where t != 0 select t, | |
194 from t in from p in db.Types select Math.Round((double)p.MoneyValue) where t != 0 select t)); | |
195 } | |
196 | |
197 [Test] | |
198 public void Round3() | |
199 { | |
200 ForEachProvider(db => AreEqual( | |
201 from t in from p in Types select Math.Round(p.MoneyValue, 1) where t != 0 && t != 7 select t, | |
202 from t in from p in db.Types select Math.Round(p.MoneyValue, 1) where t != 0 && t != 7 select t)); | |
203 } | |
204 | |
205 [Test] | |
206 public void Round4() | |
207 { | |
208 ForEachProvider(db => AreEqual( | |
209 from t in from p in Types select Math.Round((double)p.MoneyValue, 1) where t != 0 select Math.Round(t, 5), | |
210 from t in from p in db.Types select Math.Round((double)p.MoneyValue, 1) where t != 0 select Math.Round(t, 5))); | |
211 } | |
212 | |
213 [Test] | |
214 public void Round5() | |
215 { | |
216 ForEachProvider(db => AreEqual( | |
217 from t in from p in Types select Math.Round(p.MoneyValue, MidpointRounding.AwayFromZero) where t != 0 select t, | |
218 from t in from p in db.Types select Math.Round(p.MoneyValue, MidpointRounding.AwayFromZero) where t != 0 select t)); | |
219 } | |
220 | |
221 [Test] | |
222 public void Round6() | |
223 { | |
224 ForEachProvider(db => AreEqual( | |
225 from t in from p in Types select Math.Round((double)p.MoneyValue, MidpointRounding.AwayFromZero) where t != 0 select t, | |
226 from t in from p in db.Types select Math.Round((double)p.MoneyValue, MidpointRounding.AwayFromZero) where t != 0 select t)); | |
227 } | |
228 | |
229 [Test] | |
230 public void Round7() | |
231 { | |
232 ForEachProvider(db => AreEqual( | |
233 from t in from p in Types select Math.Round(p.MoneyValue, MidpointRounding.ToEven) where t != 0 select t, | |
234 from t in from p in db.Types select Math.Round(p.MoneyValue, MidpointRounding.ToEven) where t != 0 select t)); | |
235 } | |
236 | |
237 [Test] | |
238 public void Round8() | |
239 { | |
240 ForEachProvider(db => AreEqual( | |
241 from t in from p in Types select Math.Round((double)p.MoneyValue, MidpointRounding.ToEven) where t != 0 select t, | |
242 from t in from p in db.Types select Math.Round((double)p.MoneyValue, MidpointRounding.ToEven) where t != 0 select t)); | |
243 } | |
244 | |
245 [Test] | |
246 public void Round9() | |
247 { | |
248 ForEachProvider(new[] { ProviderName.SQLite }, db => AreEqual( | |
249 from t in from p in Types select Math.Round(p.MoneyValue, 1, MidpointRounding.AwayFromZero) where t != 0 select t, | |
250 from t in from p in db.Types select Math.Round(p.MoneyValue, 1, MidpointRounding.AwayFromZero) where t != 0 select t)); | |
251 } | |
252 | |
253 [Test] | |
254 public void Round10() | |
255 { | |
256 ForEachProvider(db => AreEqual( | |
257 from t in from p in Types select Math.Round(p.MoneyValue, 1, MidpointRounding.ToEven) where t != 0 && t != 7 select t, | |
258 from t in from p in db.Types select Math.Round(p.MoneyValue, 1, MidpointRounding.ToEven) where t != 0 && t != 7 select t)); | |
259 } | |
260 | |
261 [Test] | |
262 public void Round11() | |
263 { | |
264 ForEachProvider(db => AreEqual( | |
265 from t in from p in Types select Math.Round((double)p.MoneyValue, 1, MidpointRounding.ToEven) where t != 0 select Math.Round(t, 5), | |
266 from t in from p in db.Types select Math.Round((double)p.MoneyValue, 1, MidpointRounding.ToEven) where t != 0 select Math.Round(t, 5))); | |
267 } | |
268 | |
269 [Test] | |
270 public void Round12() | |
271 { | |
272 var mp = MidpointRounding.AwayFromZero; | |
273 | |
274 ForEachProvider(new[] { ProviderName.SQLite }, db => AreEqual( | |
275 from t in from p in Types select Math.Round(p.MoneyValue, 1, mp) where t != 0 && t != 7 select t, | |
276 from t in from p in db.Types select Math.Round(p.MoneyValue, 1, mp) where t != 0 && t != 7 select t)); | |
277 } | |
278 | |
279 [Test] | |
280 public void Sign() | |
281 { | |
282 ForEachProvider(db => AreEqual( | |
283 from t in from p in Types select Math.Sign(p.MoneyValue) where t != 0 select t, | |
284 from t in from p in db.Types select Math.Sign(p.MoneyValue) where t != 0 select t)); | |
285 } | |
286 | |
287 [Test] | |
288 public void Sin() | |
289 { | |
290 ForEachProvider(db => AreEqual( | |
291 from t in from p in Types select Math.Floor(Math.Sin((double)p.MoneyValue / 15) * 15) where t != 0.1 select t, | |
292 from t in from p in db.Types select Math.Floor(Math.Sin((double)p.MoneyValue / 15) * 15) where t != 0.1 select t)); | |
293 } | |
294 | |
295 [Test] | |
296 public void Sinh() | |
297 { | |
298 ForEachProvider(db => AreEqual( | |
299 from t in from p in Types select Math.Floor(Math.Sinh((double)p.MoneyValue / 15) * 15) where t != 0.1 select t, | |
300 from t in from p in db.Types select Math.Floor(Math.Sinh((double)p.MoneyValue / 15) * 15) where t != 0.1 select t)); | |
301 } | |
302 | |
303 [Test] | |
304 public void Sqrt() | |
305 { | |
306 ForEachProvider(db => AreEqual( | |
307 from t in from p in Types select Math.Floor(Math.Sqrt((double)p.MoneyValue / 15) * 15) where t != 0.1 select t, | |
308 from t in from p in db.Types select Math.Floor(Math.Sqrt((double)p.MoneyValue / 15) * 15) where t != 0.1 select t)); | |
309 } | |
310 | |
311 [Test] | |
312 public void Tan() | |
313 { | |
314 ForEachProvider(db => AreEqual( | |
315 from t in from p in Types select Math.Floor(Math.Tan((double)p.MoneyValue / 15) * 15) where t != 0.1 select t, | |
316 from t in from p in db.Types select Math.Floor(Math.Tan((double)p.MoneyValue / 15) * 15) where t != 0.1 select t)); | |
317 } | |
318 | |
319 [Test] | |
320 public void Tanh() | |
321 { | |
322 ForEachProvider(db => AreEqual( | |
323 from t in from p in Types select Math.Floor(Math.Tanh((double)p.MoneyValue / 15) * 15) where t != 0.1 select t, | |
324 from t in from p in db.Types select Math.Floor(Math.Tanh((double)p.MoneyValue / 15) * 15) where t != 0.1 select t)); | |
325 } | |
326 | |
327 [Test] | |
328 public void Truncate1() | |
329 { | |
330 ForEachProvider(db => AreEqual( | |
331 from t in from p in Types select Math.Truncate(p.MoneyValue) where t != 0.1m select t, | |
332 from t in from p in db.Types select Math.Truncate(p.MoneyValue) where t != 0.1m select t)); | |
333 } | |
334 | |
335 [Test] | |
336 public void Truncate2() | |
337 { | |
338 ForEachProvider(db => AreEqual( | |
339 from t in from p in Types select Math.Truncate((double)-p.MoneyValue) where t != 0.1 select t, | |
340 from t in from p in db.Types select Math.Truncate((double)-p.MoneyValue) where t != 0.1 select t)); | |
341 } | |
342 } | |
343 } |