Skip to content

Commit b9da673

Browse files
committed
NaN rules
1 parent ac65b9f commit b9da673

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

tests/StackExchange.Redis.Tests/KeyAndValueTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ public void TestValues()
6464

6565
internal static void CheckSame(RedisValue x, RedisValue y)
6666
{
67+
if (x.TryParse(out double value) && double.IsNaN(value))
68+
{
69+
// NaN has atypical equality rules
70+
Assert.True(y.TryParse(out value) && double.IsNaN(value));
71+
return;
72+
}
6773
Assert.True(Equals(x, y), "Equals(x, y)");
6874
Assert.True(Equals(y, x), "Equals(y, x)");
6975
Assert.True(EqualityComparer<RedisValue>.Default.Equals(x, y), "EQ(x,y)");

tests/StackExchange.Redis.Tests/RedisValueEquivalencyTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,24 @@ static void Check(RedisValue known, RedisValue test)
137137

138138
Check(double.NegativeInfinity, double.NegativeInfinity);
139139
Check(double.NegativeInfinity, "-inf");
140+
Check(double.NegativeInfinity, Bytes("-inf"));
140141
CheckString(double.NegativeInfinity, "-inf");
141142

142143
Check(double.PositiveInfinity, double.PositiveInfinity);
143144
Check(double.PositiveInfinity, "+inf");
145+
Check(double.PositiveInfinity, "inf");
146+
Check(double.PositiveInfinity, Bytes("+inf"));
147+
Check(double.PositiveInfinity, Bytes("inf"));
144148
CheckString(double.PositiveInfinity, "+inf");
149+
150+
Check(double.NaN, double.NaN);
151+
Check(double.NaN, "+nan");
152+
Check(double.NaN, "-nan");
153+
Check(double.NaN, "nan");
154+
Check(double.NaN, Bytes("+nan"));
155+
Check(double.NaN, Bytes("-nan"));
156+
Check(double.NaN, Bytes("nan"));
157+
CheckString(double.NaN, "NaN");
145158
}
146159

147160
private static void CheckString(RedisValue value, string expected)

0 commit comments

Comments
 (0)