# This file contains one final test for each function that uses calculations
# that should have intermediate values that are not even integers. It tests
# if the submission correctly uses int() and not round() or integer division.

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

rem_vocals_float = [
[[0,-3],[-4,-6],[-5, 10],[10,1]],
[[1, 1], [1, 1], [-7, -7], [4, 4]]]

fade_in_float = [
[[-18,-18],[21, 25],[-20,-20],[0,0],[18,18]] + [[-999,-999]] * 5,
[[0, 0], [4, 5], [-8, -8], [0, 0], [14, 14]] + [[-999,-999]] * 5]

fade_out_float = [
[[-18,-18],[21, 25],[-20,-20],[0,0],[18,18]] + [[-999,-999]] * 5,
[[-18, -18], [21, 25], [-20, -20], [0, 0], [18, 18], [-799, -799], [-599, -599],
[-399, -399], [-199, -199], [0, 0]]]

fade_float = [
[[26,21],[-23,39],[-999,-999],[70,30],[-90,20]],
[[0, 0], [-11, 19], [-999, -999], [35, 15], [0, 0]]]

lr_float = [
[[29,17],[-19,38],[36,59],[71,30],[-90,24]] + [[-999, -999]] * 5,
[[23, 0], [-11, 7], [14, 23], [14, 18], [0, 19]] + [[-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_rem_vocals_float(self):
    '''Test rem_vocals on a sound with floating point intermediate values.'''

    snd = make_sound (rem_vocals_float[0])
    sol = make_sound (rem_vocals_float[1])
    student = a1.rem_vocals (snd)
    self.assertEqual (student, sol)    

  def test_fade_in_float(self):
    '''Test fade_in on a sound with floating point intermediate values.'''

    snd = make_sound (fade_in_float[0])
    sol = make_sound (fade_in_float[1])
    student = a1.fade_in(snd, 5)
    self.assertEqual (student, sol)

  def test_fade_out_float(self):
    '''Test fade_out on a sound with floating point intermediate values.'''

    snd = make_sound (fade_out_float[0])
    sol = make_sound (fade_out_float[1])
    student = a1.fade_out(snd, 5)
    self.assertEqual (student, sol)

  def test_fade_float(self):
    '''Test fade on a sound with floating point intermediate values.'''

    snd = make_sound (fade_float[0])
    sol = make_sound (fade_float[1])
    student = a1.fade(snd, 2)
    self.assertEqual (student, sol)

  def test_lr_float(self):
    '''Test left_right on a sound with floating point intermediate values.'''

    snd = make_sound (lr_float[0])
    sol = make_sound (lr_float[1])
    student = a1.left_to_right(snd, 5)
    self.assertEqual (student, sol)


if __name__ == '__main__':
    unittest.main()
