# William M. Farmer
# 25 November 2010
#
# This is a solution for Lab 09: Marked Assignment 4 Wednesday.


import math

def fun(x):
    return math.sin(x)

def buildInputList(a,b):
    "Returns [a = x0, x1, ..., x100 = b]."
    a,b = min(a,b),max(a,b)  # Swaps a and b if a >= b.
    L = range(101)
    for i in range(101):
        L[i] = a + (i * ((b - a)/100.0))
    return L

def buildOutputList(L):
    "Maps [x0, x1, ..., x100] to [fun(x0), fun(x1), ..., fun(x100)]."
    newL = range(len(L))     
    for i in range(len(L)):
        newL[i] = fun(L[i])
    return newL

def checkProperty(a,b):
    "Checks if fun is negative on [a,b]."
    L = buildOutputList(buildInputList(a,b))
    neg = True
    for x in L:
        if x >= 0:
            neg = False
    if neg:
        return True
    else:
        return False


# Design Question
# 
# buildOutputList could be made more general by adding a second
# parameter to the parameter L: fun, the function that is applied to
# each member of L.
# 
# Test Plan
#
# Test 1 for fun(x):
# Input: 5
# Expected Output: 120
#
# Test 2 for fun(x):
# Input: -1
# Expected Output: 0
#
# Test 1 for builInputList(a,b):
# Input: 10 , 5
# Expected Output: A list with elements starting at 5.0 incrementing by
# .05 ending at 10.0
#
# Test 1 for buildOutputList(L):
# Input: [4.5, 5.0, 5.5, ... ,54.0]
# Expected Output: [86.625, 120.0, 160.875, ... ,157410.0]
#
# Test 2 for buildOutputList(L):
# Input: []
# Expected Output: []
#
# Test 1 for checkProperty(a,b):
# Input: 0,1
# Expected Output: False
# 
# Test 2 for checkProperty(a,b):
# Input: -3,-1.5
# Expected Output: False
# 
# Test 3 for checkProperty(a,b):
# Input: 10,11
# Expected Output: True
