[CodeFactor] Apply fixes to commit 0606491

This commit is contained in:
codefactor-io
2026-03-12 19:37:50 +00:00
parent 060649192f
commit 8f79257155
384 changed files with 1197 additions and 1215 deletions
+7 -7
View File
@@ -39,10 +39,10 @@ public class HuberTests
for (int i = 0; i < period - 1; i++)
{
Assert.False(huber.IsHot, $"IsHot should be false at index {i}");
huber.Update(i * 10, i * 10 + 5);
huber.Update(i * 10, (i * 10) + 5);
}
huber.Update((period - 1) * 10, (period - 1) * 10 + 5);
huber.Update((period - 1) * 10, ((period - 1) * 10) + 5);
Assert.True(huber.IsHot, "IsHot should be true after period updates");
}
@@ -70,7 +70,7 @@ public class HuberTests
// Error = 10 (large), Huber = delta * |error| - 0.5 * delta^2 = 1 * 10 - 0.5 = 9.5
var res1 = huber.Update(110, 100);
Assert.Equal(delta * 10 - halfDeltaSquared, res1.Value, 10);
Assert.Equal((delta * 10) - halfDeltaSquared, res1.Value, 10);
}
[Fact]
@@ -89,7 +89,7 @@ public class HuberTests
var aboveDelta = huber2.Update(105.1, 100);
// Should be very close to quadratic at transition
// delta * 5.1 - 0.5 * delta^2 = 5 * 5.1 - 12.5 = 25.5 - 12.5 = 13
double expected = delta * 5.1 - 0.5 * delta * delta;
double expected = (delta * 5.1) - (0.5 * delta * delta);
Assert.Equal(expected, aboveDelta.Value, 5);
}
@@ -163,7 +163,7 @@ public class HuberTests
for (int i = 0; i < 10; i++)
{
tenthActual = i * 10;
tenthPredicted = i * 10 + 5;
tenthPredicted = (i * 10) + 5;
huber.Update(tenthActual, tenthPredicted);
}
@@ -188,7 +188,7 @@ public class HuberTests
for (int i = 0; i < 10; i++)
{
huber.Update(i * 10, i * 10 + 5);
huber.Update(i * 10, (i * 10) + 5);
}
Assert.True(huber.IsHot);
@@ -267,7 +267,7 @@ public class HuberTests
{
var bar = gbm.Next();
actual[i] = bar.Close;
predicted[i] = bar.Close * 1.05 + 2; // Offset prediction
predicted[i] = (bar.Close * 1.05) + 2; // Offset prediction
}
// Streaming
+1 -1
View File
@@ -398,7 +398,7 @@ public class LogCoshTests
for (int i = 0; i < 100; i++)
{
var bar = gbm.Next(isNew: true);
logCosh.Update(bar.Close, bar.Close * (1 + (i % 3 - 1) * 0.1));
logCosh.Update(bar.Close, bar.Close * (1 + (((i % 3) - 1) * 0.1)));
Assert.True(logCosh.Last.Value >= 0, $"LogCosh should be non-negative, got {logCosh.Last.Value}");
}
}
+6 -6
View File
@@ -34,10 +34,10 @@ public class MaeTests
for (int i = 0; i < period - 1; i++)
{
Assert.False(mae.IsHot, $"IsHot should be false at index {i}");
mae.Update(i * 10, i * 10 + 5);
mae.Update(i * 10, (i * 10) + 5);
}
mae.Update((period - 1) * 10, (period - 1) * 10 + 5);
mae.Update((period - 1) * 10, ((period - 1) * 10) + 5);
Assert.True(mae.IsHot, "IsHot should be true after period updates");
}
@@ -146,7 +146,7 @@ public class MaeTests
for (int i = 0; i < 10; i++)
{
tenthActual = i * 10;
tenthPredicted = i * 10 + 5;
tenthPredicted = (i * 10) + 5;
mae.Update(tenthActual, tenthPredicted);
}
@@ -171,7 +171,7 @@ public class MaeTests
for (int i = 0; i < 10; i++)
{
mae.Update(i * 10, i * 10 + 5);
mae.Update(i * 10, (i * 10) + 5);
}
Assert.True(mae.IsHot);
@@ -249,7 +249,7 @@ public class MaeTests
{
var bar = gbm.Next();
actual[i] = bar.Close;
predicted[i] = bar.Close * 1.05 + 2; // Offset prediction
predicted[i] = (bar.Close * 1.05) + 2; // Offset prediction
}
// Streaming
@@ -305,7 +305,7 @@ public class MaeTests
for (int i = 0; i < 10; i++)
{
actual.Add(now.AddMinutes(i), i * 10);
predicted.Add(now.AddMinutes(i), i * 10 + 5);
predicted.Add(now.AddMinutes(i), (i * 10) + 5);
}
var results = Mae.Batch(actual, predicted, 3);
+4 -4
View File
@@ -56,7 +56,7 @@ public class MapdTests
// |50 - 60| / 60 * 100 = 16.666...%
var res3 = mapd.Update(50, 60);
double expected = (100.0 * 10 / 110 + 100.0 * 20 / 220 + 100.0 * 10 / 60) / 3;
double expected = ((100.0 * 10 / 110) + (100.0 * 20 / 220) + (100.0 * 10 / 60)) / 3;
Assert.Equal(expected, res3.Value, 10);
}
@@ -130,7 +130,7 @@ public class MapdTests
for (int i = 1; i <= 10; i++)
{
tenthActual = i * 10;
tenthPredicted = i * 10 + 5;
tenthPredicted = (i * 10) + 5;
mapd.Update(tenthActual, tenthPredicted);
}
@@ -155,7 +155,7 @@ public class MapdTests
for (int i = 1; i <= 10; i++)
{
mapd.Update(i * 10, i * 10 + 5);
mapd.Update(i * 10, (i * 10) + 5);
}
Assert.True(mapd.IsHot);
@@ -233,7 +233,7 @@ public class MapdTests
{
var bar = gbm.Next();
actual[i] = bar.Close;
predicted[i] = bar.Close * 1.05 + 2; // Offset prediction
predicted[i] = (bar.Close * 1.05) + 2; // Offset prediction
}
// Streaming
+3 -3
View File
@@ -146,7 +146,7 @@ public class MapeTests
for (int i = 1; i <= 10; i++)
{
tenthActual = i * 10;
tenthPredicted = i * 10 + 5;
tenthPredicted = (i * 10) + 5;
mape.Update(tenthActual, tenthPredicted);
}
@@ -171,7 +171,7 @@ public class MapeTests
for (int i = 1; i <= 10; i++)
{
mape.Update(i * 10, i * 10 + 5);
mape.Update(i * 10, (i * 10) + 5);
}
Assert.True(mape.IsHot);
@@ -249,7 +249,7 @@ public class MapeTests
{
var bar = gbm.Next();
actual[i] = bar.Close;
predicted[i] = bar.Close * 1.05 + 2; // Offset prediction
predicted[i] = (bar.Close * 1.05) + 2; // Offset prediction
}
// Streaming
+1 -1
View File
@@ -198,7 +198,7 @@ public class MaseTests
// Generate data where prediction is always perfect
for (int i = 0; i < 20; i++)
{
double actual = 100 + i * 2;
double actual = 100 + (i * 2);
double perfect = actual; // Perfect prediction
mase.Update(new TValue(time.AddSeconds(i), actual), new TValue(time.AddSeconds(i), perfect));
}
+6 -6
View File
@@ -34,10 +34,10 @@ public class MeTests
for (int i = 0; i < period - 1; i++)
{
Assert.False(me.IsHot, $"IsHot should be false at index {i}");
me.Update(i * 10, i * 10 + 5);
me.Update(i * 10, (i * 10) + 5);
}
me.Update((period - 1) * 10, (period - 1) * 10 + 5);
me.Update((period - 1) * 10, ((period - 1) * 10) + 5);
Assert.True(me.IsHot, "IsHot should be true after period updates");
}
@@ -172,7 +172,7 @@ public class MeTests
for (int i = 0; i < 10; i++)
{
tenthActual = i * 10;
tenthPredicted = i * 10 + 5;
tenthPredicted = (i * 10) + 5;
me.Update(tenthActual, tenthPredicted);
}
@@ -197,7 +197,7 @@ public class MeTests
for (int i = 0; i < 10; i++)
{
me.Update(i * 10, i * 10 + 5);
me.Update(i * 10, (i * 10) + 5);
}
Assert.True(me.IsHot);
@@ -275,7 +275,7 @@ public class MeTests
{
var bar = gbm.Next();
actual[i] = bar.Close;
predicted[i] = bar.Close * 1.05 + 2; // Offset prediction
predicted[i] = (bar.Close * 1.05) + 2; // Offset prediction
}
// Streaming
@@ -331,7 +331,7 @@ public class MeTests
for (int i = 0; i < 10; i++)
{
actual.Add(now.AddMinutes(i), i * 10);
predicted.Add(now.AddMinutes(i), i * 10 + 5);
predicted.Add(now.AddMinutes(i), (i * 10) + 5);
}
var results = Me.Batch(actual, predicted, 3);
+5 -5
View File
@@ -34,10 +34,10 @@ public class MraeTests
for (int i = 1; i <= period - 1; i++)
{
Assert.False(mrae.IsHot, $"IsHot should be false at index {i}");
mrae.Update(i * 10, i * 10 + 5);
mrae.Update(i * 10, (i * 10) + 5);
}
mrae.Update(period * 10, period * 10 + 5);
mrae.Update(period * 10, (period * 10) + 5);
Assert.True(mrae.IsHot, "IsHot should be true after period updates");
}
@@ -127,7 +127,7 @@ public class MraeTests
for (int i = 1; i <= 10; i++)
{
tenthActual = i * 100;
tenthPredicted = i * 100 + 10;
tenthPredicted = (i * 100) + 10;
mrae.Update(tenthActual, tenthPredicted);
}
@@ -152,7 +152,7 @@ public class MraeTests
for (int i = 1; i <= 10; i++)
{
mrae.Update(i * 10, i * 10 + 5);
mrae.Update(i * 10, (i * 10) + 5);
}
Assert.True(mrae.IsHot);
@@ -230,7 +230,7 @@ public class MraeTests
{
var bar = gbm.Next();
actual[i] = bar.Close;
predicted[i] = bar.Close * 1.05 + 2;
predicted[i] = (bar.Close * 1.05) + 2;
}
// Streaming
+6 -6
View File
@@ -34,10 +34,10 @@ public class MseTests
for (int i = 0; i < period - 1; i++)
{
Assert.False(mse.IsHot, $"IsHot should be false at index {i}");
mse.Update(i * 10, i * 10 + 5);
mse.Update(i * 10, (i * 10) + 5);
}
mse.Update((period - 1) * 10, (period - 1) * 10 + 5);
mse.Update((period - 1) * 10, ((period - 1) * 10) + 5);
Assert.True(mse.IsHot, "IsHot should be true after period updates");
}
@@ -152,7 +152,7 @@ public class MseTests
for (int i = 0; i < 10; i++)
{
tenthActual = i * 10;
tenthPredicted = i * 10 + 5;
tenthPredicted = (i * 10) + 5;
mse.Update(tenthActual, tenthPredicted);
}
@@ -177,7 +177,7 @@ public class MseTests
for (int i = 0; i < 10; i++)
{
mse.Update(i * 10, i * 10 + 5);
mse.Update(i * 10, (i * 10) + 5);
}
Assert.True(mse.IsHot);
@@ -237,7 +237,7 @@ public class MseTests
{
var bar = gbm.Next();
actual[i] = bar.Close;
predicted[i] = bar.Close * 1.05 + 2;
predicted[i] = (bar.Close * 1.05) + 2;
}
// Streaming
@@ -284,7 +284,7 @@ public class MseTests
for (int i = 0; i < 10; i++)
{
actual.Add(now.AddMinutes(i), i * 10);
predicted.Add(now.AddMinutes(i), i * 10 + 5);
predicted.Add(now.AddMinutes(i), (i * 10) + 5);
}
var results = Mse.Batch(actual, predicted, 3);
@@ -204,7 +204,7 @@ public class PseudoHuberTests
for (int i = 0; i < 100; i++)
{
var bar = gbm.Next();
pseudoHuber.Update(bar.Close, bar.Close + (i % 2 == 0 ? 1 : -1) * (i + 1));
pseudoHuber.Update(bar.Close, bar.Close + ((i % 2 == 0 ? 1 : -1) * (i + 1)));
Assert.True(pseudoHuber.Last.Value >= 0, "Pseudo-Huber loss should always be non-negative");
}
}
@@ -381,7 +381,7 @@ public class QuantileLossTests
for (int i = 0; i < 100; i++)
{
var bar = gbm.Next(isNew: true);
quantileLoss.Update(bar.Close, bar.Close * (1 + (i % 3 - 1) * 0.1));
quantileLoss.Update(bar.Close, bar.Close * (1 + (((i % 3) - 1) * 0.1)));
Assert.True(quantileLoss.Last.Value >= 0, $"QuantileLoss should be non-negative, got {quantileLoss.Last.Value}");
}
}
+1 -1
View File
@@ -148,7 +148,7 @@ public class RaeTests
// Different actual values but perfect predictions
for (int i = 0; i < 20; i++)
{
double val = 100 + i * 2;
double val = 100 + (i * 2);
rae.Update(new TValue(time.AddSeconds(i), val), new TValue(time.AddSeconds(i), val));
}
+8 -8
View File
@@ -34,10 +34,10 @@ public class RmseTests
for (int i = 0; i < period - 1; i++)
{
Assert.False(rmse.IsHot);
rmse.Update(i * 10, i * 10 + 5);
rmse.Update(i * 10, (i * 10) + 5);
}
rmse.Update((period - 1) * 10, (period - 1) * 10 + 5);
rmse.Update((period - 1) * 10, ((period - 1) * 10) + 5);
Assert.True(rmse.IsHot);
}
@@ -67,8 +67,8 @@ public class RmseTests
for (int i = 0; i < 20; i++)
{
rmse.Update(i * 10, i * 10 + 7);
mse.Update(i * 10, i * 10 + 7);
rmse.Update(i * 10, (i * 10) + 7);
mse.Update(i * 10, (i * 10) + 7);
}
Assert.Equal(Math.Sqrt(mse.Last.Value), rmse.Last.Value, 10);
@@ -127,7 +127,7 @@ public class RmseTests
for (int i = 0; i < 10; i++)
{
tenthActual = i * 10;
tenthPredicted = i * 10 + 5;
tenthPredicted = (i * 10) + 5;
rmse.Update(tenthActual, tenthPredicted);
}
@@ -150,7 +150,7 @@ public class RmseTests
for (int i = 0; i < 10; i++)
{
rmse.Update(i * 10, i * 10 + 5);
rmse.Update(i * 10, (i * 10) + 5);
}
Assert.True(rmse.IsHot);
@@ -196,7 +196,7 @@ public class RmseTests
{
var bar = gbm.Next();
actual[i] = bar.Close;
predicted[i] = bar.Close * 1.05 + 2;
predicted[i] = (bar.Close * 1.05) + 2;
}
var rmse = new Rmse(period);
@@ -238,7 +238,7 @@ public class RmseTests
for (int i = 0; i < 10; i++)
{
actual.Add(now.AddMinutes(i), i * 10);
predicted.Add(now.AddMinutes(i), i * 10 + 5);
predicted.Add(now.AddMinutes(i), (i * 10) + 5);
}
var results = Rmse.Batch(actual, predicted, 3);
+1 -1
View File
@@ -362,7 +362,7 @@ public class RmsleTests
for (int i = 0; i < 100; i++)
{
var bar = gbm.Next(isNew: true);
var result = rmsle.Update(bar.Close, bar.Close * (0.8 + 0.4 * (i % 2)));
var result = rmsle.Update(bar.Close, bar.Close * (0.8 + (0.4 * (i % 2))));
Assert.True(result.Value >= 0, $"RMSLE should always be non-negative, got {result.Value}");
}
}
+3 -3
View File
@@ -148,7 +148,7 @@ public class RseTests
// Different actual values but perfect predictions
for (int i = 0; i < 20; i++)
{
double val = 100 + i * 2;
double val = 100 + (i * 2);
rse.Update(new TValue(time.AddSeconds(i), val), new TValue(time.AddSeconds(i), val));
}
@@ -165,8 +165,8 @@ public class RseTests
// Generate data with some error
for (int i = 0; i < 20; i++)
{
double actual = 100 + i * 2;
double predicted = actual + (i % 3 - 1) * 2; // Small systematic error
double actual = 100 + (i * 2);
double predicted = actual + (((i % 3) - 1) * 2); // Small systematic error
rse.Update(new TValue(time.AddSeconds(i), actual), new TValue(time.AddSeconds(i), predicted));
}
+6 -6
View File
@@ -147,7 +147,7 @@ public class RsquaredTests
// Different actual values but perfect predictions
for (int i = 0; i < 20; i++)
{
double val = 100 + i * 2;
double val = 100 + (i * 2);
r2.Update(new TValue(time.AddSeconds(i), val), new TValue(time.AddSeconds(i), val));
}
@@ -165,8 +165,8 @@ public class RsquaredTests
// Generate data with some error
for (int i = 0; i < 20; i++)
{
double actual = 100 + i * 2;
double predicted = actual + (i % 3 - 1) * 2;
double actual = 100 + (i * 2);
double predicted = actual + (((i % 3) - 1) * 2);
r2.Update(new TValue(time.AddSeconds(i), actual), new TValue(time.AddSeconds(i), predicted));
rse.Update(new TValue(time.AddSeconds(i), actual), new TValue(time.AddSeconds(i), predicted));
}
@@ -210,7 +210,7 @@ public class RsquaredTests
// Linear trend with small random noise in predictions
for (int i = 0; i < 20; i++)
{
double actual = 100 + i * 2;
double actual = 100 + (i * 2);
double predicted = actual + (i % 2 == 0 ? 0.5 : -0.5); // Small systematic error
r2.Update(new TValue(time.AddSeconds(i), actual), new TValue(time.AddSeconds(i), predicted));
}
@@ -261,8 +261,8 @@ public class RsquaredTests
for (int i = 0; i < 100; i++)
{
double actual = 100 + Math.Sin(i * 0.1) * 20;
double predicted = actual + (i % 5 - 2); // Small systematic error
double actual = 100 + (Math.Sin(i * 0.1) * 20);
double predicted = actual + ((i % 5) - 2); // Small systematic error
r2.Update(new TValue(time.AddSeconds(i), actual), new TValue(time.AddSeconds(i), predicted));
// R² should never exceed 1
@@ -361,7 +361,7 @@ public class TukeyBiweightTests
for (int i = 0; i < 100; i++)
{
var bar = gbm.Next(isNew: true);
tukey.Update(bar.Close, bar.Close * (1 + (i % 3 - 1) * 0.2));
tukey.Update(bar.Close, bar.Close * (1 + (((i % 3) - 1) * 0.2)));
Assert.True(tukey.Last.Value >= 0, $"Loss should be non-negative, got {tukey.Last.Value}");
Assert.True(tukey.Last.Value <= maxLoss, $"Loss should be <= {maxLoss}, got {tukey.Last.Value}");
}
+11 -11
View File
@@ -34,10 +34,10 @@ public class WrmseTests
for (int i = 0; i < period - 1; i++)
{
Assert.False(wrmse.IsHot);
wrmse.Update(i * 10, i * 10 + 5);
wrmse.Update(i * 10, (i * 10) + 5);
}
wrmse.Update((period - 1) * 10, (period - 1) * 10 + 5);
wrmse.Update((period - 1) * 10, ((period - 1) * 10) + 5);
Assert.True(wrmse.IsHot);
}
@@ -49,8 +49,8 @@ public class WrmseTests
for (int i = 0; i < 20; i++)
{
wrmse.Update(i * 10, i * 10 + 7);
rmse.Update(i * 10, i * 10 + 7);
wrmse.Update(i * 10, (i * 10) + 7);
rmse.Update(i * 10, (i * 10) + 7);
}
// With default weight of 1.0, WRMSE should equal RMSE
@@ -154,7 +154,7 @@ public class WrmseTests
for (int i = 0; i < 10; i++)
{
tenthActual = i * 10;
tenthPredicted = i * 10 + 5;
tenthPredicted = (i * 10) + 5;
tenthWeight = i + 1.0;
wrmse.Update(tenthActual, tenthPredicted, tenthWeight);
}
@@ -178,7 +178,7 @@ public class WrmseTests
for (int i = 0; i < 10; i++)
{
wrmse.Update(i * 10, i * 10 + 5, i + 1.0);
wrmse.Update(i * 10, (i * 10) + 5, i + 1.0);
}
Assert.True(wrmse.IsHot);
@@ -238,7 +238,7 @@ public class WrmseTests
{
var bar = gbm.Next();
actual[i] = bar.Close;
predicted[i] = bar.Close * 1.05 + 2;
predicted[i] = (bar.Close * 1.05) + 2;
}
var wrmse = new Wrmse(period);
@@ -271,7 +271,7 @@ public class WrmseTests
{
var bar = gbm.Next();
actual[i] = bar.Close;
predicted[i] = bar.Close * 1.05 + 2;
predicted[i] = (bar.Close * 1.05) + 2;
weights[i] = (i % 5) + 1.0; // Varying weights 1-5
}
@@ -317,7 +317,7 @@ public class WrmseTests
for (int i = 0; i < 10; i++)
{
actual.Add(now.AddMinutes(i), i * 10);
predicted.Add(now.AddMinutes(i), i * 10 + 5);
predicted.Add(now.AddMinutes(i), (i * 10) + 5);
}
var results = Wrmse.Batch(actual, predicted, 3);
@@ -362,7 +362,7 @@ public class WrmseTests
actual.Add(now.AddMinutes(i), i * 10);
if (i < 5)
{
predicted.Add(now.AddMinutes(i), i * 10 + 5);
predicted.Add(now.AddMinutes(i), (i * 10) + 5);
}
}
@@ -380,7 +380,7 @@ public class WrmseTests
for (int i = 0; i < 10; i++)
{
actual.Add(now.AddMinutes(i), i * 10);
predicted.Add(now.AddMinutes(i), i * 10 + 5);
predicted.Add(now.AddMinutes(i), (i * 10) + 5);
if (i < 5)
{
weights.Add(now.AddMinutes(i), 1.0);