Skip to content

Commit

Permalink
feat: 增加题库功能
Browse files Browse the repository at this point in the history
  • Loading branch information
xjq7 authored and xjq committed Nov 15, 2022
1 parent ba5d9bc commit fcee26e
Show file tree
Hide file tree
Showing 46 changed files with 2,456 additions and 194 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.log
*.log
node_modules/
75 changes: 75 additions & 0 deletions 1.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import assert from 'assert';
function deepClone(obj) {
return JSON.parse(JSON.stringify(obj));
}

function _deepClone(obj, weakMap = new WeakMap()) {
const type = Object.prototype.toString.call(obj);
if (!(type === '[object Object]' || type === '[object Array]')) return obj;
const o = type === '[object Object]' ? {} : [];
if (weakMap.get(obj)) return o;
weakMap.set(obj, true);
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
o[key] = deepClone(obj[key]);
}
}
return o;
}

const cases = [
{
Input: [1, 2, { a: 1 }],
Expected: [1, 2, { a: 1 }],
Message: '两层对象',
},
{
Input: [{ f: 1 }],
Expected: [{ f: 1 }],
Message: '一层对象',
},
{
Input: { b: [{ c: 1, d: [{ d: 1, f: 2 }] }] },
Expected: { b: [{ c: 1, d: [{ d: 1, f: 2 }] }], a: 1 },
Message: '两层对象, 修改返回值',
},
];

(function () {
for (let i = 0; i < cases.length; i++) {
const { Input, Expected, Message } = cases[i];
let output;
try {
output = deepClone(Input);
assert.deepEqual(Input, Expected);
} catch (error) {
console.log('用例 ' + String(i + 1) + ': ' + Message + ' 未通过');
if (error.code === 'ERR_ASSERTION') {
console.log('Input:', JSON.stringify(error.actual));
console.log('Expected:', JSON.stringify(error.expected));
console.log('Received:', JSON.stringify(output));
} else {
console.log(error);
}
break;
}
const originInput = _deepClone(Input);
try {
output['1'] = Math.random();
assert.deepEqual(Input, originInput);
} catch (error) {
if (error.code === 'ERR_ASSERTION') {
console.log('用例 ' + String(i + 1) + ': ' + Message + ' 未通过');
console.log(
'Mutate Output Expected Input: ',
JSON.stringify(originInput)
);
console.log('Input: ', JSON.stringify(Input));
} else {
console.log(error);
}
break;
}
console.log('用例 ' + String(i + 1) + ': ' + Message + ' 通过');
}
})();
5 changes: 5 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
"classnames": "^2.3.2",
"daisyui": "^2.31.0",
"dayjs": "^1.11.6",
"highlight.js": "^11.6.0",
"lodash": "^4.17.21",
"marked": "^4.2.2",
"mobx": "^6.6.2",
"mobx-persist-store": "^1.1.2",
"mobx-react-lite": "^3.4.0",
"monaco-editor": "^0.34.0",
"re-resizable": "^6.9.9",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.4.2",
Expand All @@ -35,7 +38,9 @@
"xterm-addon-web-links": "^0.7.0"
},
"devDependencies": {
"@tailwindcss/typography": "^0.5.8",
"@types/lodash": "^4.14.186",
"@types/marked": "^4.0.7",
"@types/node": "^18.8.5",
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
Expand Down
Loading

0 comments on commit fcee26e

Please sign in to comment.