# embeddingtest.py
# Lillian Lee (LJL2@cornell.edu)
# Mar 5, 2014

import cornelltest
import embedding

def test_embed():
    """test embedding function variants"""

    # since the functions do the same thing, test them on the same testcases
    for fn in [embedding.embed,
               embedding.embed_if,
               embedding.embed_alt_if,
               embedding.embed_nonrecursive,
               embedding.embed_reverse_conditional]:
        print " testing " + fn.__name__

        cornelltest.assert_equals(0, fn('a'))

        cornelltest.assert_equals(1, fn(['oh']))
        cornelltest.assert_equals(1, fn(['oh', 'hi']))
        cornelltest.assert_equals(1, fn(['oh', 'hi', 'there']))

        cornelltest.assert_equals(2, fn(['oh', ['hi'], 'there']))
        cornelltest.assert_equals(2, fn([['oh'], ['hi'], ['there']]))

        s1 = ['hit', ['a', 'guy'], ['with', 'glasses']]
        s2 = ['hit', ['a', 'guy',  ['with', 'glasses']]]

        cornelltest.assert_equals(2, fn(s1))
        cornelltest.assert_equals(3, fn(s2))
        s3 = ['the', [['red', 'house'], 'and', 'barn', ['that', 'jack', 'built']], 'was', 'razed']
        cornelltest.assert_equals(3, fn(s3))

        d1 = ['i', ['saw', ['her', 'duck'], ['with', 'a', 'telescope']]]
        d2 = ['i', ['saw', ['her', ['duck', ['with', 'a', 'telescope']]]]]
        d3 = ['i', ['saw', ['her', 'duck'], ['with', 'a', 'telescope']]]
        cornelltest.assert_equals(3, fn(d1))
        cornelltest.assert_equals(5, fn(d2))
        cornelltest.assert_equals(3, fn(d3))
        print ' finished test of embedding'


if __name__ == '__main__':
    test_embed()
    print "All embedding test cases passed"