From 5a75e23c411aec1fa8f97b9ff9b931cae117c6e9 Mon Sep 17 00:00:00 2001 From: Guillermo Ramos-Macias Date: Mon, 13 Mar 2017 16:05:40 -0400 Subject: [PATCH] Implemented Bool.__mod__(bool) part of issue #46 --- batavia/types/Bool.js | 15 +++++++++++++++ tests/datatypes/test_bool.py | 1 - 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/batavia/types/Bool.js b/batavia/types/Bool.js index d7103ee9d..0358ea154 100644 --- a/batavia/types/Bool.js +++ b/batavia/types/Bool.js @@ -267,6 +267,21 @@ Bool.prototype.__mul__ = function(other) { } } Bool.prototype.__mod__ = function(other) { + var types = require('../types') + var result + if (types.isinstance(other, types.Bool)) { + if (this.valueOf()) { + result = 0 + } else { + result = new types.Bool(0) + } + if (other.valueOf()) { + return result + } else { + throw new exceptions.ZeroDivisionError.$pyclass('integer division or modulo by zero') + } + } + throw new exceptions.TypeError.$pyclass("unsupported operand type(s) for %: 'bool' and '" + type_name(other) + "'") } diff --git a/tests/datatypes/test_bool.py b/tests/datatypes/test_bool.py index 6796b796b..d83351c26 100644 --- a/tests/datatypes/test_bool.py +++ b/tests/datatypes/test_bool.py @@ -34,7 +34,6 @@ class BinaryBoolOperationTests(BinaryOperationTestCase, TranspileTestCase): 'test_lshift_int', - 'test_modulo_bool', 'test_modulo_complex', 'test_modulo_float', 'test_modulo_int',