Exemplo n.º 1
0
def test_arguments():
    f = MultiMethod('f')

    @f.register(int, int)
    @f.register(int)
    def foo(a, b=10):
        return a - b

    assert foo(10, 3) == 7
    assert foo(5) == -5
    assert foo(b=2, a=1) == -1
    assert foo(a=1, b=2) == -1
Exemplo n.º 2
0
def test_addmethod():
    D = MultiMethod('add')

    D.add((int, int), lambda x, y: x + y)
    D.add((float, float), lambda x, y: x + y)

    assert D(1, 2) == 3
    assert D(1.0, 2.0) == 3.0
Exemplo n.º 3
0
 def __init__(self, incluster, outcluster):
     self._inputs = [incluster]
     self._outputs = [outcluster]
     self._constraints = []
     MultiMethod.__init__(self)
Exemplo n.º 4
0
 def __init__(self, incluster, selclusters, outcluster, constraints, enabled):
     self._inputs = [incluster]+selclusters+[enabled]
     self._outputs = [outcluster]
     self._constraints = constraints
     MultiMethod.__init__(self)
Exemplo n.º 5
0
 def __init__(self):
     self.overconstrained = None
     self.consistent = None
     MultiMethod.__init__(self)
Exemplo n.º 6
0
 def __init__(self, incluster, selclusters, outcluster, constraints):
     self._inputs = [incluster] + selclusters
     self._outputs = [outcluster]
     self._constraints = constraints
     MultiMethod.__init__(self)
Exemplo n.º 7
0
 def __init__(self):
     self.consistent = None
     self.overconstrained = None
     MultiMethod.__init__(self)
Exemplo n.º 8
0
 def __init__(self, incluster, outcluster):
     self._inputs = [incluster]
     self._outputs = [outcluster]
     self._constraints = []
     MultiMethod.__init__(self)