Skip to content

Commit

Permalink
Fix the TeoriaInterval#octaves() method
Browse files Browse the repository at this point in the history
  • Loading branch information
saebekassebil committed Jan 26, 2014
1 parent dd8e383 commit 87b5f42
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/interval.js
Expand Up @@ -68,8 +68,15 @@ TeoriaInterval.prototype = {
},

octaves: function() {
var without = sub(this.coord, mul(sharp, this.qualityValue()));
var octaves = without[0] - intervals[this.base()][0];
var without, octaves;

if (this.direction() === 'up') {
without = sub(this.coord, mul(sharp, this.qualityValue()));
octaves = without[0] - intervals[this.base()][0];
} else {
without = sub(this.coord, mul(sharp, -this.qualityValue()));
octaves = -(without[0] + intervals[this.base()][0]);
}

return octaves;
},
Expand Down
16 changes: 16 additions & 0 deletions test/intervals.js
Expand Up @@ -322,6 +322,22 @@ vows.describe('Intervals').addBatch({
assert.equal(teoria.interval('P22').octaves(), 2);
},

'A descending fourth has no compound octaves': function() {
assert.equal(teoria.interval('P-4').octaves(), 0);
},

'A descending eleventh has one compound octave': function() {
assert.equal(teoria.interval('P-11').octaves(), 1);
},

'A descending augmented third has no compound octaves': function() {
assert.equal(teoria.interval('A-3').octaves(), 0);
},

'A descending major 16th has two compound octaves': function() {
assert.equal(teoria.interval('M-16').octaves(), 2);
},

'A major seventh is greater than a minor seventh': function() {
assert.equal(teoria.interval('M7').greater(teoria.interval('m7')), true);
},
Expand Down

0 comments on commit 87b5f42

Please sign in to comment.