feat: working through the dynamic testing portion of ligmata

This commit is contained in:
mpaulson 2022-06-23 10:29:59 -06:00
parent 8859e43ac9
commit 90fdc7aa06
9 changed files with 113 additions and 58 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
node_modules node_modules
src/day*

View file

@ -2,7 +2,7 @@
"clearMocks": true, "clearMocks": true,
"moduleNameMapper": { "moduleNameMapper": {
"@code/(.*)": [ "@code/(.*)": [
"<rootDir>/src/day2/$1" "<rootDir>/src/day4/$1"
] ]
}, },
"preset": "ts-jest" "preset": "ts-jest"

View file

@ -1,16 +1,16 @@
## Developed live on twitch ## Developed live on twitch
[ThePrimeagen](https://twitch.tv/ThePrimeagen) [ThePrimeagen](https://twitch.tv/ThePrimeagen)
## Lig-Machine ## Naming
Lengthy ### Lig-Machine
Instrumentation Lengthy Instrumentation Generating Massive Anticompetitive Computational Help for Intermediate Coders // n9
Generating
Massive ### Ligmata
Anticompetitive Literal Improvement Gaining Master and Tutelage on Algorithms
Computational Let's Intelligently Generate Multiple Algorithm Training Assessments // permdaddy
Help for
Intermediate ### If you have a suggestion
Coders make an issue and we will come up with the potential name.
### WARNING ### WARNING
I have just started to add algorithms, so the number of supported algorithms is I have just started to add algorithms, so the number of supported algorithms is

6
ligma.config.js Normal file
View file

@ -0,0 +1,6 @@
module.exports = {
dsa: [
"ArrayList",
],
}

View file

@ -1,18 +1,21 @@
{ {
"name": "kata", "name": "kata",
"version": "1.0.0", "version": "1.0.0",
"main": "index.js", "main": "index.js",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@types/jest": "^28.1.3", "@types/jest": "^28.1.3",
"jest": "^28.1.1", "jest": "^28.1.1",
"ts-jest": "^28.0.5", "ts-jest": "^28.0.5",
"ts-node": "^10.8.1", "ts-node": "^10.8.1",
"tsconfig-paths": "^4.0.0", "tsconfig-paths": "^4.0.0",
"tsconfig-paths-jest": "^0.0.1", "tsconfig-paths-jest": "^0.0.1",
"typescript": "^4.7.4" "typescript": "^4.7.4"
}, },
"scripts": { "scripts": {
"test": "jest" "test": "jest ArrayList"
} },
} "kata_stats": {
"ArrayList": 2
}
}

View file

@ -1,6 +1,23 @@
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
module.exports.package_json = function(config) {
const package_json = require("../package.json");
package_json.scripts.test = `jest ${config.dsa.join(" ")}`;
package_json.kata_stats = config.dsa.reduce((acc, ds) => {
if (!acc[ds]) {
acc[ds] = 0;
}
acc[ds]++;
return acc;
}, package_json.kata_stats || {});
fs.writeFileSync(
path.join(__dirname, "..", "package.json"),
JSON.stringify(package_json, null, 4));
}
module.exports.ts_config = function(set_to) { module.exports.ts_config = function(set_to) {
const ts_config = require("../tsconfig.json"); const ts_config = require("../tsconfig.json");
ts_config.compilerOptions.paths["@code/*"] = [`${set_to}/*`]; ts_config.compilerOptions.paths["@code/*"] = [`${set_to}/*`];

44
scripts/dsa.js Normal file
View file

@ -0,0 +1,44 @@
module.exports = {
ArrayList: {
type: "class",
name: "array-list.ts",
className: "ArrayList",
},
SinglyLinkedList: {
type: "class",
name: "single-linked-list.ts",
className: "LinkedList",
},
DoublyLinkedList: {
type: "class",
name: "doubly-linked-list.ts",
className: "LinkedList",
},
Queue: {
type: "class",
name: "queue",
className: "Queue",
},
Stack: {
type: "class",
name: "stack",
className: "Stack",
},
InsertionSort: {
type: "fn",
name: "insertion-sort.ts",
fn: "insertion_sort",
args: "arr: number[]",
"return": "void",
},
MergeSort: {
type: "fn",
name: "merge-sort.ts",
fn: "merge_sort",
args: "arr: number[]",
"return": "void",
},
};

View file

@ -1,6 +1,8 @@
#!/usr/bin/env node #!/usr/bin/env node
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
const config = require("../ligma.config");
const dsa = require("./dsa");
const src_path = path.join(__dirname, "..", "src"); const src_path = path.join(__dirname, "..", "src");
let day = 1; let day = 1;
@ -28,7 +30,7 @@ try { fs.unlinkSync(day_path); } catch (e) { }
try { fs.mkdirSync(day_path); } catch (e) { } try { fs.mkdirSync(day_path); } catch (e) { }
function create_class(item) { function create_class(item) {
fs.writeFileSync(path.join(day_path, item.name), `export default class ${item.class} { fs.writeFileSync(path.join(day_path, item.name), `export default class ${item.className} {
constructor() { constructor() {
} }
@ -41,35 +43,17 @@ function create_function(item) {
}`); }`);
} }
[{ config.dsa.forEach(ds => {
name: "single-linked-list.ts", const item = dsa[ds];
class: "LinkedList", if (item.type === "class") {
}, { create_class(item);
name: "doubly-linked-list.ts", } else {
class: "LinkedList", create_function(item);
}, { }
name: "array-list.ts", });
class: "ArrayList",
}, {
name: "queue.ts",
class: "Queue",
}, {
name: "stack.ts",
class: "Stack",
}].forEach(c => create_class(c));
[{
name: "insertion-sort.ts",
fn: "insertion_sort",
args: "arr: number[]",
"return": "void",
}, {
name: "merge-sort.ts",
fn: "merge_sort",
args: "arr: number[]",
"return": "void",
}].forEach(f => create_function(f));
const align = require("./align-configs"); const align = require("./align-configs");
align.jest(day_name); align.jest(day_name);
align.ts_config(day_name); align.ts_config(day_name);
align.package_json(config, day_name);

View file

@ -15,7 +15,7 @@
"baseUrl": "src", "baseUrl": "src",
"paths": { "paths": {
"@code/*": [ "@code/*": [
"day2/*" "day4/*"
] ]
} }
}, },