Skip to content

Commit ca997fc

Browse files
committed
Modernizes test code syntax
Uses collection expressions and generic `Enum.GetValues`, suppresses obsolete member warnings, and removes an unnecessary assertion.
1 parent 228744e commit ca997fc

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tests/MaterialColorUtilities.Tests/ContrastConstraintTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public sealed class SchemeCorrectnessTests
1313
unchecked((int)0xFFFF0000), // red
1414
};
1515

16-
private static readonly double[] ContrastLevels = { -1.0, 0.0, 0.5, 1.0 };
16+
private static readonly double[] ContrastLevels = [-1.0, 0.0, 0.5, 1.0];
1717

1818
private readonly MaterialDynamicColors _mdc = new();
1919

@@ -104,10 +104,12 @@ public void TestAgainst(DynamicScheme scheme)
104104
var aTone = _a.GetHct(scheme).Tone;
105105
var bTone = _b.GetHct(scheme).Tone;
106106

107+
#pragma warning disable CS0618 // Type or member is obsolete
107108
var aShouldBeLighter =
108109
(_polarity == TonePolarity.Lighter) ||
109110
(_polarity == TonePolarity.Nearer && !scheme.IsDark) ||
110111
(_polarity == TonePolarity.Farther && scheme.IsDark);
112+
#pragma warning restore CS0618 // Type or member is obsolete
111113

112114
var actual = aShouldBeLighter ? (aTone - bTone) : (bTone - aTone);
113115
if (actual < _delta - DeltaTolerance)
@@ -275,11 +277,13 @@ private List<IConstraint> BuildConstraints()
275277
new ContrastConstraint(DC("on_tertiary_fixed"), "on_tertiary_fixed", DC("tertiary_fixed"), "tertiary_fixed", new ContrastCurve(4.5, 7, 11, 21)),
276278
new ContrastConstraint(DC("on_tertiary_fixed"), "on_tertiary_fixed", DC("tertiary_fixed_dim"), "tertiary_fixed_dim", new ContrastCurve(4.5, 7, 11, 21)),
277279

280+
#pragma warning disable CS0618 // Type or member is obsolete
278281
// Delta constraints
279282
new DeltaConstraint(DC("primary"), "primary", DC("primary_container"), "primary_container", 10, TonePolarity.Farther),
280283
new DeltaConstraint(DC("secondary"), "secondary", DC("secondary_container"), "secondary_container", 10, TonePolarity.Farther),
281284
new DeltaConstraint(DC("tertiary"), "tertiary", DC("tertiary_container"), "tertiary_container", 10, TonePolarity.Farther),
282285
new DeltaConstraint(DC("error"), "error", DC("error_container"), "error_container", 10, TonePolarity.Farther),
286+
#pragma warning restore CS0618 // Type or member is obsolete
283287

284288
new DeltaConstraint(DC("primary_fixed_dim"), "primary_fixed_dim", DC("primary_fixed"), "primary_fixed", 10, TonePolarity.Darker),
285289
new DeltaConstraint(DC("secondary_fixed_dim"), "secondary_fixed_dim", DC("secondary_fixed"), "secondary_fixed", 10, TonePolarity.Darker),
@@ -334,7 +338,7 @@ public async Task Scheme_Correctness_All()
334338
{
335339
var constraints = BuildConstraints();
336340

337-
foreach (var variant in Enum.GetValues(typeof(Variant)).Cast<Variant>())
341+
foreach (var variant in Enum.GetValues<Variant>().Cast<Variant>())
338342
foreach (var contrastLevel in ContrastLevels)
339343
foreach (var argb in SeedArgb)
340344
foreach (var isDark in new[] { false, true })
@@ -348,7 +352,6 @@ public async Task Scheme_Correctness_All()
348352
}
349353

350354
// If we got here, constraints passed for this (variant, seed, CL, dark) tuple.
351-
await Assert.That(true).IsTrue(); // keep async signature satisfied
352355
}
353356
}
354357
}

0 commit comments

Comments
 (0)