Closed LarryBattle closed 11 years ago
Added setter and getter for the numerator and denominator. Also change this.numerator to this.n and this.denominator to this.d. This should also includes the parameter names. top-> n and bottom -> d
this.numerator
this.n
this.denominator
this.d
top
n
bottom
d
Ratio.js
numerator : function(val){ if(val != null){ this.n = Ratio.getNumeratorWithSign(val, this.d); } return this.n; }, denominator : function(val){ if(val != null){ this.n *= (0 < +val) ? 1 : -1; this.d = Math.abs(val); } return this.d; },
Test cases
test("test Ratio.prototype.numerator()", function () { var fn = function(a,b,c){ var obj = new Ratio(a,b); obj.numerator(c); return obj; }; equal(fn(1,2,2).toString(), "2/2"); }); test("test changing denominator", function () { var fn = function(a,b,c){ var obj = new Ratio(a,b); obj.denominator(c); return obj; }; equal(fn(1,3,2).toString(), "1/2"); equal(fn(-1,3,-2).toString(), "1/2"); equal(fn(1,3,-2).toString(), "-1/2"); equal(fn(-1,3,2).toString(), "-1/2"); });
Added in Version 0.4
Added setter and getter for the numerator and denominator. Also change
this.numerator
tothis.n
andthis.denominator
tothis.d
. This should also includes the parameter names.top
->n
andbottom
->d
Ratio.js
Test cases