Skip to content

Commit 0a98ae8

Browse files
committed
warning fixes.
1 parent ebcb441 commit 0a98ae8

8 files changed

Lines changed: 59 additions & 50 deletions

File tree

Test_Numerics/Machine Learning/Supervised/Test_RandomForest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void Test_RandomForest_Iris()
8989
var accuracy = GoodnessOfFit.Accuracy(Y_test.Array, prediction.GetColumn(1));
9090

9191
// Accuracy should be greater than or equal to 90%
92-
Assert.IsTrue(accuracy >= 90);
92+
Assert.IsGreaterThanOrEqualTo(90, accuracy);
9393

9494
}
9595

@@ -133,7 +133,7 @@ public void Test_RandomForest_Regression()
133133
var lmR2 = GoodnessOfFit.RSquared(Y_test.Array, lmPredict);
134134

135135
// Random Forest is better
136-
Assert.IsTrue(rfR2 > lmR2);
136+
Assert.IsGreaterThan(lmR2, rfR2 );
137137

138138
}
139139
}

Test_Numerics/Machine Learning/Supervised/Test_kNN.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public void Test_kNN_Regression()
162162
var lmR2 = GoodnessOfFit.RSquared(Y_test.Array, lmPredict);
163163

164164
// kNN is better
165-
Assert.IsTrue(knnR2 > lmR2);
165+
Assert.IsGreaterThan(lmR2, knnR2 );
166166

167167
}
168168

Test_Numerics/Mathematics/Integration/Test_Vegas.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,12 @@ public void Test_PowerTransform_RareUpperTailEvent()
209209

210210
// Analytical approximation: P(Sum > mean + 3σ) = P(Z > 3) ≈ 0.00135
211211
// We expect something in the ballpark of 1e-3 to 2e-3
212-
Assert.IsTrue(failureProbability > 5E-4, $"Probability too small: {failureProbability:E6}");
213-
Assert.IsTrue(failureProbability < 5E-3, $"Probability too large: {failureProbability:E6}");
212+
Assert.IsGreaterThan(5E-4, failureProbability );
213+
Assert.IsLessThan(5E-3, failureProbability );
214214

215215
// Standard error should be reasonable (less than 50% of estimate)
216216
double relativeError = vegas.StandardError / Math.Abs(failureProbability);
217-
Assert.IsTrue(relativeError < 0.5, $"Relative error too large: {relativeError:P1}");
217+
Assert.IsLessThan(0.5, relativeError);
218218
}
219219

220220
/// <summary>
@@ -255,14 +255,14 @@ public void Test_PowerTransform_VeryRareEvent()
255255
var failureProbability = vegas.Result;
256256

257257
// Should be in ballpark of 1e-6 to 1e-5
258-
Assert.IsTrue(failureProbability > 1E-7, $"Probability too small: {failureProbability:E2}");
259-
Assert.IsTrue(failureProbability < 1E-4, $"Probability too large: {failureProbability:E2}");
258+
Assert.IsGreaterThan(1E-7, failureProbability);
259+
Assert.IsLessThan(1E-4, failureProbability);
260260

261261
// For very rare events, relative error can be higher but should be finite
262262
double relativeError = vegas.StandardError / Math.Abs(failureProbability);
263-
Assert.IsTrue(relativeError < 1.0, $"Relative error too large: {relativeError:P1}");
264-
Assert.IsTrue(!double.IsNaN(failureProbability), "Result should not be NaN");
265-
Assert.IsTrue(!double.IsInfinity(failureProbability), "Result should not be infinite");
263+
Assert.IsLessThan(1.0, relativeError);
264+
Assert.IsFalse(double.IsNaN(failureProbability), "Result should not be NaN");
265+
Assert.IsFalse(double.IsInfinity(failureProbability), "Result should not be infinite");
266266
}
267267

268268
/// <summary>
@@ -311,13 +311,13 @@ public void Test_PowerTransform_ProbabilityRange()
311311
vegas.Integrate();
312312

313313
// Verify samples were generated
314-
Assert.IsTrue(sampleCount > 0, "No samples generated");
314+
Assert.IsGreaterThan( 0, sampleCount );
315315

