From 2ca0a39a4ce0b94989b12b416fe7b5ea6d431bc8 Mon Sep 17 00:00:00 2001 From: cgm616 Date: Mon, 15 Oct 2018 18:06:06 -0400 Subject: [PATCH] Add tests for new max and min --- vm/src/builtins.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/vm/src/builtins.rs b/vm/src/builtins.rs index b49ab8d28..7928a1a8e 100644 --- a/vm/src/builtins.rs +++ b/vm/src/builtins.rs @@ -294,19 +294,14 @@ fn builtin_map(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { } fn builtin_max(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { - arg_check!( - vm, - args, - required = [(x, Some(vm.ctx.int_type())), (y, Some(vm.ctx.int_type()))] - ); + arg_check!(vm, args, required = [(x, None), (y, None)]); - use std::cmp::Ordering; + let order = vm.call_method(x, "__gt__", vec![y.clone()])?; - let order = x.cmp(y); - - match order { - Ordering::Greater | Ordering::Equal => Ok(x.clone()), - _ => Ok(y.clone()), + if objbool::get_value(&order) { + Ok(x.clone()) + } else { + Ok(y.clone()) } }