Skip to content

Commit 59b6abb

Browse files
committed
Enable nullable annotations and add CqlQuantity tests
Enabled `#nullable` annotations to improve null safety and reorganized `using` directives for clarity. Added a new `CqlQuantityTests` class with unit tests to validate `CqlQuantity` behavior, including negation operations and handling of `null` values. Made minor formatting adjustments for consistency and readability.
1 parent f9266ec commit 59b6abb

File tree

1 file changed

+71
-4
lines changed

1 file changed

+71
-4
lines changed

Cql/CoreTests/PrimitiveTests.cs

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
* available at https://raw.githubusercontent.com/FirelyTeam/firely-cql-sdk/main/LICENSE
77
*/
88

9+
#nullable enable
910
using Hl7.Cql.CodeGeneration.NET.Toolkit;
1011
using Hl7.Cql.Compiler;
11-
using Hl7.Cql.Elm;
1212
using Hl7.Cql.Fhir;
1313
using Hl7.Cql.Iso8601;
1414
using Hl7.Cql.Operators;
1515
using Hl7.Cql.Primitives;
1616
using Hl7.Cql.Runtime;
17-
using Hl7.Cql.Runtime.Hosting;
17+
using Hl7.Cql.Runtime.Hosting;
1818

1919
namespace CoreTests
20-
{
20+
{
2121
using DateTimePrecision = Hl7.Cql.Iso8601.DateTimePrecision;
2222
using Expression = System.Linq.Expressions.Expression;
2323

@@ -165,7 +165,7 @@ public void CqlDateTime_Subtract_Day_and_Days()
165165

166166
var tdExpr = Expression.Constant(threeDays);
167167
var odExpr = Expression.Constant(oneDay);
168-
168+
169169
var rc = GetNewContext();
170170
var fcq = rc.Operators;
171171
var memExpr = Expression.Constant(fcq);
@@ -278,6 +278,73 @@ public void CqlDateTime_WholeCalendarPeriodsBetween_Months()
278278
}
279279
}
280280

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+
281348
[TestClass]
282349
[TestCategory("UnitTest")]
283350
public class PrimitiveTests

0 commit comments

Comments
 (0)