Skip to content

Commit

Permalink
updated spread functions naming
Browse files Browse the repository at this point in the history
  • Loading branch information
tmhglnd committed Nov 13, 2021
1 parent 41d4446 commit 7ed1d9f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 66 deletions.
6 changes: 6 additions & 0 deletions docs/generative-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
63 changes: 34 additions & 29 deletions src/gen-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -70,26 +81,17 @@ 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
//
// @params {length, low-output, high-output, exponent}
// @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;
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -148,30 +162,21 @@ 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
//
// @params {length, low-output, high-output, exponent}
// @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 <value, amount>
Expand Down
68 changes: 31 additions & 37 deletions test/serialism.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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(){
Expand Down

0 comments on commit 7ed1d9f

Please sign in to comment.