UNB/ CS/ David Bremner/ teaching/ cs2613/ tests/ T3/ q3-tests.py
list1 = [f'hello {n}' for n in range(10)] + ['hello world' ] + \
  [f'goodbye {n}' for n in range(10)] + [ 'goodbye world' ] + \
  [f'pi{n}' for n in range(10)] + [ 'pizza' ]

def contains_test(flt, tuple1, tuple2):
    assert 'banana' not in flt
    assert ('hello world' in flt, 'goodbye world' in flt, 'pizza' in flt) == \
        tuple1
    for n in range(10):
        f'hello {n}' in flt and f'goodbye {n}' in flt and f'pi{n}' in flt == \
            tuple2

def test_in_default():
    contains_test(Filter(list1), (True,True,True), (True, True, True))

def test_in_irrelevant():
    contains_test(Filter(list1, {'food' : False}),
                  (True,True,True), (True, True, True))

def test_in_exclude():
    contains_test(Filter(list1, {'world' : False}),
                  (False,False,True), (True, True, True))

def test_in_include():
    contains_test(Filter(list1, {'world' : True}),
                  (True, True, False), (False, False, False))

def test_in_include_exclude():
    contains_test(Filter(list1, {'world' : True, 'goodbye': False}),
                  (True, False, False), (False, False, False))

def test_default_filter():
    flt = Filter(list1)
    assert list(flt) == list1
    assert list(flt) == list1

def test_irrelevant_filter():
    flt = Filter(list1, {'food' : False})
    assert list(flt) == list1
    assert list(flt) == list1

def test_exclude():
    assert list(Filter(list1, {'world' : False})) == \
        [f'hello {n}' for n in range(10)] + \
        [f'goodbye {n}' for n in range(10)] + \
        [f'pi{n}' for n in range(10)] + [ 'pizza' ]

def test_include():
    flt = Filter(list1, {'world' : True})
    assert list(flt) == ['hello world', 'goodbye world']
    assert list(flt) == ['hello world', 'goodbye world']

def test_include_exclude():
    flt=Filter(list1, {'world' : True, 'goodbye': False})
    assert list(flt) == [ 'hello world' ]
    assert list(flt) == [ 'hello world' ]

def test_nest():
    flt1=Filter(list1, {'world' : True})
    flt2=Filter(flt1, {'goodbye': False})
    assert list(flt2) == [ 'hello world' ]
    assert list(flt2) == [ 'hello world' ]