title: How do you decide which functions you need to create test cases for?
body: <p>I'm new to programming and this is my first time trying to create test cases. My goal is to use the unittesting module and run test cases on my program for each possible scenario.
  My question is how do you determine which functions need testing or where to begin? Can someone provide an example from my code snippet to help me get started? And once you start creating test cases how do you know when you're finished?</p>
  <pre class="lang-py prettyprint-override"><code>import string
  
  # -----------------------------
  
  def createPokedex(filename):
      pokedex = {}
      file = open(filename, &quot;r&quot;)
      for pokemon in file:
          pokelist = pokemon.strip().split(&quot;,&quot;)
          index = int(pokelist.pop(0))
          pokedex[index] = [pokelist.pop(0)]         
          pokedex[index] += [int(pokelist.pop(0))]   
          pokedex[index] += [pokelist.pop(0)]
          if len(pokelist) == 1:
              pokedex[index] += [pokelist.pop(0)]    
      return pokedex
  
  # -----------------------------
  
  def print_pokedex(pokedex):
      print(&quot;\n------ The Pokedex --------\n&quot;)
      for i in pokedex:
          list = pokedex.get(i)
          n = len(list)
          if n == 3:
              print(&quot;Number = &quot;, i, &quot;Name: &quot;, list[0], &quot;CP: &quot;, list[1] , &quot;Type: &quot; + list[2])
          if n == 4:
              print(&quot;Number = &quot;, i, &quot;Name: &quot;, list[0], &quot;CP: &quot;, list[1] , &quot;Type: &quot; + list[2] + &quot; and &quot; + list[3])
      print()
  
  
  def getChoice(low, high, message):
      legal_choice = False
      while not legal_choice:
          legal_choice = True
          answer = input(message)
          for character in answer:
              if character not in string.digits:
                  legal_choice = False
                  print(&quot;That is not a number, try again.&quot;)
                  break
          if legal_choice:
              answer = int(answer)
              if (answer &lt; low) or (answer &gt; high):
                  legal_choice = False
                  print(&quot;That is not a valid choice, try again.&quot;)
      return answer
    
  
  def lookup_by_number(pokedex, number):
      if number in pokedex:
          list = pokedex.get(number)
          n = len(list)
          if n == 3:
              print(&quot;Number = &quot;, number, &quot;Name: &quot;, list[0], &quot;CP: &quot;, list[1] , &quot;Type: &quot; + list[2])
          if n == 4:
              print(&quot;Number = &quot;, number, &quot;Name: &quot;, list[0], &quot;CP: &quot;, list[1] , &quot;Type: &quot; + list[2] + &quot; and &quot; + list[3])
          print()
      else:
          print(&quot;Invalid number!\n&quot;)
  
  
  def lookup_by_name(pokedex, name):
      found = 0
      for i in pokedex:
          list = pokedex.get(i)
          if list[0].lower() == name.lower():
              found = 1
              n = len(list)
              if n == 3:
                  print(&quot;Number = &quot;, i, &quot;Name: &quot;, list[0], &quot;CP: &quot;, list[1] , &quot;Type: &quot; + list[2])
              if n == 4:
                  print(&quot;Number = &quot;, i, &quot;Name: &quot;, list[0], &quot;CP: &quot;, list[1] , &quot;Type: &quot; + list[2] + &quot; and &quot; + list[3])
              print()
      if found == 0:
          print(&quot;Invalid name!\n&quot;)
        
  
  def total_by_type(pokedex, type):
      count = 0
      for i in pokedex:
          list = pokedex.get(i)
          n = len(list)
          if n == 4:
              if ((list[2].lower() == type.lower()) or (list[2].lower() == type.lower())):
                  count = count + 1
          if n == 3:
              if (list[2] == type):
                  count = count + 1
      print(&quot;Number of pokemon of given type = &quot;, count)
      print()
  
  
  def average_hit_points(pokedex):
      count = 0
      for i in pokedex:
          list = pokedex.get(i)
          count = count + list[1]
      avg = count / 30
      print(&quot;Average hit points = %.2f&quot; %avg)
      print()
  
  
  def print_menu():
      print(&quot;1. Print Pokedex&quot;)
      print(&quot;2. Print Pokemon by Name&quot;)
      print(&quot;3. Print Pokemon by Number&quot;)
      print(&quot;4. Count pokemon by type&quot;)
      print(&quot;5. Print Average Hit Points&quot;)
      print(&quot;6. Quit&quot;)
  
  # -----------------------------
  
  def main():
      pokedex = createPokedex(r&quot;C:\Users\phill\OneDrive\Documents\pokedex.txt&quot;)
      choice = 0
      while choice != 6:
          print_menu()
          choice = getChoice(1, 6, &quot;Enter a menu option: &quot;)
          if choice == 1:  
              print_pokedex(pokedex)
          elif choice == 2:
              name = input(&quot;Enter a Pokemon name: &quot;)
              name = name.capitalize()
              lookup_by_name(pokedex, name)
          elif choice == 3:
              number = getChoice(1, 1000, &quot;Enter a Pokemon number: &quot;)
              lookup_by_number(pokedex, number)
          elif choice == 4:
              type = input(&quot;Enter a Type: &quot;)
              total_by_type(pokedex, type.lower())
          elif choice == 5:
              average_hit_points(pokedex)
      print(&quot;Thank you. Goodbye!&quot;)
  
  main()
  </code></pre>