316316
// With γ=4, should see strong tail focus (many samples near 1.0)
317-
Assert.IsTrue(maxObserved > 0.99, $"Max probability too low: {maxObserved}");
317+
Assert.IsGreaterThan(0.99, maxObserved );
318318

319319
// Should still have some diversity (not all at 1.0)
320-
Assert.IsTrue(minObserved < 0.5, $"Min probability too high: {minObserved}");
320+
Assert.IsLessThan(0.5, minObserved );
321321

322322
}
323323

Test_Numerics/Mathematics/Linear Algebra/Test_EigenValueDecomposition.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public void SymEig_3x3_RepeatedEigenvalues_AllTwos()
185185

186186
// Max eigen residual
187187
var maxRes = MaxEigenResidual(A, V, w);
188-
Assert.IsTrue(maxRes < 1e-12, $"Max eigen residual too large: {maxRes}");
188+
Assert.IsLessThan(1e-12, maxRes);
189189
}
190190

191191
/// <summary>
@@ -232,7 +232,7 @@ public void SymEig_8x8_TridiagonalToeplitz_KnownSpectrum()
232232

233233
// Max eigen residual
234234
var maxRes = MaxEigenResidual(A, V, w);
235-
Assert.IsTrue(maxRes < 1e-8, $"Max eigen residual too large: {maxRes}");
235+
Assert.IsLessThan(1e-8, maxRes);
236236
}
237237

238238
/// <summary>
@@ -268,7 +268,7 @@ public void SymEig_5x5_NearlyDiagonal_SmallCoupling()
268268

269269
// Max eigen residual
270270
var maxRes = MaxEigenResidual(A, V, w);
271-
Assert.IsTrue(maxRes < 1e-8, $"Max eigen residual too large: {maxRes}");
271+
Assert.IsLessThan(1e-8, maxRes);
272272
}
273273

274274
// ---------- Helpers ----------

Test_Numerics/Mathematics/Special Functions/Test_Gamma.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void Test_Function()
6868
for (int i = 0; i < testValid.Length; i++)
6969
{
7070
testResults[i] = Gamma.Function(testX[i]);
71-
Assert.AreEqual(Math.Abs(testValid[i] - testResults[i]) / testValid[i] < 0.01, true);
71+
Assert.IsLessThan(0.01, Math.Abs(testValid[i] - testResults[i]) / testValid[i]);
7272
}
7373
}
7474

@@ -85,7 +85,7 @@ public void Test_Lanczos()
8585
for (int i = 0; i < testValid.Length; i++)
8686
{
8787
testResults[i] = Gamma.Lanczos(testX[i]);
88-
Assert.AreEqual(Math.Abs(testValid[i] - testResults[i]) / testValid[i] < 0.01, true);
88+
Assert.IsLessThan(0.01, Math.Abs(testValid[i] - testResults[i]) / testValid[i]);
8989
}
9090
}
9191

@@ -157,7 +157,7 @@ public void Test_Trigamma()
157157
for (int i = 0; i < testValid.Length; i++)
158158
{
159159
testResults[i] = Gamma.Trigamma(testX[i]);
160-
Assert.AreEqual(Math.Abs(testValid[i] - testResults[i]) / testValid[i] < 0.01, true);
160+
Assert.IsLessThan(0.01, Math.Abs(testValid[i] - testResults[i]) / testValid[i]);
161161
}
162162
}
163163

@@ -187,7 +187,7 @@ public void Test_LogGamma()
187187
for (int i = 0; i < testValid.Length; i++)
188188
{
189189
testResults[i] = Gamma.LogGamma(testX[i]);
190-
Assert.AreEqual(Math.Abs(testValid[i] - testResults[i]) / testValid[i] < 0.01, true);
190+
Assert.IsLessThan(0.01, Math.Abs(testValid[i] - testResults[i]) / testValid[i]);
191191
}
192192
}
193193

