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

fade1 = [
[[20,40], [40,0], [-20,-40],[-40,0], [-40, 20]] + [[-999, -999]] * 5,
[[0, 0], [8, 0], [-8, -16], [-24, 0], [-32, 16]] + [[-999, -999]] * 5]

fade2 = [
[[20,40], [40,0], [-20,-40],[-40,0], [-40, 20]],
[[0, 0], [8, 0], [-8, -16], [-24, 0], [-32, 16]]]

fade3 = [
[[20,40], [40,0], [-20,-40],[-40,100]],
[[0, 0], [10, 0], [-10, -20], [-30, 75]]]

fade4 = [
[[20,0], [40,0], [-20,0],[-40,0], [30, 0]] + [[-999, -999]] * 5,	
[[0, 0], [8, 0], [-8, 0], [-24, 0], [24, 0]] + [[-999, -999]] * 5]

fade5 = [
[[0,20], [0,40], [0, -20],[0, -40], [0, 30]] + [[-999, -999]] * 5,
[[0, 0], [0, 8], [0, -8], [0, -24], [0, 24]] + [[-999, -999]] * 5]

def make_sound (lst):
  '''Make 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_basic(self):
    '''Test fading in over 5 of 10 samples.''' 

    snd = make_sound (fade1[0])
    sol = make_sound (fade1[1])
    student = a1.fade_in(snd, 5)
    self.assertEqual (student, sol)

  def test_fade_in_full_len(self):
    '''Test fading in over 5 of 5 samples.''' 

    snd = make_sound (fade2[0])
    sol = make_sound (fade2[1])
    student = a1.fade_in(snd, 5)
    self.assertEqual (student, sol)

  def test_fade_in_full_len2(self):
    '''Test fading in over 4 of 4 samples.''' 

    snd = make_sound (fade3[0])
    sol = make_sound (fade3[1])
    student = a1.fade_in(snd, 4)
    self.assertEqual (student, sol)

  def test_fade_in_left_only(self):
    '''Test fading in on left channel over 5 of 10 samples.''' 

    snd = make_sound (fade4[0])
    sol = make_sound (fade4[1])
    student = a1.fade_in(snd, 5)
    self.assertEqual (student, sol)

  def test_fade_in_right_only(self):
    '''Test fading in on right channel over 5 of 10 samples.''' 

    snd = make_sound (fade5[0])
    sol = make_sound (fade5[1])
    student = a1.fade_in(snd, 5)
    self.assertEqual (student, sol)

if __name__ == '__main__':
    unittest.main()

