Skip to content

Commit

Permalink
(WIP): testing Math functions #96
Browse files Browse the repository at this point in the history
  • Loading branch information
201flaviosilva committed Dec 21, 2022
1 parent ba532a2 commit a52a066
Show file tree
Hide file tree
Showing 19 changed files with 110 additions and 130 deletions.
6 changes: 5 additions & 1 deletion lib/Vanilla/CHANGELOG.md
Expand Up @@ -11,16 +11,20 @@ This file was based on [this template](https://gist.github.com/juampynr/4c18214a
----
## [1.3 - Tests and monorepo](https://github.com/201flaviosilva-labs/javascript-utils/milestone/4)

### [1.3.0] - 00-11-2022
### [1.3.2] - 00-01-2023

#### Added

#### Changed

#### Fixed
- Fixed multiple function based on the tests;

#### Breaking Changes

#### Removed
- SortingAlgorithms - Moved sort function to the [play-code project](https://github.com/201flaviosilva-labs/play-code);


## [1.2.0 - More Functions](https://github.com/201flaviosilva-labs/javascript-utils/milestone/2)

Expand Down
1 change: 1 addition & 0 deletions lib/Vanilla/src/Maths/average.js
Expand Up @@ -9,6 +9,7 @@ import { sum } from "./sum.js";
* @example average(1,2,-5,2.4,-6.5,0.5); // -0.9333333333333332
* @example average(1,2,3,4,5,6,7,8,9); // 5
* @example average(-1,2,3,4,5,6,7,8,-9); // 2.7777777777777777
* @example average(...[1,2,3,4,5,6]); // 3.5
*
* @param {...number} numbers - the numbers to average
* @returns {number}
Expand Down
11 changes: 5 additions & 6 deletions lib/Vanilla/src/Maths/clamp.js
Expand Up @@ -3,12 +3,11 @@
* If the value is less than the minimum, returns the minimum.
* If not, return the passed value.
*
* @example
* clamp(-10, 0, 100); // 0
* clamp(0, 0, 100); // 0
* clamp(50, 0, 100); // 50
* clamp(100, 0, 100); // 100
* clamp(200, 0, 100); // 100
* @example clamp(-10, 0, 100); // 0
* @example clamp(0, 0, 100); // 0
* @example clamp(50, 0, 100); // 50
* @example clamp(100, 0, 100); // 100
* @example clamp(200, 0, 100); // 100
*
* @param {number} value - The value to check
* @param {number} [min=0] - Minimum value
Expand Down
8 changes: 4 additions & 4 deletions lib/Vanilla/src/Maths/degreesToRadians.js
@@ -1,9 +1,9 @@
/**
* Return the givens value in radians
*
* @example
* degreesToRadians(0) // 0
* degreesToRadians(90) // 1.5707963267948966
* degreesToRadians(500) // 8.726646259971648
* @example degreesToRadians(0) // 0
* @example degreesToRadians(90) // 1.5707963267948966
* @example degreesToRadians(500) // 8.726646259971648
*
* @param {number} d - the degrees value to convert in radians
* @returns {number} converted the given degrees in radian
Expand Down
5 changes: 3 additions & 2 deletions lib/Vanilla/src/Maths/divideEvenly.js
Expand Up @@ -23,11 +23,12 @@ export function divideEvenly(min = 0, max = 10, numberDivisions = 5) {
}

/**
* Returns a array of numbers with the spaced divisions. The division starts on 0
*
* @example divideEvenlyWithSpread(10, 5); // [-5, -3.888888888888889, -2.7777777777777777, -1.6666666666666665, -0.5555555555555554, 0.5555555555555554, 1.666666666666667, 2.7777777777777777, 3.8888888888888893, 5]
*
* @param {number} numberDivisions
* @param {number} spread
* @param {number} [numberDivisions=3] - number of number to divide
* @param {number} [spread=5] - space between 0 and the last number
* @returns {number[]} An array of evenly spaced numbers.
*/
export function divideEvenlyWithSpread(numberDivisions = 3, spread = 5) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Vanilla/src/Maths/index.js
@@ -1,7 +1,7 @@
import { average } from "./average.js";
import { clamp } from "./clamp.js";
import { degreesToRadians } from "./degreesToRadians.js";
import { divideEvenly } from "./divideEvenly.js";
import { divideEvenly, divideEvenlyWithSpread } from "./divideEvenly.js";
import { division } from "./division.js";
import { factorial } from "./factorial.js";
import { getPositionWithAngleDistance } from "./getPositionWithAngleDistance.js";
Expand Down Expand Up @@ -31,7 +31,7 @@ export {
average,
clamp,
degreesToRadians,
divideEvenly,
divideEvenly, divideEvenlyWithSpread,
division,
factorial,
getPositionWithAngleDistance,
Expand Down
19 changes: 0 additions & 19 deletions lib/Vanilla/src/SortingAlgorithms/bogoSort.js

This file was deleted.

22 changes: 0 additions & 22 deletions lib/Vanilla/src/SortingAlgorithms/bubbleSort.js

This file was deleted.

19 changes: 0 additions & 19 deletions lib/Vanilla/src/SortingAlgorithms/index.js

This file was deleted.

24 changes: 0 additions & 24 deletions lib/Vanilla/src/SortingAlgorithms/insertionSort.js

This file was deleted.

29 changes: 0 additions & 29 deletions lib/Vanilla/src/SortingAlgorithms/selectionSort.js

This file was deleted.

2 changes: 0 additions & 2 deletions lib/Vanilla/src/index.js
@@ -1,7 +1,6 @@
import * as Arrays from "./Arrays/index.js";
import * as Maths from "./Maths/index.js";
import * as Physics from "./Physics/index.js";
import * as SortingAlgorithms from "./SortingAlgorithms/index.js";

import { allCharactersSame } from "./allCharactersSame.js";
import { binary2Decimal } from "./binary2Decimal.js";
Expand All @@ -28,7 +27,6 @@ export {
Arrays,
Maths,
Physics,
SortingAlgorithms,

BinarySearchTree, BinarySearchTreeInstance,
EventSystem, EventSystemInstance,
Expand Down
16 changes: 16 additions & 0 deletions lib/Vanilla/tests/Math/average.test.js
@@ -0,0 +1,16 @@
import { Maths } from "../../src/index.js";
const { average } = Maths;

describe("Maths/average.js", () => {
it("should return the average", () => {
expect(average()).toBe(0);
expect(average(...[0, 0, 0, 0])).toBe(0);
expect(average(1)).toBe(1);
expect(average(1, 2)).toBe(1.5);
expect(average(5, 4, 3, 6, 7, 3, 1, 8)).toBe(4.625);
expect(average(1, 2, -5, 2.4, -6.5, 0.5)).toBe(-0.9333333333333332);
expect(average(1, 2, 3, 4, 5, 6, 7, 8, 9)).toBe(5);
expect(average(-1, 2, 3, 4, 5, 6, 7, 8, -9)).toBe(2.7777777777777777);
expect(average(...[1, 2, 3, 4, 5, 6])).toBe(3.5);
});
});
12 changes: 12 additions & 0 deletions lib/Vanilla/tests/Math/clamp.test.js
@@ -0,0 +1,12 @@
import { Maths } from "../../src/index.js";
const { clamp } = Maths;

describe("Maths/clamp.js", () => {
it("should return the value between the limits", () => {
expect(clamp(-10, 0, 100)).toBe(0);
expect(clamp(0, 0, 100)).toBe(0);
expect(clamp(50, 0, 100)).toBe(50);
expect(clamp(100, 0, 100)).toBe(100);
expect(clamp(200, 0, 100)).toBe(100);
});
});
10 changes: 10 additions & 0 deletions lib/Vanilla/tests/Math/degreesToRadians.test.js
@@ -0,0 +1,10 @@
import { Maths } from "../../src/index.js";
const { degreesToRadians } = Maths;

describe("Maths/degreesToRadians.js", () => {
it("should return the value in radians", () => {
expect(degreesToRadians(0)).toBe(0);
expect(degreesToRadians(90)).toBe(1.5707963267948966);
expect(degreesToRadians(500)).toBe(8.726646259971648);
});
});
18 changes: 18 additions & 0 deletions lib/Vanilla/tests/Math/divideEvenly.test.js
@@ -0,0 +1,18 @@
import { Maths } from "../../src/index.js";
const { divideEvenly, divideEvenlyWithSpread, } = Maths;

describe("Maths/divideEvenly.js", () => {
describe("divideEvenly", () => {
it("should return the a array with a values with the same space between all", () => {
expect(divideEvenly()).toEqual([0, 2.5, 5, 7.5, 10]);
expect(divideEvenly(0, 10, 2)).toEqual([0, 10]);
expect(divideEvenly(-45, 45, 3)).toEqual([-45, 0, 45]);
});
});

describe("divideEvenlyWithSpread", () => {
it("---", () => {
expect(divideEvenlyWithSpread(10, 5)).toEqual([-5, -3.888888888888889, -2.7777777777777777, -1.6666666666666665, -0.5555555555555554, 0.5555555555555554, 1.666666666666667, 2.7777777777777777, 3.8888888888888893, 5]);
});
});
});
13 changes: 13 additions & 0 deletions lib/Vanilla/tests/Math/division.test.js
@@ -0,0 +1,13 @@
import { Maths } from "../../src/index.js";
const { division } = Maths;

describe("Maths/division.js", () => {
it("should return the division of all given numbers", () => {
expect(division()).toBe(0);
expect(division(1)).toBe(1);
expect(division(1, 2)).toBe(0.5);
expect(division(1000, 10)).toBe(100);
expect(division(20, 10, 5)).toBe(0.4);
expect(division(...[1, 2, -5, 2.4, -6.5, 0.5])).toBe(0.012820512820512822);
});
});
13 changes: 13 additions & 0 deletions lib/Vanilla/tests/Math/factorial.test.js
@@ -0,0 +1,13 @@
import { Maths } from "../../src/index.js";
const { factorial } = Maths;

describe("Maths/factorial.js", () => {
it("should return the factorial", () => {
expect(factorial(0)).toBe(0);
expect(factorial(1)).toBe(1);
expect(factorial(1.2)).toBe(0.23999999999999994);
expect(factorial(4)).toBe(24);
expect(factorial(6)).toBe(720);
expect(factorial(10)).toBe(3628800);
});
});
8 changes: 8 additions & 0 deletions lib/Vanilla/tests/Math/getPositionWithAngleDistance.test.js
@@ -0,0 +1,8 @@
import { Maths } from "../../src/index.js";
const { getPositionWithAngleDistance } = Maths;

describe("Maths/getPositionWithAngleDistance.js", () => {
it("should return a position based in the given angle, distance, and origin", () => {
expect(getPositionWithAngleDistance(10, 100)).toEqual({ x: -83.90715290764524, y: -54.40211108893698 });
});
});

0 comments on commit a52a066

Please sign in to comment.