import a1
import sound
import unittest

#For each of these variables, element 0 is the list used to generate the
#input sample and element 1 is the list used to generate the expected output


fade6 = [
[[40,20], [40,4],[-32,64],[72,36],[-999,-999],[-999,-999],[-20,40],[8,60],[20,20],[-96,-100]],
[[0, 0], [10, 1], [-16, 32], [54, 27], [-999, -999], [-999, -999], [-15, 30], [4, 30], [5, 5], [0, 0]]
]

fade7 = [
[[30,20],[-20,40],[-999,-999],[70,30],[-90,20]],
[[0, 0], [-10, 20], [-999, -999], [35, 15], [0, 0]]]

fade8 = [
[[30,20],[-20,40],[40,60],[70,30]],
[[0, 0], [-10, 20], [20, 30], [0, 0]]]


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_basic(self):
    '''Test fade, 10 samples, fade_length of 4.'''

    snd = make_sound (fade6[0])
    sol = make_sound (fade6[1])
    student = a1.fade(snd, 4)
    self.assertEqual (student, sol)

  def test_fade_basic2(self):
    '''Test fade, 5 samples, fade_length of 2.'''

    snd = make_sound (fade7[0])
    sol = make_sound (fade7[1])
    student = a1.fade(snd, 2)
    self.assertEqual (student, sol)

  def test_fade_basic3(self):
    '''Test fade, 4 samples, fade_length of 2.'''

    snd = make_sound (fade8[0])
    sol = make_sound (fade8[1])
    student = a1.fade(snd, 2)
    self.assertEqual (student, sol)

if __name__ == '__main__':
    unittest.main()

