Commit 7d997be0 authored by Jesse McGrew's avatar Jesse McGrew
Browse files

Changed MIN and MAX to allow 0 args. [ZILF-202]

<MIN> returns int.MaxValue, and <MAX> returns int.MinValue.
parent 410a382df17f
......@@ -142,15 +142,15 @@ namespace Zilf.Interpreter
}
[Subr]
public static ZilObject? MIN(Context ctx, [Required] int[] args)
public static ZilObject MIN(Context ctx, int[] args)
{
return new ZilFix(args.Min());
return new ZilFix(args.Length == 0 ? int.MaxValue : args.Min());
}
[Subr]
public static ZilObject MAX(Context ctx, [Required] int[] args)
public static ZilObject MAX(Context ctx, int[] args)
{
return new ZilFix(args.Max());
return new ZilFix(args.Length == 0 ? int.MinValue : args.Max());
}
[Subr("OR?")]
......
......@@ -252,14 +252,15 @@ namespace Zilf.Tests.Interpreter
[TestMethod]
public void TestMIN_MAX()
{
TestHelpers.EvalAndAssert("<MIN>", new ZilFix(int.MaxValue));
TestHelpers.EvalAndAssert("<MAX>", new ZilFix(int.MinValue));
TestHelpers.EvalAndAssert("<MIN 1>", new ZilFix(1));
TestHelpers.EvalAndAssert("<MAX 4>", new ZilFix(4));
TestHelpers.EvalAndAssert("<MIN -5 2 0 12>", new ZilFix(-5));
TestHelpers.EvalAndAssert("<MAX -5 2 0 12>", new ZilFix(12));
TestHelpers.EvalAndCatch<InterpreterError>("<MIN>");
TestHelpers.EvalAndCatch<InterpreterError>("<MAX>");
TestHelpers.EvalAndCatch<InterpreterError>("<MIN APPLE>");
TestHelpers.EvalAndCatch<InterpreterError>("<MIN '(1 2 3)>");
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment