test.py 1.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
from match import ThreeWayMatchOperator


def tryOrAssert(fn, output, error=False):
    try:
        return (fn() == output)
    except:
        return error


def test1():
    r1 = range(0,10)
    r2 = range(0,10,3)
    r3 = range(0,10,2)

    t = ThreeWayMatchOperator((r1,r2,r3))
    values = set([v[0] for v in t])
    return values


def test2():
    r1 = range(0,12)
    r2 = range(0,10,3)
    r3 = range(0,10,2)

    t = ThreeWayMatchOperator((r1,r2,r3))
    values = set([v[0] for v in t])
    return values


def test3():
    r1 = range(0)
    r2 = range(0)
    r3 = range(0)

    t = ThreeWayMatchOperator((r1,r2,r3))
    values = set([v[0] for v in t])
    return values


def test4():
    r1 = range(0,1)
    r2 = range(0,1)
    r3 = range(0,1)

    t = ThreeWayMatchOperator((r1,r2,r3))
    values = set([v[0] for v in t])
    return values

def test5():
    r1 = ['a', 'b', 'c','d']
    r2 = ['3', '2', '1','d']
    r3 = ['p', 'q', 'a','d']

    t = ThreeWayMatchOperator((r1,r2,r3))
    values = set([v[0] for v in t])
    return values

print("Basic 1", tryOrAssert(test1, {0, 6}))
print("Basic 2", tryOrAssert(test2, {0, 6}))
print("Basic 3", tryOrAssert(test5, {'d'}))
print("Empty",tryOrAssert(test3, None, True))
print("Singleton", tryOrAssert(test4, {0}))