/src/System.Linq.Expressions/tests/Lifted/NonLiftedComparisonGreaterThanOrEqualNullableTests.cs

https://gitlab.com/0072016/0072016-corefx- · C# · 368 lines · 324 code · 41 blank · 3 comment · 24 complexity · 6504929c46837c699058a564a702ade2 MD5 · raw file

  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. using System;
  5. using Xunit;
  6. namespace System.Linq.Expressions.Tests
  7. {
  8. public static class NonLiftedComparisonGreaterThanOrEqualNullableTests
  9. {
  10. #region Test methods
  11. [Theory, ClassData(typeof(CompilationTypes))]
  12. public static void CheckNonLiftedComparisonGreaterThanOrEqualNullableByteTest(bool useInterpreter)
  13. {
  14. byte?[] values = new byte?[] { null, 0, 1, byte.MaxValue };
  15. for (int i = 0; i < values.Length; i++)
  16. {
  17. for (int j = 0; j < values.Length; j++)
  18. {
  19. VerifyComparisonGreaterThanOrEqualNullableByte(values[i], values[j], useInterpreter);
  20. }
  21. }
  22. }
  23. [Theory, ClassData(typeof(CompilationTypes))]
  24. public static void CheckNonLiftedComparisonGreaterThanOrEqualNullableCharTest(bool useInterpreter)
  25. {
  26. char?[] values = new char?[] { null, '\0', '\b', 'A', '\uffff' };
  27. for (int i = 0; i < values.Length; i++)
  28. {
  29. for (int j = 0; j < values.Length; j++)
  30. {
  31. VerifyComparisonGreaterThanOrEqualNullableChar(values[i], values[j], useInterpreter);
  32. }
  33. }
  34. }
  35. [Theory, ClassData(typeof(CompilationTypes))]
  36. public static void CheckNonLiftedComparisonGreaterThanOrEqualNullableDecimalTest(bool useInterpreter)
  37. {
  38. decimal?[] values = new decimal?[] { null, decimal.Zero, decimal.One, decimal.MinusOne, decimal.MinValue, decimal.MaxValue };
  39. for (int i = 0; i < values.Length; i++)
  40. {
  41. for (int j = 0; j < values.Length; j++)
  42. {
  43. VerifyComparisonGreaterThanOrEqualNullableDecimal(values[i], values[j], useInterpreter);
  44. }
  45. }
  46. }
  47. [Theory, ClassData(typeof(CompilationTypes))]
  48. public static void CheckNonLiftedComparisonGreaterThanOrEqualNullableDoubleTest(bool useInterpreter)
  49. {
  50. double?[] values = new double?[] { null, 0, 1, -1, double.MinValue, double.MaxValue, double.Epsilon, double.NegativeInfinity, double.PositiveInfinity, double.NaN };
  51. for (int i = 0; i < values.Length; i++)
  52. {
  53. for (int j = 0; j < values.Length; j++)
  54. {
  55. VerifyComparisonGreaterThanOrEqualNullableDouble(values[i], values[j], useInterpreter);
  56. }
  57. }
  58. }
  59. [Theory, ClassData(typeof(CompilationTypes))]
  60. public static void CheckNonLiftedComparisonGreaterThanOrEqualNullableFloatTest(bool useInterpreter)
  61. {
  62. float?[] values = new float?[] { null, 0, 1, -1, float.MinValue, float.MaxValue, float.Epsilon, float.NegativeInfinity, float.PositiveInfinity, float.NaN };
  63. for (int i = 0; i < values.Length; i++)
  64. {
  65. for (int j = 0; j < values.Length; j++)
  66. {
  67. VerifyComparisonGreaterThanOrEqualNullableFloat(values[i], values[j], useInterpreter);
  68. }
  69. }
  70. }
  71. [Theory, ClassData(typeof(CompilationTypes))]
  72. public static void CheckNonLiftedComparisonGreaterThanOrEqualNullableIntTest(bool useInterpreter)
  73. {
  74. int?[] values = new int?[] { null, 0, 1, -1, int.MinValue, int.MaxValue };
  75. for (int i = 0; i < values.Length; i++)
  76. {
  77. for (int j = 0; j < values.Length; j++)
  78. {
  79. VerifyComparisonGreaterThanOrEqualNullableInt(values[i], values[j], useInterpreter);
  80. }
  81. }
  82. }
  83. [Theory, ClassData(typeof(CompilationTypes))]
  84. public static void CheckNonLiftedComparisonGreaterThanOrEqualNullableLongTest(bool useInterpreter)
  85. {
  86. long?[] values = new long?[] { null, 0, 1, -1, long.MinValue, long.MaxValue };
  87. for (int i = 0; i < values.Length; i++)
  88. {
  89. for (int j = 0; j < values.Length; j++)
  90. {
  91. VerifyComparisonGreaterThanOrEqualNullableLong(values[i], values[j], useInterpreter);
  92. }
  93. }
  94. }
  95. [Theory, ClassData(typeof(CompilationTypes))]
  96. public static void CheckNonLiftedComparisonGreaterThanOrEqualNullableSByteTest(bool useInterpreter)
  97. {
  98. sbyte?[] values = new sbyte?[] { null, 0, 1, -1, sbyte.MinValue, sbyte.MaxValue };
  99. for (int i = 0; i < values.Length; i++)
  100. {
  101. for (int j = 0; j < values.Length; j++)
  102. {
  103. VerifyComparisonGreaterThanOrEqualNullableSByte(values[i], values[j], useInterpreter);
  104. }
  105. }
  106. }
  107. [Theory, ClassData(typeof(CompilationTypes))]
  108. public static void CheckNonLiftedComparisonGreaterThanOrEqualNullableShortTest(bool useInterpreter)
  109. {
  110. short?[] values = new short?[] { null, 0, 1, -1, short.MinValue, short.MaxValue };
  111. for (int i = 0; i < values.Length; i++)
  112. {
  113. for (int j = 0; j < values.Length; j++)
  114. {
  115. VerifyComparisonGreaterThanOrEqualNullableShort(values[i], values[j], useInterpreter);
  116. }
  117. }
  118. }
  119. [Theory, ClassData(typeof(CompilationTypes))]
  120. public static void CheckNonLiftedComparisonGreaterThanOrEqualNullableUIntTest(bool useInterpreter)
  121. {
  122. uint?[] values = new uint?[] { null, 0, 1, uint.MaxValue };
  123. for (int i = 0; i < values.Length; i++)
  124. {
  125. for (int j = 0; j < values.Length; j++)
  126. {
  127. VerifyComparisonGreaterThanOrEqualNullableUInt(values[i], values[j], useInterpreter);
  128. }
  129. }
  130. }
  131. [Theory, ClassData(typeof(CompilationTypes))]
  132. public static void CheckNonLiftedComparisonGreaterThanOrEqualNullableULongTest(bool useInterpreter)
  133. {
  134. ulong?[] values = new ulong?[] { null, 0, 1, ulong.MaxValue };
  135. for (int i = 0; i < values.Length; i++)
  136. {
  137. for (int j = 0; j < values.Length; j++)
  138. {
  139. VerifyComparisonGreaterThanOrEqualNullableULong(values[i], values[j], useInterpreter);
  140. }
  141. }
  142. }
  143. [Theory, ClassData(typeof(CompilationTypes))]
  144. public static void CheckNonLiftedComparisonGreaterThanOrEqualNullableUShortTest(bool useInterpreter)
  145. {
  146. ushort?[] values = new ushort?[] { null, 0, 1, ushort.MaxValue };
  147. for (int i = 0; i < values.Length; i++)
  148. {
  149. for (int j = 0; j < values.Length; j++)
  150. {
  151. VerifyComparisonGreaterThanOrEqualNullableUShort(values[i], values[j], useInterpreter);
  152. }
  153. }
  154. }
  155. #endregion
  156. #region Test verifiers
  157. private static void VerifyComparisonGreaterThanOrEqualNullableByte(byte? a, byte? b, bool useInterpreter)
  158. {
  159. Expression<Func<bool>> e =
  160. Expression.Lambda<Func<bool>>(
  161. Expression.GreaterThanOrEqual(
  162. Expression.Constant(a, typeof(byte?)),
  163. Expression.Constant(b, typeof(byte?)),
  164. false,
  165. null));
  166. Func<bool> f = e.Compile(useInterpreter);
  167. bool expected = a >= b;
  168. bool result = f();
  169. Assert.Equal(expected, result);
  170. }
  171. private static void VerifyComparisonGreaterThanOrEqualNullableChar(char? a, char? b, bool useInterpreter)
  172. {
  173. Expression<Func<bool>> e =
  174. Expression.Lambda<Func<bool>>(
  175. Expression.GreaterThanOrEqual(
  176. Expression.Constant(a, typeof(char?)),
  177. Expression.Constant(b, typeof(char?)),
  178. false,
  179. null));
  180. Func<bool> f = e.Compile(useInterpreter);
  181. bool expected = a >= b;
  182. bool result = f();
  183. Assert.Equal(expected, result);
  184. }
  185. private static void VerifyComparisonGreaterThanOrEqualNullableDecimal(decimal? a, decimal? b, bool useInterpreter)
  186. {
  187. Expression<Func<bool>> e =
  188. Expression.Lambda<Func<bool>>(
  189. Expression.GreaterThanOrEqual(
  190. Expression.Constant(a, typeof(decimal?)),
  191. Expression.Constant(b, typeof(decimal?)),
  192. false,
  193. null));
  194. Func<bool> f = e.Compile(useInterpreter);
  195. bool expected = a >= b;
  196. bool result = f();
  197. Assert.Equal(expected, result);
  198. }
  199. private static void VerifyComparisonGreaterThanOrEqualNullableDouble(double? a, double? b, bool useInterpreter)
  200. {
  201. Expression<Func<bool>> e =
  202. Expression.Lambda<Func<bool>>(
  203. Expression.GreaterThanOrEqual(
  204. Expression.Constant(a, typeof(double?)),
  205. Expression.Constant(b, typeof(double?)),
  206. false,
  207. null));
  208. Func<bool> f = e.Compile(useInterpreter);
  209. bool expected = a >= b;
  210. bool result = f();
  211. Assert.Equal(expected, result);
  212. }
  213. private static void VerifyComparisonGreaterThanOrEqualNullableFloat(float? a, float? b, bool useInterpreter)
  214. {
  215. Expression<Func<bool>> e =
  216. Expression.Lambda<Func<bool>>(
  217. Expression.GreaterThanOrEqual(
  218. Expression.Constant(a, typeof(float?)),
  219. Expression.Constant(b, typeof(float?)),
  220. false,
  221. null));
  222. Func<bool> f = e.Compile(useInterpreter);
  223. bool expected = a >= b;
  224. bool result = f();
  225. Assert.Equal(expected, result);
  226. }
  227. private static void VerifyComparisonGreaterThanOrEqualNullableInt(int? a, int? b, bool useInterpreter)
  228. {
  229. Expression<Func<bool>> e =
  230. Expression.Lambda<Func<bool>>(
  231. Expression.GreaterThanOrEqual(
  232. Expression.Constant(a, typeof(int?)),
  233. Expression.Constant(b, typeof(int?)),
  234. false,
  235. null));
  236. Func<bool> f = e.Compile(useInterpreter);
  237. bool expected = a >= b;
  238. bool result = f();
  239. Assert.Equal(expected, result);
  240. }
  241. private static void VerifyComparisonGreaterThanOrEqualNullableLong(long? a, long? b, bool useInterpreter)
  242. {
  243. Expression<Func<bool>> e =
  244. Expression.Lambda<Func<bool>>(
  245. Expression.GreaterThanOrEqual(
  246. Expression.Constant(a, typeof(long?)),
  247. Expression.Constant(b, typeof(long?)),
  248. false,
  249. null));
  250. Func<bool> f = e.Compile(useInterpreter);
  251. bool expected = a >= b;
  252. bool result = f();
  253. Assert.Equal(expected, result);
  254. }
  255. private static void VerifyComparisonGreaterThanOrEqualNullableSByte(sbyte? a, sbyte? b, bool useInterpreter)
  256. {
  257. Expression<Func<bool>> e =
  258. Expression.Lambda<Func<bool>>(
  259. Expression.GreaterThanOrEqual(
  260. Expression.Constant(a, typeof(sbyte?)),
  261. Expression.Constant(b, typeof(sbyte?)),
  262. false,
  263. null));
  264. Func<bool> f = e.Compile(useInterpreter);
  265. bool expected = a >= b;
  266. bool result = f();
  267. Assert.Equal(expected, result);
  268. }
  269. private static void VerifyComparisonGreaterThanOrEqualNullableShort(short? a, short? b, bool useInterpreter)
  270. {
  271. Expression<Func<bool>> e =
  272. Expression.Lambda<Func<bool>>(
  273. Expression.GreaterThanOrEqual(
  274. Expression.Constant(a, typeof(short?)),
  275. Expression.Constant(b, typeof(short?)),
  276. false,
  277. null));
  278. Func<bool> f = e.Compile(useInterpreter);
  279. bool expected = a >= b;
  280. bool result = f();
  281. Assert.Equal(expected, result);
  282. }
  283. private static void VerifyComparisonGreaterThanOrEqualNullableUInt(uint? a, uint? b, bool useInterpreter)
  284. {
  285. Expression<Func<bool>> e =
  286. Expression.Lambda<Func<bool>>(
  287. Expression.GreaterThanOrEqual(
  288. Expression.Constant(a, typeof(uint?)),
  289. Expression.Constant(b, typeof(uint?)),
  290. false,
  291. null));
  292. Func<bool> f = e.Compile(useInterpreter);
  293. bool expected = a >= b;
  294. bool result = f();
  295. Assert.Equal(expected, result);
  296. }
  297. private static void VerifyComparisonGreaterThanOrEqualNullableULong(ulong? a, ulong? b, bool useInterpreter)
  298. {
  299. Expression<Func<bool>> e =
  300. Expression.Lambda<Func<bool>>(
  301. Expression.GreaterThanOrEqual(
  302. Expression.Constant(a, typeof(ulong?)),
  303. Expression.Constant(b, typeof(ulong?)),
  304. false,
  305. null));
  306. Func<bool> f = e.Compile(useInterpreter);
  307. bool expected = a >= b;
  308. bool result = f();
  309. Assert.Equal(expected, result);
  310. }
  311. private static void VerifyComparisonGreaterThanOrEqualNullableUShort(ushort? a, ushort? b, bool useInterpreter)
  312. {
  313. Expression<Func<bool>> e =
  314. Expression.Lambda<Func<bool>>(
  315. Expression.GreaterThanOrEqual(
  316. Expression.Constant(a, typeof(ushort?)),
  317. Expression.Constant(b, typeof(ushort?)),
  318. false,
  319. null));
  320. Func<bool> f = e.Compile(useInterpreter);
  321. bool expected = a >= b;
  322. bool result = f();
  323. Assert.Equal(expected, result);
  324. }
  325. #endregion
  326. }
  327. }