#Test that the functions behave properly on fade-lengths and pan-lengths of 0
#This is a separate test so that if the submission messes this up, the deduction
#is not made multiple times.

import a1
import sound
import unittest

fade1 = [[20,40], [40,0], [-20,-40],[-40,0], [-40, 20]] + [[-999, -999]] * 5

fade1end = [[-999, -999]] * 5 + [[20,40], [40,0], [-20,-40],[-40,0], [-40, 20]] 

fade6 = [[40,20], [40,4],[-32,64],[72,36],[-999,-999],[-999,-999],[-20,40],[8,60],[20,20],[-96,-100]]

lr1 = [[30,20],[-20,40],[40,60],[70,30],[-90,20]] + [[-999, -999]] * 5

def make_sound (lst):
  '''Return a sound object from List lst of sample values. Each element of
  lst is a 2-element list where the first is the left channel value and 
  the second is the right channel value. '''

  snd = sound.create_sound (len(lst))
  for i in range(len(lst)):
    samp = sound.get_sample (snd, i)
    sound.set_left (samp, lst[i][0])
    sound.set_right (samp, lst[i][1])
  return snd


class TestCases(unittest.TestCase):

  def setUp(self):
    pass
  
  def test_fade_in_zero(self):
    '''Test fade_in with zero fade_length.'''

    snd = make_sound (fade1)
    snd2 = sound.copy (snd)    
    student = a1.fade_in (snd, 0)
    self.assertEqual (student, snd2)  
  
  def test_fade_out_zero(self):
    '''Test fade_out with zero fade_length.'''

    snd = make_sound (fade1end)
    snd2 = sound.copy (snd)    
    student = a1.fade_out (snd, 0)
    self.assertEqual (snd, snd2)    

  def test_fade_zero(self):
    '''Test fade with zero fade_length.'''

    snd = make_sound (fade6)
    snd2 = sound.copy (snd)    
    student = a1.fade (snd, 0)
    self.assertEqual (snd, snd2)    

  def test_left_to_right_zero(self):
    '''Test left_to_right with zero fade_length.'''

    snd = make_sound (lr1)
    snd2 = sound.copy (snd)    
    student = a1.left_to_right (snd, 0)
    self.assertEqual (snd, snd2)    

if __name__ == '__main__':
    unittest.main()

