Пример #1
0
 def test_equality(self):
     from typecheck import Length
     
     eq_tests = [(Length(4), Length(4)), (Length(4.0), Length(4))]
     ne_tests = [(Length(5), Length(4))]
                 
     test_equality(eq_tests, ne_tests)
Пример #2
0
 def test_equality(self):
     from typecheck import Typeclass
     
     eq_tests = [ (Typeclass(int), Typeclass(int)),
                  (Typeclass(int, float), Typeclass(float, int)),
                  (Typeclass(int, int), Typeclass(int)),
                  (Typeclass(int), Typeclass(Typeclass(int))) ]
                  
     ne_tests = [ (Typeclass(int), Typeclass(float)) ]
     
     test_equality(eq_tests, ne_tests)
Пример #3
0
 def test_equality(self):
     from typecheck import Exact
     
     eq_tests = [
                 (Exact(4), Exact(4)),
                 (Exact([4, 5]), Exact([4, 5])),
                 (Exact(Exact), Exact(Exact)) ]
                 
     ne_tests = [
                 (Exact(4), Exact(5)),
                 (Exact([5, 4]), Exact([4, 5])),
                 (Exact(Exact), Exact(object)),
                 (Exact(object), Exact(dict)) ]
                 
     test_equality(eq_tests, ne_tests)
Пример #4
0
 def test_equality(self):
     from typecheck import YieldSeq, And
     
     eq_tests = [
         (YieldSeq(int, float), YieldSeq(int, float)),
         (YieldSeq(And(int, str), float), YieldSeq(And(int, str), float)) ]
         
     ne_tests = [
         (YieldSeq(float, str), YieldSeq(int, float)),
         (YieldSeq(int, float), YieldSeq(int, int, int, float)),
         (YieldSeq(int, float, str), YieldSeq(int, float)),
         (YieldSeq(int, float), YieldSeq(int, float, str)),
         (YieldSeq(int, float), And(int, float)),
         (YieldSeq(int, int, int, float), YieldSeq(int, float)) ]
         
     test_equality(eq_tests, ne_tests)
Пример #5
0
 def test_equality(self):
     from typecheck import Single
     
     class A(object): pass
     class B(A): pass
     
     eq_tests = [
         (Single(int), Single(int)),
         (Single(A), Single(A)),
         (Single(B), Single(B)) ]
         
     ne_tests = [
         (Single(int), Single(float)),
         (Single(A), Single(B)) ]
     
     test_equality(eq_tests, ne_tests)
Пример #6
0
 def test_equality(self):
     from typecheck import Empty
     
     eq_tests = [
         (Empty(list), Empty(list)),
         (Empty(dict), Empty(dict)),
         (Empty(set), Empty(set)) ]
         
     ne_tests = [
         (Empty(list), Empty(dict)),
         (Empty(list), Empty(set)),
         (Empty(dict), Empty(list)),
         (Empty(dict), Empty(set)),
         (Empty(set), Empty(list)),
         (Empty(set), Empty(dict)), ]
         
     test_equality(eq_tests, ne_tests)
Пример #7
0
 def test_equality(self):
     from typecheck import Dict
     
     class A(object): pass
     class B(A): pass
     
     eq_tests = [
         (Dict(str, int), Dict(str, int)),
         (Dict(str, A), Dict(str, A)),
         (Dict(str, Dict(str, int)), Dict(str, Dict(str, int))) ]
         
     ne_tests = [
         (Dict(str, int), Dict(int, str)),
         (Dict(str, int), {'a': 5}),
         (Dict(str, Dict(str, int)), Dict(str, Dict(int, str))) ]
     
     test_equality(eq_tests, ne_tests)
Пример #8
0
 def test_equality(self):
     from typecheck import Or, And
     
     eq_tests = [
         (Or(int, float), Or(int, float)),
         (Or(int, float), Or(int, int, int, float)),
         (Or(int, int, int, float), Or(int, float)),
         (Or(int, float), Or(float, int)),
         (Or(Or(int, str), float), Or(float, Or(str, int))),
         (Or(Or(int, str), float), Or(int, str, float)) ]
         
     ne_tests = [
         (Or(float, str), Or(int, float)),
         (Or(int, float, str), Or(int, float)),
         (Or(int, float), Or(int, float, str)),
         (Or(int, float), And(int, float)) ]
         
     test_equality(eq_tests, ne_tests)
Пример #9
0
 def test_equality(self):
     from typecheck import HasAttr, Any
     
     eq_tests = [
         (HasAttr(['a']), HasAttr(['a'])),
         (HasAttr(['a', 'b']), HasAttr(['b', 'a'])),
         (HasAttr({'a': int}), HasAttr({'a': int})),
         (HasAttr({'a': int, 'b': int}), HasAttr({'b': int, 'a': int})),
         (HasAttr({'a': HasAttr(['a'])}), HasAttr({'a': HasAttr(['a'])})),
         (HasAttr(['a'], {'b': int, 'c': int}), HasAttr(['a'], {'b': int, 'c': int})),
         (HasAttr(['a']), HasAttr({'a': Any()})),
         (HasAttr({'a': int, 'b': float, 'c': str}), HasAttr({'a': int, 'b': float, 'c': str})) ]
         
     ne_tests = [
         (HasAttr(['a', 'b']), HasAttr(['b'])),
         (HasAttr(['a', 'b']), HasAttr(['a'], {'b': int})),
         (HasAttr({'a': HasAttr(['a'])}), HasAttr({'a': HasAttr(['b'])})), ]
         
     test_equality(eq_tests, ne_tests, 100)