@@ -227,7 +227,7 @@ public void Test_Incomplete()
227227
for (int i = 0; i < testValid.Length; i++)
228228
{
229229
testResults[i] = Gamma.Incomplete(testX[i], testA[i]);
230-
Assert.AreEqual(Math.Abs(testValid[i] - testResults[i]) / testValid[i] < 0.01, true);
230+
Assert.IsLessThan(0.01,Math.Abs(testValid[i] - testResults[i]) / testValid[i]);
231231
}
232232

233233
}
@@ -460,7 +460,7 @@ public void Test_InverseUpperIncomplete()
460460
double x = Gamma.UpperIncomplete(lambda, i);
461461
double j = Gamma.InverseUpperIncomplete(lambda, x);
462462

463-
Assert.IsTrue(Math.Abs(i - j) < 1e-2 * Math.Abs(j));
463+
Assert.IsLessThan(1e-2 * Math.Abs(j),Math.Abs(i - j) );
464464
}
465465
}
466466
}

Test_Numerics/Mathematics/Special Functions/Test_SpecialFunctions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ public void Test_CombinationsNum()
207207
// Total number of possible combinations
208208
double possible = Math.Pow(2, 5) - 1;
209209

210+
var ccLen = cc.Length;
210211
// Length of cc should be the possible number of combinations * the number of elements in each combination (5)
211-
Assert.AreEqual(possible * 5, cc.Length);
212+
Assert.AreEqual(possible * 5, ccLen);
212213

213214
// How many of subsets of combinations there should be
214215
// For example, there are 5 ways to have only one #1 in the array, with the other 4 elements being #0

Test_Numerics/Serialization/Test_JsonSerialization.cs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ public void Test_UncertaintyAnalysisResults_ArraySerialization()
9999

100100
// Assert
101101
Assert.IsNotNull(deserialized.ModeCurve);
102-
Assert.AreEqual(original.ModeCurve.Length, deserialized.ModeCurve.Length);
102+
Assert.HasCount(original.ModeCurve.Length, deserialized.ModeCurve);
103103
for (int i = 0; i < original.ModeCurve.Length; i++)
104104
{
105105
Assert.AreEqual(original.ModeCurve[i], deserialized.ModeCurve[i], 1e-10);
106106
}
107107

