Add .conjugate() method to int type

Also add tests for for the int type, and a commented out one for the
bool type.
This commit is contained in:
Alexander Gude
2019-02-03 11:18:23 -08:00
parent 34c99b0c99
commit a95747f161
3 changed files with 9 additions and 0 deletions

View File

@@ -45,6 +45,8 @@ a = complex(2, 4)
assert type(a) is complex
assert type(a + a) is complex
a = 1
assert a.conjugate() == a
a = 12345

View File

@@ -46,3 +46,4 @@ assert True + True == 2
assert False * 7 == 0
assert True > 0
assert int(True) == 1
#assert True.conjugate() == 1

View File

@@ -489,6 +489,11 @@ fn int_bit_length(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
Ok(vm.ctx.new_int(bits.to_bigint().unwrap()))
}
fn int_conjugate(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args, required = [(i, Some(vm.ctx.int_type()))]);
Ok(i.clone())
}
pub fn init(context: &PyContext) {
let ref int_type = context.int_type;
context.set_attr(&int_type, "__eq__", context.new_rustfunc(int_eq));
@@ -526,4 +531,5 @@ pub fn init(context: &PyContext) {
"bit_length",
context.new_rustfunc(int_bit_length),
);
context.set_attr(&int_type, "conjugate", context.new_rustfunc(int_conjugate));
}