# Ryan Martin
# macid: abcd123
# student number: #######
# August 2, 2011
#
# This is a solution for Major Assignment 3 (Lab 08).

def toASCII(s):
    '''Takes a string and returns a list of ASCII character equivalents.'''
    result = []
    for char in s:
        result.append(ord(char))

    return result

def toString(a):
    '''Takes a list of ASCII character codes and returns a string equivalent.'''
    result = ''
    for num in a:
        result = result + chr(num)

    return result

def encode(S):
    '''Encodes a list of strings by converting to ASCII codes.'''
    result = []
    for word in S:
        result.append(toASCII(word))

    return result

def decode(A):
    '''Decodes a set of ASCII codes by converting to strings.'''
    result = []
    for charSet in A:
        result.append(toString(charSet))
    
    return result

'''
Design Question

To shift the ASCII codes up by a (small) integer n,
an extra step would need to be added to the 
toASCII function that adds n to the ASCII code
for each character after applying ord(). 
Additionally, n should be subtracted from the
codes in toString before applying chr(). It should
be noted that simply adding n will result in some
special characters to appear ie. z + (a number)
could be a symbol or capital letter. With some
clever thought the modulo operator can be used to
create a "wrapping" addition. For example z + 2 = b.


If n is to be variable by the user, an additional
parameter for n needs to be added to all 
four functions in the library.

'''
##Note: This format is used by our automated marking system.
##You will see that, for inputs, the function name is
##given with the corresponding inputs to that function
##listed right after it.
##Format: [funName, [arg1, arg2, ...]]

'''
Test Plan

V01 = {'test1': 
       {'inputs': ['toASCII',['TestString']],
       'outputs': [[84, 101, 115, 116, 83, 116, 114, 105, 110, 103]]},
       
       'test2':
       {'inputs': ['toString',[[84, 101, 115, 116, 83, 116, 114, 105, 110, 103]]],
       'outputs': ['TestString']},
       
       'test3':
       {'inputs': ['encode',[['This', 'is', 'a', 'test']]],
       'outputs': [[[84, 104, 105, 115], [105, 115], [97], [116, 101, 115, 116]]]},
       
       'test4':
       {'inputs': ['decode',[[[84, 104, 105, 115], [105, 115], [97], [116, 101, 115, 116]]]],
       'outputs': [['This', 'is', 'a', 'test']]},
       
       'test5': 
       {'inputs': ['toASCII',['']],
       'outputs': [[]]}
        
       'test6': 
       {'inputs': ['toASCII',['\n\\n']],
       'outputs': [[10, 92, 110]]}}}
'''


