From 7ed1d9f3c04d453591b131647457599f853d0dd2 Mon Sep 17 00:00:00 2001 From: tmhglnd Date: Sat, 13 Nov 2021 20:25:51 +0100 Subject: [PATCH] updated spread functions naming --- docs/generative-methods.md | 6 ++++ src/gen-basic.js | 63 +++++++++++++++++++---------------- test/serialism.test.js | 68 +++++++++++++++++--------------------- 3 files changed, 71 insertions(+), 66 deletions(-) diff --git a/docs/generative-methods.md b/docs/generative-methods.md index 3980ca52..b27faf63 100644 --- a/docs/generative-methods.md +++ b/docs/generative-methods.md @@ -105,6 +105,9 @@ Gen.spreadExp(10, 0, 10, 2); // 0, 0, 0, 0, 1, // 2, 3, 4, 6, 8 // ] + +Gen.spreadExpFloat(); +// Alternative: Gen.spreadExpF() ``` ## spreadInclusiveExp @@ -123,6 +126,9 @@ Gen.spreadInclusiveExp(10, 0, 10, 2); // 0, 0, 0, 1, 1, // 3, 4, 6, 7, 10 // ] + +Gen.spreadInclusiveExpFloat(); +// Alternative: Gen.spreadIncExpF() ``` ## fill diff --git a/src/gen-basic.js b/src/gen-basic.js index d5e71b5d..0e3af294 100644 --- a/src/gen-basic.js +++ b/src/gen-basic.js @@ -45,6 +45,17 @@ function spreadFloat(len=1, lo=1, hi){ exports.spreadFloat = spreadFloat; exports.spreadF = spreadFloat; +// Spread function rounded to integers +// +// @params {length, low-output, high-output} +// @return {Array} +// +function spread(len, lo=len, hi){ + let arr = spreadFloat(len, lo, hi); + return arr.map(v => Math.floor(Number(v.toPrecision(15)))); +} +exports.spread = spread; + // Generate a list of n-length starting at one value // up until (but excluding) the 3th argument. // Set an exponential curve in the spacing of the values. @@ -53,7 +64,7 @@ exports.spreadF = spreadFloat; // @params {length, low-output, high-output, exponent} // @return {Array} // -function spreadFloatExp(len=1, lo=1, hi, exp=1){ +function spreadExpFloat(len=1, lo=1, hi, exp=1){ // if hi undefined set lo to 0 and hi=lo if (hi === undefined){ var t=lo, lo=0, hi=t; } // calculate the range @@ -70,18 +81,9 @@ function spreadFloatExp(len=1, lo=1, hi, exp=1){ } return (r < 0)? arr.reverse() : arr; } -exports.spreadFloatExp = spreadFloatExp; - -// Spread function rounded to integers -// -// @params {length, low-output, high-output} -// @return {Array} -// -function spread(len, lo=len, hi){ - let arr = spreadFloat(len, lo, hi); - return arr.map(v => Math.floor(Number(v.toPrecision(15)))); -} -exports.spread = spread; +exports.spreadFloatExp = spreadExpFloat; // deprecated +exports.spreadExpFloat = spreadExpFloat; +exports.spreadExpF = spreadExpFloat; // Spread function floored to integers // @@ -89,7 +91,7 @@ exports.spread = spread; // @return {Array} // function spreadExp(len, lo=len, hi, exp){ - let arr = spreadFloatExp(len, lo, hi, exp); + let arr = spreadExpFloat(len, lo, hi, exp); return arr.map(v => Math.floor(Number(v.toPrecision(15)))); } exports.spreadExp = spreadExp; @@ -124,6 +126,18 @@ function spreadInclusiveFloat(len=1, lo=1, hi){ exports.spreadInclusiveFloat = spreadInclusiveFloat; exports.spreadIncF = spreadInclusiveFloat; +// spreadinclusiveFloat function floored to integers +// +// @params {length, low-output, high-output} +// @return {Array} +// +function spreadInclusive(len, lo=len, hi){ + var arr = spreadInclusiveFloat(len, lo, hi); + return arr.map(v => Math.floor(Number(v.toPrecision(15)))); +} +exports.spreadInclusive = spreadInclusive; +exports.spreadInc = spreadInclusive; + // Generate a list of n-length starting at one value // ending at the 3th argument. // Set an exponential curve in the spacing of the values. @@ -132,7 +146,7 @@ exports.spreadIncF = spreadInclusiveFloat; // @params {length, low-output, high-output, exponent} // @return {Array} // -function spreadInclusiveFloatExp(len=1, lo=1, hi, exp=1){ +function spreadInclusiveExpFloat(len=1, lo=1, hi, exp=1){ // if hi undefined set lo to 0 and hi=lo if (hi === undefined){ var t=lo, lo=0, hi=t; } // calculate the range @@ -148,19 +162,9 @@ function spreadInclusiveFloatExp(len=1, lo=1, hi, exp=1){ } return (r < 0)? arr.reverse() : arr; } -exports.spreadInclusiveFloatExp = spreadInclusiveFloatExp; - -// spreadinclusiveFloat function floored to integers -// -// @params {length, low-output, high-output} -// @return {Array} -// -function spreadInclusive(len, lo=len, hi){ - var arr = spreadInclusiveFloat(len, lo, hi); - return arr.map(v => Math.floor(Number(v.toPrecision(15)))); -} -exports.spreadInclusive = spreadInclusive; -exports.spreadInc = spreadInclusive; +exports.spreadInclusiveFloatExp = spreadInclusiveExpFloat; //deprecated +exports.spreadInclusiveExpFloat = spreadInclusiveExpFloat; +exports.spreadIncExpF = spreadInclusiveExpFloat; // spreadinclusiveFloatExp function floored to integers // @@ -168,10 +172,11 @@ exports.spreadInc = spreadInclusive; // @return {Array} // function spreadInclusiveExp(len, lo=len, hi, exp){ - var arr = spreadInclusiveFloatExp(len, lo, hi, exp); + var arr = spreadInclusiveExpFloat(len, lo, hi, exp); return arr.map(v => Math.floor(Number(v.toPrecision(15)))); } exports.spreadInclusiveExp = spreadInclusiveExp; +exports.spreadIncExp = spreadInclusiveExp; // fill an array with values. Arguments are pairs. // Every pair consists of diff --git a/test/serialism.test.js b/test/serialism.test.js index 17fc4d73..14b2b76a 100644 --- a/test/serialism.test.js +++ b/test/serialism.test.js @@ -59,24 +59,19 @@ console.log(); // markov.clear(); // console.log(markov.table); -// fullTest(); - -console.log(Util.div([[1, 11, 111], 2, 3], [2, 10])); -console.log(Util.div([1, [2, [3, 5]], 4], [10, [20, 30]])) -console.log(Util.div([1, 2, [3, [4, 5]]], [10, [[20, 100], 30]])); -console.log(Util.div(10, [1, 2, 3, 4])); +fullTest(); function fullTest(){ console.time('Total Time'); // testSerial(); - // testGen(); + testGen(); // testAlgo(); // testRand(); // testMod(); // testStat(); // testTranslate(); - testUtil(); + // testUtil(); pagebreak("All Tests Passed"); console.timeEnd('Total Time'); @@ -104,49 +99,48 @@ function testGen(){ pagebreak("Generative"); test("Gen.spread()"); - test("Gen.spreadFloat()"); - test("Gen.spreadInclusive()"); - test("Gen.spreadInclusiveFloat()"); + test("Gen.spread(6)"); + test("Gen.spread(6, 12)"); + test("Gen.spread(6, -3, 12)"); + test("Gen.spread(6, -12, 3)"); - test("Gen.spread(5)"); - test("Gen.spread(5, 12)"); - test("Gen.spread(5, 3, 12)"); - test("Gen.spread(5, 12, 3)"); - - test("Gen.spreadInclusive(5)"); - test("Gen.spreadInclusive(5, 12)"); - test("Gen.spreadInclusive(5, 3, 12)"); - test("Gen.spreadInclusive(5, 12, 3)"); - + test("Gen.spreadFloat()"); test("Gen.spreadFloat(4)"); test("Gen.spreadFloat(4, 2)"); test("Gen.spreadFloat(4, -1, 1)"); - test("Gen.spreadInclusiveFloat(5)"); - test("Gen.spreadInclusiveFloat(5, 2)"); - test("Gen.spreadInclusiveFloat(5, -1, 1)"); + test("Gen.spreadInc()"); + test("Gen.spreadInc(6)"); + test("Gen.spreadInc(6, 12)"); + test("Gen.spreadInc(6, -3, 12)"); + test("Gen.spreadInc(6, -12, 3)"); + + test("Gen.spreadIncF()"); + test("Gen.spreadIncF(5)"); + test("Gen.spreadIncF(5, 2)"); + test("Gen.spreadIncF(5, -1, 1)"); test("Gen.spreadExp(10, 0, 10, 2)"); - test("Gen.spreadInclusiveExp(10, 0, 10, 2)"); - test("Gen.spreadFloatExp(12, 0, 10, 0.5)"); - test("Gen.spreadInclusiveFloatExp(12, 0, 10, 0.5)"); + test("Gen.spreadIncExp(10, 0, 10, 2)"); + test("Gen.spreadExpF(12, 0, 10, 0.5)"); + test("Gen.spreadIncExpF(12, 0, 10, 0.5)"); - // test("Gen.fill()"); - test("Gen.fill(10, 2, 15, 3, 20, 4)"); - test("Gen.fill([10, 20], 2, 15, 3, 20, 4)"); - test("Gen.fill([10, 20, 2, 15, 3, 20, 4])"); + // // test("Gen.fill()"); + // test("Gen.fill(10, 2, 15, 3, 20, 4)"); + // test("Gen.fill([10, 20], 2, 15, 3, 20, 4)"); + // test("Gen.fill([10, 20, 2, 15, 3, 20, 4])"); - test("Util.plot(Gen.cosineFloat(16), {log: false, height: 5, data: true})"); + // test("Util.plot(Gen.cosineFloat(16), {log: false, height: 5, data: true})"); - test("Util.plot(Gen.sine(10), {log: false})"); - test("Util.plot(Gen.cosine(7, 1.5), {log: false})"); + // test("Util.plot(Gen.sine(10), {log: false})"); + // test("Util.plot(Gen.cosine(7, 1.5), {log: false})"); - test("Util.plot(Gen.sineFloat(40, Gen.sineFloat(40, 4, 1, 5)), {log: false, height: 10})"); + // test("Util.plot(Gen.sineFloat(40, Gen.sineFloat(40, 4, 1, 5)), {log: false, height: 10})"); - test("Util.plot(Gen.saw(16, 8.5), {log: false})"); + // test("Util.plot(Gen.saw(16, 8.5), {log: false})"); - test("Util.plot(Gen.sawFloat(25, 2.5), {log: false, height: 5, data: true})"); + // test("Util.plot(Gen.sawFloat(25, 2.5), {log: false, height: 5, data: true})"); } function testAlgo(){