From cf8cf46d63dc7f8ffd710a79733c09d4e2a63f32 Mon Sep 17 00:00:00 2001 From: josdejong Date: Tue, 19 Mar 2013 20:34:21 +0100 Subject: [PATCH] Renamed methods 'copy' to 'clone' --- src/function/arithmetic/add.js | 2 +- src/function/arithmetic/divide.js | 2 +- src/function/arithmetic/multiply.js | 4 ++-- src/function/arithmetic/pow.js | 1 - src/function/arithmetic/subtract.js | 2 +- src/function/arithmetic/unaryminus.js | 2 +- src/function/units/in.js | 2 +- src/type/Complex.js | 4 ++-- src/type/Unit.js | 4 ++-- test/test.html | 16 ---------------- test/type/complex.js | 14 +++++++------- 11 files changed, 18 insertions(+), 35 deletions(-) diff --git a/src/function/arithmetic/add.js b/src/function/arithmetic/add.js index f49ae0671..b551c3277 100644 --- a/src/function/arithmetic/add.js +++ b/src/function/arithmetic/add.js @@ -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; diff --git a/src/function/arithmetic/divide.js b/src/function/arithmetic/divide.js index e23d96fd7..faa6d886d 100644 --- a/src/function/arithmetic/divide.js +++ b/src/function/arithmetic/divide.js @@ -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; } diff --git a/src/function/arithmetic/multiply.js b/src/function/arithmetic/multiply.js index 69ab356d0..72d090ff4 100644 --- a/src/function/arithmetic/multiply.js +++ b/src/function/arithmetic/multiply.js @@ -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; } diff --git a/src/function/arithmetic/pow.js b/src/function/arithmetic/pow.js index 79d98fdd3..f06b70e37 100644 --- a/src/function/arithmetic/pow.js +++ b/src/function/arithmetic/pow.js @@ -50,7 +50,6 @@ function pow(x, y) { if (y == 0) { // return the identity matrix - // TODO: implement method eye return eye(s[0]); } else { diff --git a/src/function/arithmetic/subtract.js b/src/function/arithmetic/subtract.js index f58750724..319793408 100644 --- a/src/function/arithmetic/subtract.js +++ b/src/function/arithmetic/subtract.js @@ -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; diff --git a/src/function/arithmetic/unaryminus.js b/src/function/arithmetic/unaryminus.js index d4b0f6685..7e171e932 100644 --- a/src/function/arithmetic/unaryminus.js +++ b/src/function/arithmetic/unaryminus.js @@ -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; } diff --git a/src/function/units/in.js b/src/function/units/in.js index 51bb03889..e9ed0020b 100644 --- a/src/function/units/in.js +++ b/src/function/units/in.js @@ -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; diff --git a/src/type/Complex.js b/src/type/Complex.js index bb1e4ef8a..f5300eb7d 100644 --- a/src/type/Complex.js +++ b/src/type/Complex.js @@ -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); }; diff --git a/src/type/Unit.js b/src/type/Unit.js index 47d8d8e62..4b4fa7868 100644 --- a/src/type/Unit.js +++ b/src/type/Unit.js @@ -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) { diff --git a/test/test.html b/test/test.html index e7f952a47..69cfa61be 100644 --- a/test/test.html +++ b/test/test.html @@ -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()); diff --git a/test/type/complex.js b/test/type/complex.js index 6e1de66a6..5e773edd6 100644 --- a/test/type/complex.js +++ b/test/type/complex.js @@ -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);