示例#1
0
文件: test.py 项目: LX19970305/Lab3
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
示例#2
0
文件: test.py 项目: LX19970305/Lab3
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
示例#3
0
 def __init__(self, incluster, outcluster):
     self._inputs = [incluster]
     self._outputs = [outcluster]
     self._constraints = []
     MultiMethod.__init__(self)
示例#4
0
 def __init__(self, incluster, selclusters, outcluster, constraints, enabled):
     self._inputs = [incluster]+selclusters+[enabled]
     self._outputs = [outcluster]
     self._constraints = constraints
     MultiMethod.__init__(self)
示例#5
0
 def __init__(self):
     self.overconstrained = None
     self.consistent = None
     MultiMethod.__init__(self)
示例#6
0
 def __init__(self, incluster, selclusters, outcluster, constraints):
     self._inputs = [incluster] + selclusters
     self._outputs = [outcluster]
     self._constraints = constraints
     MultiMethod.__init__(self)
示例#7
0
 def __init__(self):
     self.consistent = None
     self.overconstrained = None
     MultiMethod.__init__(self)
示例#8
0
 def __init__(self, incluster, outcluster):
     self._inputs = [incluster]
     self._outputs = [outcluster]
     self._constraints = []
     MultiMethod.__init__(self)