feat: working through the dynamic testing portion of ligmata
This commit is contained in:
parent
8859e43ac9
commit
90fdc7aa06
9 changed files with 113 additions and 58 deletions
|
|
@ -1,6 +1,23 @@
|
|||
const fs = require("fs");
|
||||
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) {
|
||||
const ts_config = require("../tsconfig.json");
|
||||
ts_config.compilerOptions.paths["@code/*"] = [`${set_to}/*`];
|
||||
|
|
|
|||
44
scripts/dsa.js
Normal file
44
scripts/dsa.js
Normal 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",
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
#!/usr/bin/env node
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const config = require("../ligma.config");
|
||||
const dsa = require("./dsa");
|
||||
|
||||
const src_path = path.join(__dirname, "..", "src");
|
||||
let day = 1;
|
||||
|
|
@ -28,7 +30,7 @@ try { fs.unlinkSync(day_path); } catch (e) { }
|
|||
try { fs.mkdirSync(day_path); } catch (e) { }
|
||||
|
||||
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() {
|
||||
|
||||
}
|
||||
|
|
@ -41,35 +43,17 @@ function create_function(item) {
|
|||
}`);
|
||||
}
|
||||
|
||||
[{
|
||||
name: "single-linked-list.ts",
|
||||
class: "LinkedList",
|
||||
}, {
|
||||
name: "doubly-linked-list.ts",
|
||||
class: "LinkedList",
|
||||
}, {
|
||||
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));
|
||||
config.dsa.forEach(ds => {
|
||||
const item = dsa[ds];
|
||||
if (item.type === "class") {
|
||||
create_class(item);
|
||||
} else {
|
||||
create_function(item);
|
||||
}
|
||||
});
|
||||
|
||||
const align = require("./align-configs");
|
||||
align.jest(day_name);
|
||||
align.ts_config(day_name);
|
||||
align.package_json(config, day_name);
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue