import a1
import sound
import unittest

#For each of these examples, element 0 is the list used to generate the
#input sample and element 1 is the list used to generate the expected output


lr1 = [
[[30,20],[-20,40],[40,60],[70,30],[-90,20]] + [[-999, -999]] * 5,
[[24, 0], [-12, 8], [16, 24], [14, 18], [0, 16]] + [[-999, -999]] * 5]

lr2 = [
[[30,20],[-20,40],[40,60],[70,30],[-90,20]],
[[24, 0], [-12, 8], [16, 24], [14, 18], [0, 16]]]

lr3 = [
[[32,20],[-20,40],[40,60],[72,32]],
[[24, 0], [-10, 10], [10, 30], [0, 24]]]

lr4 = [
[[30,0],[-20,0],[40,0],[70,0],[-90,0]] + [[-999, -999]] * 5,
[[24, 0], [-12, 0], [16, 0], [14, 0], [0, 0]] + [[-999, -999]] * 5]

lr5 = [
[[0,20],[0,40],[0,60],[0,30],[0,20]] + [[-999, -999]] * 5,
[[0, 0], [0, 8], [0, 24], [0, 18], [0, 16]] + [[-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_lr_basic(self):
    '''Test left_to_right over 5 of 10 samples.'''

    snd = make_sound (lr1[0])
    sol = make_sound (lr1[1])
    student = a1.left_to_right(snd, 5)
    self.assertEqual (student, sol)

  def test_lr_full(self):
    '''Test left_to_right over 5 of 5 samples.'''

    snd = make_sound (lr2[0])
    sol = make_sound (lr2[1])
    student = a1.left_to_right(snd, 5)
    self.assertEqual (student, sol)

  def test_lr_full2(self):
    '''Test left_to_right over 4 of 4 samples.'''

    snd = make_sound (lr3[0])
    sol = make_sound (lr3[1])
    student = a1.left_to_right(snd, 4)
    self.assertEqual (student, sol)

  def test_lr_left(self):
    '''Test left_to_right on the left channel only over 5 of 10.'''

    snd = make_sound (lr4[0])
    sol = make_sound (lr4[1])
    student = a1.left_to_right(snd, 5)
    self.assertEqual (student, sol)

  def test_lr_right(self):
    '''Test left_to_right on the right channel only over 5 of 10.'''

    snd = make_sound (lr5[0])
    sol = make_sound (lr5[1])
    student = a1.left_to_right(snd, 5)
    self.assertEqual (student, sol)

if __name__ == '__main__':
    unittest.main()

