This repo is for studying purposes. I developed this small system to practice and resolve algorithm exercises and efficiently test several use cases for each problem.
git clone git@github.com:jparadasb/algorithm_exercises.git
npm install
This is composed by a config file witch have an structure to define the use cases for each problem
{
"name": "BinaryGap" //[name of exercise, this will be shown when the unit test be running],
"func": require("../exercises/BinaryGap.js") //[require sentence to import the solution function],
"cases": [
{
"input": 1041 //[input for the solution function],
"expected": 5 //[return expected, this could be a single result or an array]
}
],
}
The config is loaded for the global.test file using this function.
const config = require("./config.js");
config.forEach((problem) => {
problem.cases.forEach((useCase, index) => {
test(`${problem.name} : ${index}`, () => {
if (Array.isArray(useCase.expected)) {
return expect(useCase.expected).toContain(problem.func(useCase.input));
}
return expect(problem.func(useCase.input)).toBe(useCase.expected);
})
})
})
This logger allows for tracking how much time the execution took.
Use example:
const PerformaceLogger = require('utils/performace.logger.js');
const logger = new PerformaceLogger('Exercise 1');
...
// end of execution
...
logger.stop()
// Exercise 1
// Took 1000ms
// Took 1s
npm run test
If you want to collaborate, just make a fork and a PR