Skip to content

Commit d876f47

Browse files
committed
Cover negative doubles in the FbDecFloat round-trip property test
Random.NextInt64() never returns a negative value, so the random doubles were all positive. Use the full long range and assert both signs are covered.
1 parent 1bb32cc commit d876f47

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎src/FirebirdSql.Data.FirebirdClient.Tests/FbDecFloatTypeTests.cs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,20 +162,27 @@ public void ConvertsSpecialValues()
162162
public void DoubleAndSingleConversionsRoundTrip()
163163
{
164164
var random = new Random(20261107);
165+
var negativeDoubles = 0;
166+
var negativeSingles = 0;
165167
for (var i = 0; i < 10_000; i++)
166168
{
167-
var d = BitConverter.Int64BitsToDouble(random.NextInt64());
169+
// random bit patterns, so all exponents and both signs are covered
170+
var d = BitConverter.Int64BitsToDouble(random.NextInt64(long.MinValue, long.MaxValue));
168171
if (double.IsFinite(d))
169172
{
170173
var result = (FbDecFloat)d;
171174
Assert.AreEqual(d, double.Parse(result.ToString(), CultureInfo.InvariantCulture), $"{d:R} -> {result}");
175+
negativeDoubles += d < 0 ? 1 : 0;
172176
}
173177
var f = BitConverter.Int32BitsToSingle(random.Next(int.MinValue, int.MaxValue));
174178
if (float.IsFinite(f))
175179
{
176180
var result = (FbDecFloat)f;
177181
Assert.AreEqual(f, float.Parse(result.ToString(), CultureInfo.InvariantCulture), $"{f:R} -> {result}");
182+
negativeSingles += f < 0 ? 1 : 0;
178183
}
179184
}
185+
Assert.Greater(negativeDoubles, 1000);
186+
Assert.Greater(negativeSingles, 1000);
180187
}
181188
}

0 commit comments

Comments
 (0)