# lec14_test.py
# Lillian Lee (LJL2), Walker M. White (wmw2)
# Mar 13, 2014
"""Unit test for (mostly) recursive string functions."""
import cornelltest
import lec14


def test_num_e():
    """test functions that count es"""

    for fn in [lec14.num_es, lec14.num_es_compact, lec14.num_es_middle]:
        print '     testing ' + fn.__name__

        # use python's built-in count function to test
        for test_s in ['', 'c', 'ab', 'asdfftgylkjb',
                       'e', 'eg', 'ge', 'ceceddd', 'c e x']:
            cornelltest.assert_equals(test_s.count('e'),
                                      fn(test_s))
    print ' finished test of "number-of-e" functions'



def test_palindrome_fns():
    """test palindrome dectectors"""

    # All functions should return the same result on these test cases, so run
    # them on the exact same test cases.
    for fn in [lec14.ispalindrome]:
        print ' testing ' + fn.__name__

        for test_s in ['', 'B', 'BB', 'BoB',
                       'ablewasiereisawelba', 'amanaplanacanalpanama']:
            cornelltest.assert_true(fn(test_s))

        for test_s in ['BA', 'BOA', 'BABA', 'amanaplana canalpanama']:
            cornelltest.assert_true(not fn(test_s))

    print ' finished palindrome tests'



def test_reverse():
    """test reverse"""

    for test_s in ['abc', '', 'abac']:
        test_s_list = list(test_s)
        test_s_list.reverse()
        answer = ''.join(test_s_list)
        cornelltest.assert_equals(answer, lec14.reverse(test_s))
    print ' finished test of reverse'




# Application Code
if __name__ == '__main__':
    test_num_e()
    test_palindrome_fns()
    test_reverse()
    print 'Tests of string recursion all passed'