Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more math functions #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' into master
  • Loading branch information
shiffman authored Oct 1, 2018
commit 74a6d81cd0eb64b83c3403bae965b646d75272ea
8 changes: 7 additions & 1 deletion sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ function inDist(p1, p2, d){
return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y) + (p1.z - p2.z) * (p1.z - p2.z) < d * d;
}

function nOfFibonacci(x) {
let n = parseInt(x, 10);
return (!n || n < 1) ? -1 : (n < 3 ? 1 : (nOfFibonacci(n-1) + nOfFibonacci(n-2)));
}

module.exports = {
sum: sum,
sub: sub,
Expand All @@ -79,5 +84,6 @@ module.exports = {
randInt: randInt,
factorize: factorize,
Point3D: Point3D,
inDist: inDist
inDist: inDist,
nOfFibonacci: nOfFibonacci
}
32 changes: 32 additions & 0 deletions sketch.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const { sum, sub, prod, digital_root, sum42, sayHelloTo, anomalyCode, setArray, randInt, factorize, Point3D, inDist } = require('./sketch');
const { sum, sub, prod, digital_root, sum42, sayHelloTo, anomalyCode, nOfFibonacci } = require('./sketch');
const fs = require("fs");
const path = require("path");
const fetch = require("node-fetch");

// test('adds 1 + 2 to equal 3', () => {
// expect(sum(1, 2)).toBe(3);
Expand Down Expand Up @@ -114,3 +118,31 @@ test('intDist point (0, 0, 0) and (1, 1, 1) are within distance of 2', () => {
expect(inDist(new Point3D(0, 0, 0), new Point3D(1, 1, 1), 2)).toBe(true);
});

test('the 20th number of fibonacci should be 6765', () => {
expect(nOfFibonacci(20)).toBe(6765);
})

const testUrlInMarkdown = (file) => {
let markdown = fs.readFileSync(file).toString();
let urls = [];
let regExp = /\[([^\]]+)\]\(([^)]+)\)/g;
let result = null;
while (result = regExp.exec(markdown)) urls.push(result[2]);
return [urls.length, async () => {
for (let url of urls) {
if (url.includes("://") && !url.split("://")[0].includes("/")) {
// An External url
let res = await fetch(url);
if (![200, 301, 302].includes(res.status)) throw new Error(`External Link Test: ${url} with bad response code ${res.status}`);
} else {
if (!fs.existsSync(path.join(path.dirname(file), url))) throw new Error(`Internal Link Test: ${url} with not found error`);
}
}
}];
}

it('tests url avaliability in README.md', async () => {
let [testCount, testFunc] = testUrlInMarkdown("README.md");
jest.setTimeout(testCount * 5000);
return await testFunc();
});
You are viewing a condensed version of this merge commit. You can view the full changes here.