var assert = chai.assert;

window.AudioContext = window.AudioContext||window.webkitAudioContext;


// Here we create a buffer to be used later with our player
var audioContext = new AudioContext();
var targetNode = audioContext.destination;

// Returns a random integer between min and max
function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

describe("BinauralFIR tests", function() {

  this.buffer = audioContext.createBuffer(1, 512, 44100);
  this.data = this.buffer.getChannelData(0);
  for (var i = 0; i < this.data.length; i++) {
    this.data[i] = (Math.random() - 0.5) * 2;
  }

  var numberOfPositions = getRandomInt(100,200);
  this.hrtfs = [];
  for (var i = 0; i < numberOfPositions; i++){
    var url = 'fakeURL.wav';
    var obj = {
      azimuth: getRandomInt(0,90),
      elevation: getRandomInt(0,90),
      distance: getRandomInt(1,3),
      url: url,
      buffer: this.buffer
    };
    this.hrtfs.push(obj);
  }

  var self = this;
  self.binauralFIR = createBinauralFIR();
  self.binauralFIR.connect(targetNode);

  it('should set HRTF DataSet correctly', function(){
    self.binauralFIR.HRTFDataset = self.hrtfs;
    assert.equal(self.binauralFIR.HRTFDataset, self.hrtfs);
  });

  // it('should set position correctly', function(){
  //   self.binauralFIR.setPosition(10, 20, 30);
  //   assert.equal(self.binauralFIR.getPosition()[0], 10);
  //   assert.equal(self.binauralFIR.getPosition()[1], 20);
  //   assert.equal(self.binauralFIR.getPosition()[2], 30);
  // });

  it('should set crossfade duration correctly', function(){
    self.binauralFIR.setCrossfadeDuration(30);
    assert.equal(self.binauralFIR.getCrossfadeDuration(), 30);
  });

  it('should detect that is crossfading', function(){
    self.binauralFIR.setPosition(0, 0, 1);
    assert.equal(self.binauralFIR.isCrossfading(), true);
  });

});

@@ -1243,19 +1243,16 @@
   %7D);%0A%0A 
- //
  it('sho
@@ -1259,30 +1259,34 @@
 uld 
-set position correctly
+detect that is crossfading
 ', f
@@ -1297,19 +1297,16 @@
 ion()%7B%0A 
- //
    self.
@@ -1333,25 +1333,19 @@
 ion(
-1
 0, 
-2
 0, 
-30
+1
 );%0A 
- //
    a
@@ -1377,51 +1377,93 @@
 FIR.
-getPosition()%5B0%5D, 10);%0A  //   assert.equal(
+isCrossfading(), true);%0A  %7D);%0A%0A  it('should set position correctly', function()%7B%0A    
 self
@@ -1467,33 +1467,33 @@
 elf.binauralFIR.
-g
+s
 etPosition()%5B1%5D,
@@ -1491,153 +1491,176 @@
 ion(
-)%5B1%5D, 20);%0A  //   assert.equal(self.binauralFIR.getPosition()%5B2%5D, 30);%0A  // %7D);%0A%0A  it('should set crossfade duration correctly', function()%7B%0A    
+10, 20, 30);%0A    var coord = self.binauralFIR.getRealCoordinates(10, 20, 30);%0A    assert.equal(self.binauralFIR.getPosition().azimuth, coord.azimuth);%0A    assert.equal(
 self
@@ -1676,31 +1676,48 @@
 FIR.
-setCrossfadeDur
+getPosition().elevation, coord.elev
 ation
-(30
 );%0A 
@@ -1756,31 +1756,43 @@
 .get
-CrossfadeDuration(), 30
+Position().distance, coord.distance
 );%0A 
@@ -1814,34 +1814,40 @@
 uld 
-detect that is crossfading
+set crossfade duration correctly
 ', f
@@ -1881,32 +1881,36 @@
 lFIR.set
-Position(0, 0, 1
+CrossfadeDuration(30
 );%0A    a
@@ -1934,34 +1934,35 @@
 binauralFIR.
-is
+get
 Crossfad
 ing(), true)
@@ -1945,35 +1945,39 @@
 .getCrossfad
-ing(), true
+eDuration(), 30
 );%0A  %7D);%0A%0A%7D)

test updated