def fct2(): return ShapeBinaryOperator("+", lambda x, y: x + y, "lambda x, y: x + y", DimensionObject((1, 2)), DimensionObject(3))
def test_missing_stmt_binary(self): def fct1(): return ShapeBinaryOperator("+", lambda x, y: x + y, "lambda x, y: x + y", DimensionObject(1), DimensionObject((2, 3))) def fct2(): return ShapeBinaryOperator("+", lambda x, y: x + y, "lambda x, y: x + y", DimensionObject((1, 2)), DimensionObject(3)) self.assertRaise(fct1, TypeError) self.assertRaise(fct2, TypeError) sh = ShapeBinaryOperator("+", lambda x, y: x + y, "lambda x, y: x + y", DimensionObject(1), DimensionObject(2)) st = sh.to_string() self.assertEqual(st, '3') sh = ShapeBinaryOperator("+", lambda x, y: x + y, "lambda x, y: x + y", DimensionObject('1'), DimensionObject('2')) st = sh.to_string() self.assertEqual(st, '(1)+(2)') x, y = sh._args # pylint: disable=W0212 self.assertEqual(sh._to_string1(x, y), "12") # pylint: disable=W0212 self.assertEqual(sh._to_string2(x, y), "1+2") # pylint: disable=W0212 self.assertEqual( sh._to_string2b( # pylint: disable=W0212 x, y), "(1)+(2)") # pylint: disable=W0212 self.assertEqual(sh._to_string3(x), "1+x") # pylint: disable=W0212 sh = ShapeBinaryOperator("+", lambda x, y: x + y, "lambda x, y: x + y", DimensionObject('X'), DimensionObject(2)) st = sh.to_string() self.assertEqual(st, 'X+2') sh = ShapeBinaryOperator("+", lambda x, y: x + y, "lambda x, y: x + y", DimensionObject(2), DimensionObject('X')) st = sh.to_string() self.assertEqual(st, '2+X') sh = ShapeBinaryOperator("+", lambda x, y: x + y, "lambda x, y: x + y", DimensionObject(2), DimensionObject(None)) st = sh.to_string() self.assertEqual(st, '2+x') d = DimensionObject(None) self.assertEqual(d.dim, None) d = DimensionObject(DimensionObject(2)) st = repr(d) self.assertEqual(st, "DimensionObject(2)")
def fct1(): return ShapeBinaryOperator("+", lambda x, y: x + y, "lambda x, y: x + y", DimensionObject(1), DimensionObject((2, 3)))
def test_missing_stmt_binary(self): def fct1(): return ShapeBinaryOperator("+", lambda x, y: x + y, "lambda x, y: x + y", DimensionObject(1), DimensionObject((2, 3))) def fct2(): return ShapeBinaryOperator("+", lambda x, y: x + y, "lambda x, y: x + y", DimensionObject((1, 2)), DimensionObject(3)) self.assertRaise(fct1, TypeError) self.assertRaise(fct2, TypeError) sh = ShapeBinaryOperator("+", lambda x, y: x + y, "lambda x, y: x + y", DimensionObject(1), DimensionObject(2)) st = sh.to_string() self.assertEqual(st, '3') sh = ShapeBinaryOperator("+", lambda x, y: x + y, "lambda x, y: x + y", DimensionObject('1'), DimensionObject('2')) st = sh.to_string() self.assertEqual(st, '(1)+(2)') sh = ShapeBinaryOperator("+", lambda x, y: x + y, "lambda x, y: x + y", DimensionObject('X'), DimensionObject(2)) st = sh.to_string() self.assertEqual(st, 'X+2') sh = ShapeBinaryOperator("+", lambda x, y: x + y, "lambda x, y: x + y", DimensionObject(2), DimensionObject('X')) st = sh.to_string() self.assertEqual(st, '2+X') sh = ShapeBinaryOperator("+", lambda x, y: x + y, "lambda x, y: x + y", DimensionObject(2), DimensionObject(None)) st = sh.to_string() self.assertEqual(st, '2+x') d = DimensionObject(None) self.assertEqual(d.dim, None) d = DimensionObject(DimensionObject(2)) st = repr(d) self.assertEqual(st, "DimensionObject(2)")