"""
A library in which students may develop searching tools.

Author: Zachary Palmer
Date: 2015-10-28 - 2015-10-29
"""

def linear_search(lst, element):
  """
  Performs a linear search for the given element.  Returns the index at which
  the element is found or None if the element is not found.
  """
  for i in range(len(lst)):
    if lst[i] == element:
      return i
  return None

def binary_search(lst, element):
  """
  Performs a binary search for the given element.  Returns the index at which
  the element is found or None if the element is not found.
  """
  # TODO: implement this search!
  raise NotImplementedError("binary_search has not yet been written!")

def test_linear_search(lst, search_element, expected_result):
  if linear_search(lst,search_element) != expected_result:
    print "linear_search is broken!  %s looking for %s is not %s" % (str(lst),str(search_element),str(expected_result))

def test_binary_search(lst, search_element, expected_result):
  if binary_search(lst,search_element) != expected_result:
    print "binary_search is broken!  %s looking for %s is not %s" % (str(lst),str(search_element),str(expected_result))

def test():
  #if linear_search([1,2,3,4],3) != 2:
  #  print "linear_search is broken!  [1,2,3,4] looking for 3 is not 2"
  #if linear_search([1,5,6],5) != 1:
  #  print "linear_search is broken!  [1,5,6] looking for 5 is not 1"
  #if linear_search([],5) != None:
  #  print "linear_search is broken!  [] looking for 5 is not None"
  test_linear_search([1,2,3,4],3,2)
  test_linear_search([1,5,6],5,1)
  test_linear_search([],5,None)
  test_linear_search([1,2,3,3,4],3,2)
  test_linear_search(["cat","dog","mouse"],"dog",1)
  test_binary_search([1,2,3,4],3,2)
  test_binary_search([1,5,6],5,1)
  test_binary_search([],5,None)
  test_binary_search([1,2,3,3,4],3,2)
  test_binary_search(["cat","dog","mouse"],"dog",1)

if __name__ == "__main__":
  test()