108108
Assert.IsNotNull(deserialized.MeanCurve);
109-
Assert.AreEqual(original.MeanCurve.Length, deserialized.MeanCurve.Length);
109+
Assert.HasCount(original.MeanCurve.Length, deserialized.MeanCurve);
110110
for (int i = 0; i < original.MeanCurve.Length; i++)
111111
{
112112
Assert.AreEqual(original.MeanCurve[i], deserialized.MeanCurve[i], 1e-10);
@@ -161,9 +161,11 @@ public void Test_UncertaintyAnalysisResults_ParameterSetsSerialization()
161161
byte[] serialized = UncertaintyAnalysisResults.ToByteArray(original);
162162
var deserialized = UncertaintyAnalysisResults.FromByteArray(serialized);
163163

164+
var origLen = original.ParameterSets.Length;
165+
var desLen = deserialized.ParameterSets.Length;
164166
// Assert
165167
Assert.IsNotNull(deserialized.ParameterSets);
166-
Assert.AreEqual(original.ParameterSets.Length, deserialized.ParameterSets.Length);
168+
Assert.AreEqual(origLen, desLen);
167169

168170
for (int i = 0; i < original.ParameterSets.Length; i++)
169171
{
@@ -173,7 +175,7 @@ public void Test_UncertaintyAnalysisResults_ParameterSetsSerialization()
173175
if (original.ParameterSets[i].Values != null)
174176
{
175177
Assert.IsNotNull(deserialized.ParameterSets[i].Values);
176-
Assert.AreEqual(original.ParameterSets[i].Values.Length, deserialized.ParameterSets[i].Values.Length);
178+
Assert.HasCount(original.ParameterSets[i].Values.Length, deserialized.ParameterSets[i].Values);
177179

178180
for (int j = 0; j < original.ParameterSets[i].Values.Length; j++)
179181
{
@@ -246,11 +248,11 @@ public void Test_UncertaintyAnalysisResults_EmptyArrays()
246248
// Assert
247249
Assert.IsNotNull(deserialized);
248250
Assert.IsNotNull(deserialized.ParameterSets);
249-
Assert.AreEqual(0, deserialized.ParameterSets.Length);
251+
Assert.IsEmpty( deserialized.ParameterSets);
250252
Assert.IsNotNull(deserialized.ModeCurve);
251-
Assert.AreEqual(0, deserialized.ModeCurve.Length);
253+
Assert.IsEmpty(deserialized.ModeCurve);
252254
Assert.IsNotNull(deserialized.MeanCurve);
253-
Assert.AreEqual(0, deserialized.MeanCurve.Length);
255+
Assert.IsEmpty(deserialized.MeanCurve);
254256
}
255257

256258
/// <summary>
@@ -293,10 +295,12 @@ public void Test_MCMCResults_BasicSerialization()
293295
byte[] serialized = MCMCResults.ToByteArray(original);
294296
var deserialized = MCMCResults.FromByteArray(serialized);
295297

298+
var origLen = original.AcceptanceRates.Length;
299+
var desLen = deserialized.AcceptanceRates.Length;
296300
// Assert
297301
Assert.IsNotNull(deserialized);
298302
Assert.IsNotNull(deserialized.AcceptanceRates);
299-
Assert.AreEqual(original.AcceptanceRates.Length, deserialized.AcceptanceRates.Length);
303+
Assert.AreEqual(origLen, desLen);
300304

301305
for (int i = 0; i < original.AcceptanceRates.Length; i++)
302306
{
@@ -323,14 +327,16 @@ public void Test_MCMCResults_MarkovChainsSerialization()
323327
byte[] serialized = MCMCResults.ToByteArray(original);
324328
var deserialized = MCMCResults.FromByteArray(serialized);
325329

330+
var origLen = original.MarkovChains.Length;
331+
var desLen = deserialized.MarkovChains.Length;
326332
// Assert
327333
Assert.IsNotNull(deserialized.MarkovChains);
328-
Assert.AreEqual(original.MarkovChains.Length, deserialized.MarkovChains.Length);
334+
Assert.AreEqual(origLen, desLen);
329335

330336
for (int i = 0; i < original.MarkovChains.Length; i++)
331337
{
332338
Assert.IsNotNull(deserialized.MarkovChains[i]);
333-
Assert.AreEqual(original.MarkovChains[i].Count, deserialized.MarkovChains[i].Count);
339+
Assert.HasCount(original.MarkovChains[i].Count, deserialized.MarkovChains[i]);
334340

335341
for (int j = 0; j < original.MarkovChains[i].Count; j++)
336342
{
@@ -368,7 +374,7 @@ public void Test_MCMCResults_OutputSerialization()
368374

369375
// Assert
370376
Assert.IsNotNull(deserialized.Output);
371-
Assert.AreEqual(original.Output.Count, deserialized.Output.Count);
377+
Assert.HasCount(original.Output.Count, deserialized.Output);
372378

373379
for (int i = 0; i < original.Output.Count; i++)
374380
{
@@ -423,7 +429,7 @@ public void Test_MCMCResults_MeanLogLikelihoodSerialization()
423429

424430
// Assert
425431
Assert.IsNotNull(deserialized.MeanLogLikelihood);
426-
Assert.AreEqual(original.MeanLogLikelihood.Count, deserialized.MeanLogLikelihood.Count);
432+
Assert.HasCount(original.MeanLogLikelihood.Count, deserialized.MeanLogLikelihood);
427433

428434
for (int i = 0; i < original.MeanLogLikelihood.Count; i++)
429435
{
@@ -461,9 +467,9 @@ public void Test_MCMCResults_EmptyChains()
461467
// Assert
462468
Assert.IsNotNull(deserialized);
463469
Assert.IsNotNull(deserialized.MarkovChains);
464-
Assert.AreEqual(2, deserialized.MarkovChains.Length);
465-
Assert.AreEqual(0, deserialized.MarkovChains[0].Count);
466-
Assert.AreEqual(0, deserialized.MarkovChains[1].Count);
470+
Assert.HasCount(2, deserialized.MarkovChains);
471+
Assert.HasCount(0, deserialized.MarkovChains[0]);
472+
Assert.HasCount(0, deserialized.MarkovChains[1]);
467473
}
468474

469475
/// <summary>
@@ -486,9 +492,11 @@ public void Test_MCMCResults_LargeDataSet()
486492
byte[] serialized = MCMCResults.ToByteArray(original);
487493
var deserialized = MCMCResults.FromByteArray(serialized);
488494

495+
var origLen = original.MarkovChains.Length;
496+
var deserializedLen = deserialized.MarkovChains.Length;
489497
// Assert
490498
Assert.IsNotNull(deserialized);
491-
Assert.AreEqual(original.MarkovChains.Length, deserialized.MarkovChains.Length);
499+
Assert.AreEqual(origLen, deserializedLen);
492500

493501
// Verify first and last elements to ensure proper serialization
494502
var firstOriginal = original.MarkovChains[0][0];
@@ -531,15 +539,15 @@ public void Test_JsonSerializerOptions_Configuration()
531539

532540
// Assert
533541
// Verify that WriteIndented is false (no formatting whitespace)
534-
Assert.IsFalse(jsonString.Contains("\n"));
535-
Assert.IsFalse(jsonString.Contains(" ")); // No indentation
542+
Assert.DoesNotContain(jsonString,("\n"));
543+
Assert.DoesNotContain(jsonString, (" ")); // No indentation
536544

537545
// Verify that null values are not included (DefaultIgnoreCondition)
538-
Assert.IsFalse(jsonString.Contains("\"ParentDistribution\":null"));
546+
Assert.DoesNotContain(jsonString, ("\"ParentDistribution\":null"));
539547

540548
// Verify that fields are included (IncludeFields = true)
541-
Assert.IsTrue(jsonString.Contains("\"AIC\":"));
542-
Assert.IsTrue(jsonString.Contains("\"BIC\":"));
549+
Assert.DoesNotContain(jsonString, ("\"AIC\":"));
550+
Assert.DoesNotContain(jsonString, ("\"BIC\":"));
543551
}
544552

545553
#endregion

Test_Numerics/Utilities/Test_ExtensionMethods.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void Test_NextIntegers()
8484
{
8585
var random = new Random();
8686
var result = random.NextIntegers(5);
87-
Assert.AreEqual(5, result.Length);
87+
Assert.HasCount(5, result);
8888
}
8989

9090
/// <summary>
@@ -95,7 +95,7 @@ public void Test_NextIntegersMinMax()
9595
{
9696
var random = new Random();
9797
var result = random.NextIntegers(0, 10, 5);
98-
Assert.AreEqual(5, result.Length);
98+
Assert.HasCount(5, result);
9999
for (int i = 0; i < result.Length; i++)
100100
Assert.IsTrue(result[i] >= 0 && result[i] < 10);
101101
}
@@ -134,7 +134,7 @@ public void Test_NextDoubles()
134134
{
135135
var random = new Random();
136136
var result = random.NextDoubles(5);
137-
Assert.AreEqual(5, result.Length);
137+
Assert.HasCount(5, result);
138138
for (int i = 0; i < result.Length; i++)
139139
Assert.IsTrue(result[i] >= 0 && result[i] < 1);
140140
}
@@ -275,7 +275,7 @@ public void Test_Random_Subset()
275275
var array = new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
276276
var result = array.RandomSubset(5);
277277
CollectionAssert.IsSubsetOf(result, array);
278-
Assert.AreEqual(5, result.Length);
278+
Assert.HasCount(5, result);
279279
}
280280

281281
/// <summary>
@@ -420,7 +420,7 @@ public void Test_Vector_Random_Subset()
420420
var vector = new Vector(new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
421421
var result = vector.RandomSubset(5).Array;
422422
CollectionAssert.IsSubsetOf(result, vector.Array);
423-
Assert.AreEqual(5, result.Length);
423+
Assert.HasCount(5, result);
424424
}
425425

426426
/// <summary>

0 commit comments

Comments
 (0)