Пример #10
0
 def test_equality(self):
     from typecheck import Not, Or
     
     eq_tests = [
         (Not(int, float), Not(int, float)),
         (Not(int, float), Not(int, int, int, float)),
         (Not(int, int, int, float), Not(int, float)),
         (Not(int, float), Not(float, int)),
         (Not(Not(int, str), float), Not(float, Not(str, int))) ]
         
     ne_tests = [
         (Not(float, str), Not(int, float)),
         (Not(int, float, str), Not(int, float)),
         (Not(int, float), Not(int, float, str)),
         (Not(int, float), Or(int, float)),
         (Not(Not(int, str), float), Not(int, str, float)),
         (Not(Not(int, float), Not(str, int)), Not(int, float, str)) ]
         
     test_equality(eq_tests, ne_tests)
Пример #11
0
 def test_equality(self):
     from typecheck import And, Or
     
     eq_tests = [
         (And(int, float), And(int, float)),
         (And(int, float), And(int, int, int, float)),
         (And(int, int, int, float), And(int, float)),
         (And(int, float), And(float, int)),
         (And(And(int, str), float), And(float, And(str, int))),
         (And(And(int, str), float), And(int, str, float)),
         (And(And(int, float), And(str, int)), And(int, float, str)) ]
         
     ne_tests = [
         (And(float, str), And(int, float)),
         (And(int, float, str), And(int, float)),
         (And(int, float), And(int, float, str)),
         (And(int, float), Or(int, float)) ]
         
     test_equality(eq_tests, ne_tests)
Пример #12
0
 def test_equality(self):
     from typecheck import Xor, Or
     
     eq_tests = [
         (Xor(int, float), Xor(int, float)),
         (Xor(int, float), Xor(int, int, int, float)),
         (Xor(int, int, int, float), Xor(int, float)),
         (Xor(int, float), Xor(float, int)),
         (Xor(Xor(int, str), float), Xor(float, Xor(str, int))),
         (Xor(Xor(int, str), float), Xor(int, str, float)),
         (Xor(Xor(int, float), Xor(str, int)), Xor(int, float, str)) ]
         
     ne_tests = [
         (Xor(float, str), Xor(int, float)),
         (Xor(int, float, str), Xor(int, float)),
         (Xor(int, float), Xor(int, float, str)),
         (Xor(int, float), Or(int, float)) ]
         
     test_equality(eq_tests, ne_tests)
Пример #13
0
 def test_equality(self):
     from typecheck import Tuple
     
     class A(object): pass
     class B(A): pass
     
     eq_tests = [
         (Tuple(str, int), Tuple(str, int)),
         (Tuple(str, A), Tuple(str, A)),
         (Tuple(), Tuple()),
         (Tuple(str, Tuple(str, int)), Tuple(str, Tuple(str, int))) ]
         
     ne_tests = [
         (Tuple(str, int), Tuple(int, str)),
         (Tuple(str, int), (str, int)),
         (Tuple(A, A), Tuple(A, B)),
         (Tuple(str, int, float), Tuple()),
         (Tuple(str, Tuple(str, int)), Tuple(str, Tuple(int, str))) ]
     
     test_equality(eq_tests, ne_tests)
Пример #14
0
 def test_equality(self):
     from typecheck import List
     
     class A(object): pass
     class B(A): pass
     
     eq_tests = [
         (List(str, str), List(str, str)),
         (List(A, B), List(A, B)),
         (List(List(int, int), int), List(List(int, int), int)) ]
         
     ne_tests = [
         (List(str, int), List(int, str)),
         (List(A, B), List(B, B)),
         (List(A, B), List(A, A)),
         (List(), List(int, int)),
         (List(List(int, int)), List(List(List(int, int)))),
         (List(int, int), List(int, int, int)),
         (List(int, int), [int, int]) ]
     
     test_equality(eq_tests, ne_tests)
Пример #15
0
    def test_equality(self):
        class A(object):
            pass

        class B(A):
            pass

        eq_tests = [(Set([str]), Set([str])), (Set([A, B]), Set([A, B])),
                    (Set([]), Set([])), (Set([int, int, str]), Set([int,
                                                                    str])),
                    (Set([int, str]), Set([str, int])),
                    (Set([Set([int, float]),
                          int]), Set([Set([float, int]), int])),
                    (Set([Set([int, str]),
                          Set([int, str])]), Set([Set([int, str])]))]

        ne_tests = [(Set([A, B]), Set([B, B])), (Set([A, B]), Set([A, A])),
                    (Set([]), Set([int, int])),
                    (Set([Set([int, str])]), Set([Set([Set([int, str])])])),
                    (Set([int, int]), set([int, int]))]

        test_equality(eq_tests, ne_tests)