Renamed methods 'copy' to 'clone'

This commit is contained in:
josdejong 2013-03-19 20:34:21 +01:00
parent 0c41367b6f
commit cf8cf46d63
11 changed files with 18 additions and 35 deletions

View File

@ -52,7 +52,7 @@ function add(x, y) {
throw new Error('Unit on right hand side of operator + has no value');
}
var res = x.copy();
var res = x.clone();
res.value += y.value;
res.fixPrefix = false;
return res;

View File

@ -33,7 +33,7 @@ function divide(x, y) {
if (x instanceof Unit) {
if (isNumber(y)) {
var res = x.copy();
var res = x.clone();
res.value /= y;
return res;
}

View File

@ -19,7 +19,7 @@ function multiply(x, y) {
return multiplyComplex(new Complex(x, 0), y);
}
else if (y instanceof Unit) {
res = y.copy();
res = y.clone();
res.value *= x;
return res;
}
@ -36,7 +36,7 @@ function multiply(x, y) {
}
else if (x instanceof Unit) {
if (isNumber(y)) {
res = x.copy();
res = x.clone();
res.value *= y;
return res;
}

View File

@ -50,7 +50,6 @@ function pow(x, y) {
if (y == 0) {
// return the identity matrix
// TODO: implement method eye
return eye(s[0]);
}
else {

View File

@ -52,7 +52,7 @@ function subtract(x, y) {
throw new Error('Unit on right hand side of operator - has no value');
}
var res = x.copy();
var res = x.clone();
res.value -= y.value;
res.fixPrefix = false;

View File

@ -18,7 +18,7 @@ function unaryminus(x) {
);
}
else if (x instanceof Unit) {
var res = x.copy();
var res = x.clone();
res.value = -x.value;
return res;
}

View File

@ -20,7 +20,7 @@ function unit_in(x, unit) {
throw new Error('Unit expected on the right hand side of function in');
}
var res = unit.copy();
var res = unit.clone();
res.value = x.value;
res.fixPrefix = true;

View File

@ -278,9 +278,9 @@ function isComplex(value) {
/**
* Create a copy of the complex value
* @return {Complex} copy
* @return {Complex} clone
*/
Complex.prototype.copy = function () {
Complex.prototype.clone = function () {
return new Complex(this.re, this.im);
};

View File

@ -249,9 +249,9 @@ function isUnit(value) {
/**
* create a copy of this unit
* @return {Unit} copy
* @return {Unit} clone
*/
Unit.prototype.copy = function () {
Unit.prototype.clone = function () {
var clone = new Unit();
for (var p in this) {

View File

@ -31,30 +31,14 @@
console.log('a = ' + workspace.getResult(id0));
console.log('a + 2 = ' + workspace.getResult(id1));
console.log();
console.log(new Unit('0.01m').toString());
console.log(new Unit('0.1m').toString());
console.log(new Unit('0.5m').toString());
console.log(new Unit('0.6m').toString());
console.log(new Unit('1m').toString());
console.log(new Unit('10m').toString());
console.log(new Unit('100m').toString());
console.log(new Unit('200m').toString());
console.log(new Unit('300m').toString());
console.log(new Unit('400m').toString());
console.log(new Unit('499m').toString());
console.log(new Unit('500m').toString());
console.log(new Unit('501m').toString());
console.log(new Unit('502m').toString());
console.log(new Unit('510m').toString());
console.log(new Unit('520m').toString());
console.log(new Unit('600m').toString());
console.log(new Unit('700m').toString());
console.log(new Unit('800m').toString());
console.log(new Unit('900m').toString());
console.log(new Unit('1000m').toString());
console.log(new Unit('1100m').toString());
console.log(new Unit('1200m').toString());
</script>
</body>

View File

@ -77,12 +77,12 @@ assert.equal(new Complex(1, 0).toString(), '1');
assert.equal(new Complex(-1, 2).toString(), '-1 + 2i');
assert.equal(new Complex(-1, 1).toString(), '-1 + i');
// test copy
var copy = complex1.copy();
copy.re = 100;
copy.im = 200;
assert.notEqual(complex1, copy);
// test clone
var clone = complex1.clone();
clone.re = 100;
clone.im = 200;
assert.notEqual(complex1, clone);
assert.equal(complex1.re, 3);
assert.equal(complex1.im, -4);
assert.equal(copy.re, 100);
assert.equal(copy.im, 200);
assert.equal(clone.re, 100);
assert.equal(clone.im, 200);