From ba0d4d6e110da6f23b705167d45ade7cf4071104 Mon Sep 17 00:00:00 2001 From: amylizzle Date: Fri, 2 Feb 2024 17:02:13 +0000 Subject: [PATCH 1/3] also test --- Content.Tests/DMProject/Tests/Math/minmax.dm | 16 ++++++++++++++++ .../Procs/Native/DreamProcNativeRoot.cs | 15 ++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 Content.Tests/DMProject/Tests/Math/minmax.dm diff --git a/Content.Tests/DMProject/Tests/Math/minmax.dm b/Content.Tests/DMProject/Tests/Math/minmax.dm new file mode 100644 index 0000000000..ee7678648b --- /dev/null +++ b/Content.Tests/DMProject/Tests/Math/minmax.dm @@ -0,0 +1,16 @@ +/proc/RunTest() + ASSERT(min(1,2,3) == 1) + ASSERT(min(null, 1) == null) + ASSERT(min(null, -1) == -1) + ASSERT(min(1, null) == null) + ASSERT(min(0,null)==null) + ASSERT(min("a","b","c")=="a") + ASSERT(min("b","a","c")=="a") + + ASSERT(max(1,2,3) == 3) + ASSERT(max(null, 1) == 1) + ASSERT(max(null, -1) == null) + ASSERT(max(1, null) == 1) + ASSERT(max(0,null)==null) + ASSERT(max("a","b","c")=="c") + ASSERT(max("b","a","c")=="c") \ No newline at end of file diff --git a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs index 17c3fe2e53..7fc0b1a68d 100644 --- a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs +++ b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs @@ -1473,14 +1473,19 @@ public static DreamValue NativeProc_md5(NativeProc.Bundle bundle, DreamObject? s } private static DreamValue MinComparison(DreamValue min, DreamValue value) { - if (value.TryGetValueAsFloat(out var lFloat) && min.TryGetValueAsFloat(out var rFloat)) { - if (lFloat < rFloat) + if (value.TryGetValueAsFloat(out var lFloat)) { + if (min.IsNull && lFloat < 0) min = value; - } else if (value.TryGetValueAsString(out var lString) && min.TryGetValueAsString(out var rString)) { - if (string.Compare(lString, rString, StringComparison.Ordinal) < 0) + else if (min.TryGetValueAsFloat(out var rFloat) && lFloat <= rFloat) min = value; } else if (value.IsNull) { - min = value; + if (min.TryGetValueAsFloat(out var minFloat) && minFloat >= 0) + min = value; + } else if (value.TryGetValueAsString(out var lString)) { + if (min.IsNull) + min = value; + else if (min.TryGetValueAsString(out var rString) && string.Compare(lString, rString, StringComparison.Ordinal) <= 0) + min = value; } else { throw new Exception($"Cannot compare {min} and {value}"); } From 067118783949aa560d459b1eafab2d6bfc905666 Mon Sep 17 00:00:00 2001 From: Amy <3855802+amylizzle@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:03:33 +0000 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: wixoa --- Content.Tests/DMProject/Tests/Math/minmax.dm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Content.Tests/DMProject/Tests/Math/minmax.dm b/Content.Tests/DMProject/Tests/Math/minmax.dm index ee7678648b..1c0adad627 100644 --- a/Content.Tests/DMProject/Tests/Math/minmax.dm +++ b/Content.Tests/DMProject/Tests/Math/minmax.dm @@ -3,7 +3,8 @@ ASSERT(min(null, 1) == null) ASSERT(min(null, -1) == -1) ASSERT(min(1, null) == null) - ASSERT(min(0,null)==null) + ASSERT(min(0, null) == null) + ASSERT(min(null, 0) == 0) ASSERT(min("a","b","c")=="a") ASSERT(min("b","a","c")=="a") @@ -11,6 +12,7 @@ ASSERT(max(null, 1) == 1) ASSERT(max(null, -1) == null) ASSERT(max(1, null) == 1) - ASSERT(max(0,null)==null) + ASSERT(max(0, null) == null) + ASSERT(max(null, 0) == 0) ASSERT(max("a","b","c")=="c") ASSERT(max("b","a","c")=="c") \ No newline at end of file From 7262e2fd16a13b7681df1eefa8b7b26d5491d526 Mon Sep 17 00:00:00 2001 From: amylizzle Date: Fri, 16 Feb 2024 17:44:54 +0000 Subject: [PATCH 3/3] one char fix lul --- Content.Tests/DMProject/Tests/Math/minmax.dm | 36 ++++++++++--------- .../Procs/Native/DreamProcNativeRoot.cs | 2 +- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Content.Tests/DMProject/Tests/Math/minmax.dm b/Content.Tests/DMProject/Tests/Math/minmax.dm index 1c0adad627..af8c3b23ea 100644 --- a/Content.Tests/DMProject/Tests/Math/minmax.dm +++ b/Content.Tests/DMProject/Tests/Math/minmax.dm @@ -1,18 +1,22 @@ /proc/RunTest() - ASSERT(min(1,2,3) == 1) - ASSERT(min(null, 1) == null) - ASSERT(min(null, -1) == -1) - ASSERT(min(1, null) == null) - ASSERT(min(0, null) == null) - ASSERT(min(null, 0) == 0) - ASSERT(min("a","b","c")=="a") - ASSERT(min("b","a","c")=="a") + ASSERT(min(1,2,3) == 1) + ASSERT(min(null, 1) == null) + ASSERT(min(null, -1) == -1) + ASSERT(min(1, null) == null) + ASSERT(min(-1, null) == -1) + ASSERT(min(1, null) == null) + ASSERT(min(0, null) == null) + ASSERT(min(null, 0) == 0) + ASSERT(min("a","b","c")=="a") + ASSERT(min("b","a","c")=="a") - ASSERT(max(1,2,3) == 3) - ASSERT(max(null, 1) == 1) - ASSERT(max(null, -1) == null) - ASSERT(max(1, null) == 1) - ASSERT(max(0, null) == null) - ASSERT(max(null, 0) == 0) - ASSERT(max("a","b","c")=="c") - ASSERT(max("b","a","c")=="c") \ No newline at end of file + ASSERT(max(1,2,3) == 3) + ASSERT(max(null, 1) == 1) + ASSERT(max(null, -1) == null) + ASSERT(max(1,null) == 1) + ASSERT(max(-1,null) == null) + ASSERT(max(1, null) == 1) + ASSERT(max(0, null) == null) + ASSERT(max(null, 0) == 0) + ASSERT(max("a","b","c")=="c") + ASSERT(max("b","a","c")=="c") diff --git a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs index 80f1df0047..fcdda5049a 100644 --- a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs +++ b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs @@ -1474,7 +1474,7 @@ public static DreamValue NativeProc_md5(NativeProc.Bundle bundle, DreamObject? s private static DreamValue MinComparison(DreamValue min, DreamValue value) { if (value.TryGetValueAsFloat(out var lFloat)) { - if (min.IsNull && lFloat < 0) + if (min.IsNull && lFloat <= 0) min = value; else if (min.TryGetValueAsFloat(out var rFloat) && lFloat <= rFloat) min = value;