|
6 | 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-cql-sdk/main/LICENSE
|
7 | 7 | */
|
8 | 8 |
|
| 9 | +#nullable enable |
9 | 10 | using Hl7.Cql.CodeGeneration.NET.Toolkit;
|
10 | 11 | using Hl7.Cql.Compiler;
|
11 |
| -using Hl7.Cql.Elm; |
12 | 12 | using Hl7.Cql.Fhir;
|
13 | 13 | using Hl7.Cql.Iso8601;
|
14 | 14 | using Hl7.Cql.Operators;
|
15 | 15 | using Hl7.Cql.Primitives;
|
16 | 16 | using Hl7.Cql.Runtime;
|
17 |
| -using Hl7.Cql.Runtime.Hosting; |
| 17 | +using Hl7.Cql.Runtime.Hosting; |
18 | 18 |
|
19 | 19 | namespace CoreTests
|
20 |
| -{ |
| 20 | +{ |
21 | 21 | using DateTimePrecision = Hl7.Cql.Iso8601.DateTimePrecision;
|
22 | 22 | using Expression = System.Linq.Expressions.Expression;
|
23 | 23 |
|
@@ -165,7 +165,7 @@ public void CqlDateTime_Subtract_Day_and_Days()
|
165 | 165 |
|
166 | 166 | var tdExpr = Expression.Constant(threeDays);
|
167 | 167 | var odExpr = Expression.Constant(oneDay);
|
168 |
| - |
| 168 | + |
169 | 169 | var rc = GetNewContext();
|
170 | 170 | var fcq = rc.Operators;
|
171 | 171 | var memExpr = Expression.Constant(fcq);
|
@@ -278,6 +278,73 @@ public void CqlDateTime_WholeCalendarPeriodsBetween_Months()
|
278 | 278 | }
|
279 | 279 | }
|
280 | 280 |
|
| 281 | + [TestClass] |
| 282 | + [TestCategory("UnitTest")] |
| 283 | + public class CqlQuantityTests |
| 284 | + { |
| 285 | + [TestMethod] |
| 286 | + public void Negate_PositiveValue_ReturnsNegativeValue() |
| 287 | + { |
| 288 | + var quantity = new CqlQuantity(5.5m, "mg"); |
| 289 | + var negated = CqlQuantity.Negate(quantity); |
| 290 | + |
| 291 | + Assert.IsNotNull(negated); |
| 292 | + Assert.AreEqual(-5.5m, negated.value); |
| 293 | + Assert.AreEqual("mg", negated.unit); |
| 294 | + } |
| 295 | + |
| 296 | + [TestMethod] |
| 297 | + public void Negate_NullValue_ReturnsNullValueWithUnit() |
| 298 | + { |
| 299 | + var quantity = new CqlQuantity(null, "mg"); |
| 300 | + var negated = CqlQuantity.Negate(quantity); |
| 301 | + |
| 302 | + Assert.IsNotNull(negated); |
| 303 | + Assert.IsNull(negated.value); |
| 304 | + Assert.AreEqual("mg", negated.unit); |
| 305 | + } |
| 306 | + |
| 307 | + [TestMethod] |
| 308 | + public void Negate_NullQuantity_ReturnsNull() |
| 309 | + { |
| 310 | + CqlQuantity? quantity = null; |
| 311 | + var negated = CqlQuantity.Negate(quantity); |
| 312 | + |
| 313 | + Assert.IsNull(negated); |
| 314 | + } |
| 315 | + |
| 316 | + [TestMethod] |
| 317 | + public void OperatorNegate_PositiveValue_ReturnsNegativeValue() |
| 318 | + { |
| 319 | + var quantity = new CqlQuantity(10m, "g"); |
| 320 | + var negated = -quantity; |
| 321 | + |
| 322 | + Assert.IsNotNull(negated); |
| 323 | + Assert.AreEqual(-10m, negated.value); |
| 324 | + Assert.AreEqual("g", negated.unit); |
| 325 | + } |
| 326 | + |
| 327 | + [TestMethod] |
| 328 | + public void OperatorNegate_NullValue_ReturnsNullValueWithUnit() |
| 329 | + { |
| 330 | + var quantity = new CqlQuantity(null, "g"); |
| 331 | + var negated = -quantity; |
| 332 | + |
| 333 | + Assert.IsNotNull(negated); |
| 334 | + Assert.IsNull(negated.value); |
| 335 | + Assert.AreEqual("g", negated.unit); |
| 336 | + } |
| 337 | + |
| 338 | + [TestMethod] |
| 339 | + public void OperatorNegate_NullQuantity_ReturnsNull() |
| 340 | + { |
| 341 | + CqlQuantity? quantity = null; |
| 342 | + var negated = -quantity; |
| 343 | + |
| 344 | + Assert.IsNull(negated); |
| 345 | + } |
| 346 | + } |
| 347 | + |
281 | 348 | [TestClass]
|
282 | 349 | [TestCategory("UnitTest")]
|
283 | 350 | public class PrimitiveTests
|
|
0 commit comments