Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix min/max also test #1646

Merged
merged 7 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Content.Tests/DMProject/Tests/Math/minmax.dm
Original file line number Diff line number Diff line change
@@ -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)
amylizzle marked this conversation as resolved.
Show resolved Hide resolved
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)
amylizzle marked this conversation as resolved.
Show resolved Hide resolved
ASSERT(max("a","b","c")=="c")
ASSERT(max("b","a","c")=="c")
15 changes: 10 additions & 5 deletions OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
Expand Down
Loading