index.ts 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. import http from "../common/http";
  2. import {Gitlab} from "@gitbeaker/browser";
  3. import {store} from "@/redux/store";
  4. import {loadError, loadSuccess} from "@/redux/action/action";
  5. import {IFolderTreeNodeProps} from "@dtinsight/molecule/esm/model";
  6. import molecule from "@dtinsight/molecule";
  7. const basePath = './mock';
  8. const apiPath = '/api'
  9. const host = 'https://seecoder-gitlab-gitlab.seec.seecoder.cn';
  10. const token = 'Qhdx3cZF-WRPTTc1yWSf';
  11. const client = new Gitlab({
  12. host: host,
  13. token: token
  14. });
  15. const api = {
  16. getFolderTree() {
  17. const extToLang: { [prop: string]: string } = {
  18. 'html': 'html',
  19. 'js': 'javascript',
  20. 'ts': 'typescript',
  21. 'java': 'java',
  22. 'py': 'python',
  23. 'cpp': 'cpp',
  24. 'json': 'json',
  25. 'xml': 'xml',
  26. }
  27. const nameScope = store.getState().loadProject.nameScope
  28. const path = store.getState().loadProject.path
  29. const projectId = encodeURI(nameScope + '/' + path)
  30. async function getFolderInfo(parent: IFolderTreeNodeProps, parentPath: string): Promise<IFolderTreeNodeProps> {
  31. try {
  32. const tree = await client.Repositories.tree(projectId, {path: parentPath})
  33. for (const index in tree) {
  34. const file = tree[index]
  35. let fileNode: IFolderTreeNodeProps
  36. if (file.type === 'tree') {
  37. fileNode = {
  38. id: file.id,
  39. isEditable: false,
  40. name: file.name,
  41. fileType: "Folder",
  42. location: parentPath ? parentPath + '/' + file.name : file.name,
  43. isLeaf: false,
  44. children: []
  45. }
  46. await getFolderInfo(fileNode, fileNode.location!)
  47. fileNode.location = path + "/" + fileNode.location
  48. parent.children?.push(fileNode)
  49. } else {
  50. fileNode = {
  51. id: file.id,
  52. isEditable: false,
  53. name: file.name,
  54. fileType: "File",
  55. location: parentPath ? parentPath + '/' + file.name : file.name,
  56. isLeaf: true,
  57. data: ''
  58. }
  59. const data = await client.RepositoryFiles.show(projectId, fileNode.location!, 'master')
  60. const frag = fileNode.name!.split('.');
  61. const lang = extToLang[frag[frag.length - 1]] || 'file'
  62. fileNode.data = {language: lang, value: window.atob(data.content)}
  63. fileNode.location = path + "/" + fileNode.location
  64. parent.children?.push(fileNode)
  65. }
  66. }
  67. return parent
  68. } catch (e) {
  69. store.dispatch(loadError(e))
  70. return {id: 'error', data: e}
  71. }
  72. }
  73. let data: IFolderTreeNodeProps = {
  74. id: 0,
  75. isEditable: false,
  76. name: path,
  77. fileType: "RootFolder",
  78. location: path,
  79. isLeaf: false,
  80. data: "",
  81. children: []
  82. }
  83. const res = getFolderInfo(data, "")
  84. res.then(data => {
  85. console.log(data)
  86. if (data.id !== 'error') store.dispatch(loadSuccess())
  87. })
  88. return res
  89. },
  90. search(value: string) {
  91. return http.get(`${basePath}/folderTree.json`, {query: value});
  92. },
  93. async query(query: string = '') {
  94. const data = molecule.folderTree.getState().folderTree;
  95. const result: any[] = [];
  96. const search = (nodeItem: any) => {
  97. if (!nodeItem) return;
  98. const target = nodeItem.name || '';
  99. if (target.includes(query) || query.includes(target)) {
  100. result.push(nodeItem);
  101. }
  102. if (nodeItem.children) {
  103. nodeItem.children.forEach((item: any) => {
  104. search(item)
  105. })
  106. }
  107. }
  108. search(data);
  109. return result;
  110. },
  111. current() {
  112. return http.get(`${apiPath}/auth/current`)
  113. },
  114. getOnlineCodeByExamId(examId: number | string, userId?: number | string) {
  115. return http.get(`${apiPath}/exam/${examId}/onlinecode`,
  116. {userId: userId})
  117. },
  118. updateOnlineCodeByExamIdAndQuestionId(
  119. examId: number | string,
  120. questionId: number | string,
  121. codeDTO: CodeDTO
  122. ) {
  123. return http.post(`${apiPath}/exam/${examId}/onlinecode/${questionId}`, codeDTO)
  124. },
  125. getByExamId(examId: number | string) {
  126. return http.get(`${apiPath}/exam/${examId}`)
  127. },
  128. getByResultId(resultId: number | string) {
  129. return http.get(`${apiPath}/result/${resultId}`)
  130. },
  131. getByCommitId(commitId: number | string) {
  132. return http.get(`${apiPath}/commit/${commitId}`)
  133. },
  134. getByRecordId(recordId: number | string) {
  135. return http.get(`${apiPath}/record/${recordId}`)
  136. },
  137. getExamTest(examId: number):Promise<any> {
  138. return new Promise((resolve => {
  139. setTimeout(()=>{
  140. resolve(JSON.parse("{\n" +
  141. " \"err\": 0,\n" +
  142. " \"res\": {\n" +
  143. " \"id\": 6553,\n" +
  144. " \"name\": \"联调\",\n" +
  145. " \"startAt\": 1667232000,\n" +
  146. " \"endAt\": 1669737600,\n" +
  147. " \"status\": \"AVAILABLE\",\n" +
  148. " \"creator\": {\n" +
  149. " \"id\": 271,\n" +
  150. " \"username\": \"kenny67nju\"\n" +
  151. " },\n" +
  152. " \"joined\": false,\n" +
  153. " \"courseId\": 52,\n" +
  154. " \"url\": null,\n" +
  155. " \"problems\": [\n" +
  156. " {\n" +
  157. " \"id\": 63,\n" +
  158. " \"name\": \"plus2\",\n" +
  159. " \"type\": \"JAVA\",\n" +
  160. " \"description\": \"plus2\"\n" +
  161. " },\n" +
  162. " {\n" +
  163. " \"id\": 113,\n" +
  164. " \"name\": \"hanoi\",\n" +
  165. " \"type\": \"JAVA\",\n" +
  166. " \"description\": \"汉诺塔问题\"\n" +
  167. " },\n" +
  168. " {\n" +
  169. " \"id\": 95,\n" +
  170. " \"name\": \"good-map-game-new\",\n" +
  171. " \"type\": \"JAVA\",\n" +
  172. " \"description\": \"面向对象\"\n" +
  173. " }\n" +
  174. " ],\n" +
  175. " \"result\": null,\n" +
  176. " \"created_at\": 1667473399,\n" +
  177. " \"course\": \"基于Java的面向对象编程范式2022\"\n" +
  178. " }\n" +
  179. "}"))
  180. }, 500)
  181. }))
  182. },
  183. getRecordTest(recordId: number | string) {
  184. return new Promise((resolve) => {
  185. setTimeout(() => {
  186. resolve(JSON.parse("{\"err\":0,\n" +
  187. " \"res\":{\n" +
  188. " \"id\":36464,\n" +
  189. " \"number\":1,\n" +
  190. " \"status\":\"UNSTABLE\",\n" +
  191. " \"consoleOutput\":\"Timeout set to expire in 1 min 0 sec\\r\\nPicked up JAVA_TOOL_OPTIONS: -Dfile.encoding=utf-8\\r\\nPicked up _JAVA_OPTIONS: -Djdk.net.URLClassPath.disableClassPathURLCheck=true\\r\\n[INFO] Scanning for projects...\\r\\n[INFO] \\r\\n[INFO] ------------------------------------------------------------------------\\r\\n[INFO] Building matrix-calculation 1.0.0\\r\\n[INFO] ------------------------------------------------------------------------\\r\\n[INFO] \\r\\n[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ matrix-calculation ---\\r\\n[INFO] Deleting /var/ws/tmp/target\\r\\n[INFO] \\r\\n[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ matrix-calculation ---\\r\\n[INFO] Using 'UTF-8' encoding to copy filtered resources.\\r\\n[INFO] skip non existing resourceDirectory /var/ws/tmp/src/main/resources\\r\\n[INFO] \\r\\n[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ matrix-calculation ---\\r\\n[INFO] Changes detected - recompiling the module!\\r\\n[INFO] Compiling 1 source file to /var/ws/tmp/target/classes\\r\\n[INFO] \\r\\n[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ matrix-calculation ---\\r\\n[INFO] Using 'UTF-8' encoding to copy filtered resources.\\r\\n[INFO] skip non existing resourceDirectory /var/ws/tmp/src/test/resources\\r\\n[INFO] \\r\\n[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ matrix-calculation ---\\r\\n[INFO] Changes detected - recompiling the module!\\r\\n[INFO] Compiling 1 source file to /var/ws/tmp/target/test-classes\\r\\n[INFO] \\r\\n[INFO] --- maven-surefire-plugin:2.17:test (default-test) @ matrix-calculation ---\\r\\n[INFO] Surefire report directory: /var/ws/tmp/target/surefire-reports\\r\\n\\r\\n-------------------------------------------------------\\r\\n T E S T S\\r\\n-------------------------------------------------------\\r\\nPicked up JAVA_TOOL_OPTIONS: -Dfile.encoding=utf-8\\r\\nPicked up _JAVA_OPTIONS: -Djdk.net.URLClassPath.disableClassPathURLCheck=true\\r\\nRunning edu.nju.test.MatrixCalculationTest\\r\\nTests run: 21, Failures: 11, Errors: 2, Skipped: 0, Time elapsed: 0.125 sec <<< FAILURE! - in edu.nju.test.MatrixCalculationTest\\r\\ntestPrint(edu.nju.test.MatrixCalculationTest) Time elapsed: 0.007 sec <<< FAILURE!\\r\\norg.junit.ComparisonFailure: expected:<[\\r\\n]1 1 1\\r\\n1 1 1\\r\\n1 1 1\\r\\n> but was:<[]1 1 1\\r\\n1 1 1\\r\\n1 1 1\\r\\n>\\r\\n\\tat org.junit.Assert.assertEquals(Assert.java:115)\\r\\n\\tat org.junit.Assert.assertEquals(Assert.java:144)\\r\\n\\tat edu.nju.test.MatrixCalculationTest.testPrint(MatrixCalculationTest.java:111)\\r\\n\\r\\ntestTimes(edu.nju.test.MatrixCalculationTest) Time elapsed: 0 sec <<< FAILURE!\\r\\njava.lang.AssertionError: null\\r\\n\\tat org.junit.Assert.fail(Assert.java:86)\\r\\n\\tat org.junit.Assert.assertTrue(Assert.java:41)\\r\\n\\tat org.junit.Assert.assertTrue(Assert.java:52)\\r\\n\\tat edu.nju.test.MatrixCalculationTest.testTimes(MatrixCalculationTest.java:65)\\r\\n\\r\\ntestPlusFromConsole4(edu.nju.test.MatrixCalculationTest) Time elapsed: 0.003 sec <<< ERROR!\\r\\njava.lang.ArrayIndexOutOfBoundsException: 0\\r\\n\\tat edu.nju.MatrixCalculation.plus(MatrixCalculation.java:20)\\r\\n\\tat edu.nju.MatrixCalculation.plusFromConsole(MatrixCalculation.java:81)\\r\\n\\tat edu.nju.test.MatrixCalculationTest.testPlusFromConsole4(MatrixCalculationTest.java:323)\\r\\n\\r\\ntestTimesFromConsole(edu.nju.test.MatrixCalculationTest) Time elapsed: 0.001 sec <<< FAILURE!\\r\\njava.lang.AssertionError: null\\r\\n\\tat org.junit.Assert.fail(Assert.java:86)\\r\\n\\tat org.junit.Assert.assertTrue(Assert.java:41)\\r\\n\\tat org.junit.Assert.assertTrue(Assert.java:52)\\r\\n\\tat edu.nju.test.MatrixCalculationTest.testTimesFromConsole(MatrixCalculationTest.java:97)\\r\\n\\r\\ntestPrint1(edu.nju.test.MatrixCalculationTest) Time elapsed: 0 sec <<< FAILURE!\\r\\norg.junit.ComparisonFailure: expected:<[\\r\\n]1 1 1\\r\\n> but was:<[]1 1 1\\r\\n>\\r\\n\\tat org.junit.Assert.assertEquals(Assert.java:115)\\r\\n\\tat org.junit.Assert.assertEquals(Assert.java:144)\\r\\n\\tat edu.nju.test.MatrixCalculationTest.testPrint1(MatrixCalculationTest.java:255)\\r\\n\\r\\ntestPrint2(edu.nju.test.MatrixCalculationTest) Time elapsed: 0 sec <<< FAILURE!\\r\\norg.junit.ComparisonFailure: expected:<[\\r\\n]1\\r\\n1\\r\\n1\\r\\n> but was:<[]1\\r\\n1\\r\\n1\\r\\n>\\r\\n\\tat org.junit.Assert.assertEquals(Assert.java:115)\\r\\n\\tat org.junit.Assert.assertEquals(Assert.java:144)\\r\\n\\tat edu.nju.test.MatrixCalculationTest.testPrint2(MatrixCalculationTest.java:267)\\r\\n\\r\\ntestTimesFromConsole1(edu.nju.test.MatrixCalculationTest) Time elapsed: 0.001 sec <<< FAILURE!\\r\\njava.lang.AssertionError: null\\r\\n\\tat org.junit.Assert.fail(Assert.java:86)\\r\\n\\tat org.junit.Assert.assertTrue(Assert.java:41)\\r\\n\\tat org.junit.Assert.assertTrue(Assert.java:52)\\r\\n\\tat edu.nju.test.MatrixCalculationTest.testTimesFromConsole1(MatrixCalculationTest.java:340)\\r\\n\\r\\ntestTimesFromConsole2(edu.nju.test.MatrixCalculationTest) Time elapsed: 0.002 sec <<< FAILURE!\\r\\njava.lang.AssertionError: null\\r\\n\\tat org.junit.Assert.fail(Assert.java:86)\\r\\n\\tat org.junit.Assert.assertTrue(Assert.java:41)\\r\\n\\tat org.junit.Assert.assertTrue(Assert.java:52)\\r\\n\\tat edu.nju.test.MatrixCalculationTest.testTimesFromConsole2(MatrixCalculationTest.java:357)\\r\\n\\r\\ntestTimesFromConsole3(edu.nju.test.MatrixCalculationTest) Time elapsed: 0.001 sec <<< FAILURE!\\r\\njava.lang.AssertionError: null\\r\\n\\tat org.junit.Assert.fail(Assert.java:86)\\r\\n\\tat org.junit.Assert.assertTrue(Assert.java:41)\\r\\n\\tat org.junit.Assert.assertTrue(Assert.java:52)\\r\\n\\tat edu.nju.test.MatrixCalculationTest.testTimesFromConsole3(MatrixCalculationTest.java:372)\\r\\n\\r\\ntestTimesFromConsole4(edu.nju.test.MatrixCalculationTest) Time elapsed: 0 sec <<< ERROR!\\r\\njava.lang.ArrayIndexOutOfBoundsException: 0\\r\\n\\tat edu.nju.MatrixCalculation.times(MatrixCalculation.java:34)\\r\\n\\tat edu.nju.MatrixCalculation.timesFromConsole(MatrixCalculation.java:107)\\r\\n\\tat edu.nju.test.MatrixCalculationTest.testTimesFromConsole4(MatrixCalculationTest.java:383)\\r\\n\\r\\ntestTimes1(edu.nju.test.MatrixCalculationTest) Time elapsed: 0 sec <<< FAILURE!\\r\\njava.lang.AssertionError: null\\r\\n\\tat org.junit.Assert.fail(Assert.java:86)\\r\\n\\tat org.junit.Assert.assertTrue(Assert.java:41)\\r\\n\\tat org.junit.Assert.assertTrue(Assert.java:52)\\r\\n\\tat edu.nju.test.MatrixCalculationTest.testTimes1(MatrixCalculationTest.java:203)\\r\\n\\r\\ntestTimes2(edu.nju.test.MatrixCalculationTest) Time elapsed: 0 sec <<< FAILURE!\\r\\njava.lang.AssertionError: null\\r\\n\\tat org.junit.Assert.fail(Assert.java:86)\\r\\n\\tat org.junit.Assert.assertTrue(Assert.java:41)\\r\\n\\tat org.junit.Assert.assertTrue(Assert.java:52)\\r\\n\\tat edu.nju.test.MatrixCalculationTest.testTimes2(MatrixCalculationTest.java:223)\\r\\n\\r\\ntestTimes3(edu.nju.test.MatrixCalculationTest) Time elapsed: 0 sec <<< FAILURE!\\r\\njava.lang.AssertionError: null\\r\\n\\tat org.junit.Assert.fail(Assert.java:86)\\r\\n\\tat org.junit.Assert.assertTrue(Assert.java:41)\\r\\n\\tat org.junit.Assert.assertTrue(Assert.java:52)\\r\\n\\tat edu.nju.test.MatrixCalculationTest.testTimes3(MatrixCalculationTest.java:241)\\r\\n\\r\\n\\r\\nResults :\\r\\n\\r\\nFailed tests: \\r\\n MatrixCalculationTest.testPrint:111 expected:<[\\r\\n]1 1 1\\r\\n1 1 1\\r\\n1 1 1\\r\\n> but was:<[]1 1 1\\r\\n1 1 1\\r\\n1 1 1\\r\\n>\\r\\n MatrixCalculationTest.testTimes:65 null\\r\\n MatrixCalculationTest.testTimesFromConsole:97 null\\r\\n MatrixCalculationTest.testPrint1:255 expected:<[\\r\\n]1 1 1\\r\\n> but was:<[]1 1 1\\r\\n>\\r\\n MatrixCalculationTest.testPrint2:267 expected:<[\\r\\n]1\\r\\n1\\r\\n1\\r\\n> but was:<[]1\\r\\n1\\r\\n1\\r\\n>\\r\\n MatrixCalculationTest.testTimesFromConsole1:340 null\\r\\n MatrixCalculationTest.testTimesFromConsole2:357 null\\r\\n MatrixCalculationTest.testTimesFromConsole3:372 null\\r\\n MatrixCalculationTest.testTimes1:203 null\\r\\n MatrixCalculationTest.testTimes2:223 null\\r\\n MatrixCalculationTest.testTimes3:241 null\\r\\n\\r\\nTests in error: \\r\\n MatrixCalculationTest.testPlusFromConsole4:323 » ArrayIndexOutOfBounds 0\\r\\n MatrixCalculationTest.testTimesFromConsole4:383 » ArrayIndexOutOfBounds 0\\r\\n\\r\\nTests run: 21, Failures: 11, Errors: 2, Skipped: 0\\r\\n\\r\\n[INFO] ------------------------------------------------------------------------\\r\\n[INFO] BUILD FAILURE\\r\\n[INFO] ------------------------------------------------------------------------\\r\\n[INFO] Total time: 5.066 s\\r\\n[INFO] Finished at: 2022-10-12T04:45:26+00:00\\r\\n[INFO] Final Memory: 13M/33M\\r\\n[INFO] ------------------------------------------------------------------------\\r\\n[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test (default-test) on project matrix-calculation: There are test failures.\\r\\n[ERROR] \\r\\n[ERROR] Please refer to /var/ws/tmp/target/surefire-reports for the individual test results.\\r\\n[ERROR] -> [Help 1]\\r\\n[ERROR] \\r\\n[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.\\r\\n[ERROR] Re-run Maven using the -X switch to enable full debug logging.\\r\\n[ERROR] \\r\\n[ERROR] For more information about the errors and possible solutions, please read the following articles:\\r\\n[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException\\r\\n[INFO] Build failures were ignored.\\r\\n\",\n" +
  192. " \"score\":38,\n" +
  193. " \"failures\": [\n" +
  194. " {\"name\":\"edu.nju.test.MatrixCalculationTest.testTimes1\",\n" +
  195. " \"details\":\"\",\n" +
  196. " \"trace\":\"java.lang.AssertionError: null\\n\\tat org.junit.Assert.fail(Assert.java:86)\\n\\tat org.junit.Assert.assertTrue(Assert.java:41)\\n\\tat org.junit.Assert.assertTrue(Assert.java:52)\\n\\tat edu.nju.test.MatrixCalculationTest.testTimes1(MatrixCalculationTest.java:203)\\n\"},\n" +
  197. " {\"name\":\"edu.nju.test.MatrixCalculationTest.testPrint1\",\"details\":\"expected:<[\\n]1 1 1\\n> but was:<[]1 1 1\\n>\",\"trace\":\"org.junit.ComparisonFailure: expected:<[\\n]1 1 1\\n> but was:<[]1 1 1\\n>\\n\\tat org.junit.Assert.assertEquals(Assert.java:115)\\n\\tat org.junit.Assert.assertEquals(Assert.java:144)\\n\\tat edu.nju.test.MatrixCalculationTest.testPrint1(MatrixCalculationTest.java:255)\\n\"},\n" +
  198. " {\"name\":\"edu.nju.test.MatrixCalculationTest.testTimesFromConsole2\",\"details\":\"\",\"trace\":\"java.lang.AssertionError: null\\n\\tat org.junit.Assert.fail(Assert.java:86)\\n\\tat org.junit.Assert.assertTrue(Assert.java:41)\\n\\tat org.junit.Assert.assertTrue(Assert.java:52)\\n\\tat edu.nju.test.MatrixCalculationTest.testTimesFromConsole2(MatrixCalculationTest.java:357)\\n\"},\n" +
  199. " {\"name\":\"edu.nju.test.MatrixCalculationTest.testTimes3\",\"details\":\"\",\"trace\":\"java.lang.AssertionError: null\\n\\tat org.junit.Assert.fail(Assert.java:86)\\n\\tat org.junit.Assert.assertTrue(Assert.java:41)\\n\\tat org.junit.Assert.assertTrue(Assert.java:52)\\n\\tat edu.nju.test.MatrixCalculationTest.testTimes3(MatrixCalculationTest.java:241)\\n\"},{\"name\":\"edu.nju.test.MatrixCalculationTest.testTimesFromConsole4\",\"details\":\"0\",\"trace\":\"java.lang.ArrayIndexOutOfBoundsException: 0\\n\\tat edu.nju.MatrixCalculation.times(MatrixCalculation.java:34)\\n\\tat edu.nju.MatrixCalculation.timesFromConsole(MatrixCalculation.java:107)\\n\\tat edu.nju.test.MatrixCalculationTest.testTimesFromConsole4(MatrixCalculationTest.java:383)\\n\"},{\"name\":\"edu.nju.test.MatrixCalculationTest.testTimes\",\"details\":\"\",\"trace\":\"java.lang.AssertionError: null\\n\\tat org.junit.Assert.fail(Assert.java:86)\\n\\tat org.junit.Assert.assertTrue(Assert.java:41)\\n\\tat org.junit.Assert.assertTrue(Assert.java:52)\\n\\tat edu.nju.test.MatrixCalculationTest.testTimes(MatrixCalculationTest.java:65)\\n\"},{\"name\":\"edu.nju.test.MatrixCalculationTest.testPrint2\",\"details\":\"expected:<[\\n]1\\n1\\n1\\n> but was:<[]1\\n1\\n1\\n>\",\"trace\":\"org.junit.ComparisonFailure: expected:<[\\n]1\\n1\\n1\\n> but was:<[]1\\n1\\n1\\n>\\n\\tat org.junit.Assert.assertEquals(Assert.java:115)\\n\\tat org.junit.Assert.assertEquals(Assert.java:144)\\n\\tat edu.nju.test.MatrixCalculationTest.testPrint2(MatrixCalculationTest.java:267)\\n\"},{\"name\":\"edu.nju.test.MatrixCalculationTest.testTimesFromConsole1\",\"details\":\"\",\"trace\":\"java.lang.AssertionError: null\\n\\tat org.junit.Assert.fail(Assert.java:86)\\n\\tat org.junit.Assert.assertTrue(Assert.java:41)\\n\\tat org.junit.Assert.assertTrue(Assert.java:52)\\n\\tat edu.nju.test.MatrixCalculationTest.testTimesFromConsole1(MatrixCalculationTest.java:340)\\n\"},{\"name\":\"edu.nju.test.MatrixCalculationTest.testPlusFromConsole4\",\"details\":\"0\",\"trace\":\"java.lang.ArrayIndexOutOfBoundsException: 0\\n\\tat edu.nju.MatrixCalculation.plus(MatrixCalculation.java:20)\\n\\tat edu.nju.MatrixCalculation.plusFromConsole(MatrixCalculation.java:81)\\n\\tat edu.nju.test.MatrixCalculationTest.testPlusFromConsole4(MatrixCalculationTest.java:323)\\n\"},{\"name\":\"edu.nju.test.MatrixCalculationTest.testTimesFromConsole\",\"details\":\"\",\"trace\":\"java.lang.AssertionError: null\\n\\tat org.junit.Assert.fail(Assert.java:86)\\n\\tat org.junit.Assert.assertTrue(Assert.java:41)\\n\\tat org.junit.Assert.assertTrue(Assert.java:52)\\n\\tat edu.nju.test.MatrixCalculationTest.testTimesFromConsole(MatrixCalculationTest.java:97)\\n\"},{\"name\":\"edu.nju.test.MatrixCalculationTest.testTimesFromConsole3\",\"details\":\"\",\"trace\":\"java.lang.AssertionError: null\\n\\tat org.junit.Assert.fail(Assert.java:86)\\n\\tat org.junit.Assert.assertTrue(Assert.java:41)\\n\\tat org.junit.Assert.assertTrue(Assert.java:52)\\n\\tat edu.nju.test.MatrixCalculationTest.testTimesFromConsole3(MatrixCalculationTest.java:372)\\n\"},{\"name\":\"edu.nju.test.MatrixCalculationTest.testPrint\",\"details\":\"expected:<[\\n]1 1 1\\n1 1 1\\n1 1 1\\n> but was:<[]1 1 1\\n1 1 1\\n1 1 1\\n>\",\"trace\":\"org.junit.ComparisonFailure: expected:<[\\n]1 1 1\\n1 1 1\\n1 1 1\\n> but was:<[]1 1 1\\n1 1 1\\n1 1 1\\n>\\n\\tat org.junit.Assert.assertEquals(Assert.java:115)\\n\\tat org.junit.Assert.assertEquals(Assert.java:144)\\n\\tat edu.nju.test.MatrixCalculationTest.testPrint(MatrixCalculationTest.java:111)\\n\"},{\"name\":\"edu.nju.test.MatrixCalculationTest.testTimes2\",\"details\":\"\",\"trace\":\"java.lang.AssertionError: null\\n\\tat org.junit.Assert.fail(Assert.java:86)\\n\\tat org.junit.Assert.assertTrue(Assert.java:41)\\n\\tat org.junit.Assert.assertTrue(Assert.java:52)\\n\\tat edu.nju.test.MatrixCalculationTest.testTimes2(MatrixCalculationTest.java:223)\\n\"}],\n" +
  200. " \"commit\": {\n" +
  201. " \"id\":32552,\n" +
  202. " \"created_at\":1665549884\n" +
  203. " }\n" +
  204. " }\n" +
  205. "}"))
  206. }, 500)
  207. })
  208. },
  209. async test(examId: number, questionId: number):Promise<any> {
  210. http.get(`${apiPath}/auth/current`)
  211. return new Promise((resolve) => {
  212. setTimeout(() => {
  213. resolve(JSON.parse("{\"err\":0,\n" +
  214. " \"res\":{\n" +
  215. " \"examId\":6629,\n" +
  216. " \"fetchAt\":1669059664,\n" +
  217. " \"startAt\":1668441600,\n" +
  218. " \"endAt\":1669737600,\n" +
  219. " \"codeList\":[\n" +
  220. " {\"questionId\":113,\n" +
  221. " \"language\":\"JAVA\",\n" +
  222. " \"projectName\":\"113-hanoi\",\n" +
  223. " \"editable\":{\n" +
  224. " \"/src/main/java/TowerOfHanoi.java\":\"public class TowerOfHanoi {\\n public void Hanoi(int n) {}\\n}\\n\"},\n" +
  225. " \"uneditable\":{\n" +
  226. " \"/README.md\":\"2.实现Hanoi塔\\r\\n\\r\\n问题描述:递归实现汉诺塔,有三根杆(编号A、B、C),在A杆自下而上、由大到小按顺序放置n个盘子。\\r\\n要求把A杆上的盘子全部移到B杆上,并仍保持原有顺序叠好。\\r\\n操作规则:每次只能移动一个盘子,并且在移动过程中三根杆上都始终保持大盘在下,小盘在上,操作过程中盘子可以置于A、B、C任一杆上。\\r\\n\\r\\n完成函数Hanoi,使用标准输出打印移动盘子的过程。\\r\\n输入:n为正整数,n >= 1\\r\\n\\r\\n示例:\\r\\nn = 2\\r\\n打印结果(最后一行有换行符):\\r\\nMove disk 1 from A to C\\r\\nMove disk 2 from A to B\\r\\nMove disk 1 from C to B\\r\\n\"\n" +
  227. " }\n" +
  228. " }\n" +
  229. " ]\n" +
  230. " }\n" +
  231. "}"))
  232. }, 2500)
  233. })
  234. },
  235. // getQuestion(examId: number, questionId: number) {
  236. // return http.get(`${apiPath}/exam/${examId}/onlinecode/${questionId}`)
  237. // },
  238. getQuestion(examId: number, userId: number) {
  239. if (userId) return http.get(`${apiPath}/exam/${examId}/onlinecode`, {userId: userId})
  240. else return http.get(`${apiPath}/exam/${examId}/onlinecode`)
  241. }
  242. }
  243. export interface CodeDTO {
  244. code: { [key: string]: string }
  245. }
  246. export interface PageSerializer {
  247. page?: number
  248. limit?: number
  249. size?: number
  250. total?: number
  251. }
  252. export interface ResultSerializer {
  253. id?: number
  254. score?: number
  255. lastCommitAt?: number
  256. deleted?: boolean
  257. exam?: {
  258. id?: number
  259. name?: string
  260. course?: string
  261. }
  262. owner?: {
  263. id?: number
  264. username?: string
  265. }
  266. commits?: Array<{
  267. id?: number
  268. finished?: boolean
  269. score?: number
  270. // eslint-disable-next-line camelcase
  271. created_at?: number
  272. }>
  273. }
  274. export interface CommitSerializer {
  275. id?: number
  276. hash?: string
  277. finished?: boolean
  278. score?: number
  279. createdAt?: number
  280. result?: {
  281. id?: number
  282. score?: number
  283. exam?: {
  284. id?: number
  285. name?: string
  286. }
  287. owner?: {
  288. id?: number
  289. username?: string
  290. }
  291. }
  292. records?: Array<{
  293. id?: number
  294. status?: BuildStatus
  295. score?: number
  296. problem?: {
  297. id?: number
  298. name?: string
  299. }
  300. }>
  301. }
  302. export interface ExamSerializer {
  303. id?: number
  304. name?: string
  305. // eslint-disable-next-line camelcase
  306. created_at?: number
  307. startAt?: number
  308. endAt?: number
  309. status?: ExamStatus
  310. creator?: {
  311. id?: number
  312. username?: string
  313. }
  314. problems?: ProblemSerializer[]
  315. joined?: boolean
  316. courseId?: number
  317. courseName?: string
  318. result?: ResultSerializer
  319. isCodeAnalysisNeeded?: boolean
  320. url?: string
  321. }
  322. export type ProblemType =
  323. | 'JAVA' // 普通Java题目,统计测试用例通过情况
  324. | 'JAVA_DATABASE' // 带数据库的Java题目,统计测试用例通过情况
  325. | 'PYTHON' // 普通Python题目,统计测试用例通过情况
  326. | 'JAVA_COVERAGE' // Java测试覆盖率题目,统计测试覆盖率
  327. | 'PYTHON_COVERAGE' // Python测试覆盖率题目,统计测试覆盖率
  328. | 'JAVA_MUTATION' // Java变异覆盖题目,统计变异覆盖率
  329. | 'JAVA_DATA_STRUCTURE' // 带数据结构的Java题目,统计测试用例通过情况
  330. | 'JAVA_COMPUTER_ORGANIZATION' // 带计算机组成原理的Java题目,统计测试用例通过情况
  331. | 'JAVA_SOFTWARE_DESIGN' // 带软件设计的Java题目,统计测试用例通过情况
  332. export interface ProblemSerializer {
  333. id?: number
  334. name?: string
  335. type?: ProblemType
  336. description?: string
  337. publicFiles?: Array<string>
  338. protectedFiles?: Array<string>
  339. privateFiles?: Array<string>
  340. createdAt?: number
  341. modifiedAt?: number
  342. deprecated?: boolean
  343. creator?: {
  344. id?: number
  345. username?: string
  346. }
  347. }
  348. export interface ReceivedData<R = {}, E = 0> {
  349. msg?: string
  350. err?: E | 0 | 401
  351. res?: R
  352. page?: PageSerializer
  353. }
  354. export type UserRole =
  355. | 'STUDENT'
  356. | 'TEACHER'
  357. | 'ADMIN'
  358. | 'HR'
  359. | 'STAFF'
  360. | 'SEEC'
  361. | 'SEECX'
  362. | 'ASSISTANT'
  363. export interface UserSerializer {
  364. id?: number
  365. score?: number
  366. username?: string
  367. email?: string
  368. phone?: string
  369. role?: UserRole
  370. }
  371. export interface CodeSerializer {
  372. examId?: number
  373. fetchAt?: number
  374. startAt?: number
  375. endAt?: number
  376. codeList?: Array<NestedCodeItemVO>
  377. }
  378. export interface NestedCodeItemVO {
  379. questionId?: number
  380. language?: string
  381. projectName?: string
  382. editable?: {
  383. [key: string]: string
  384. }
  385. uneditable?: {
  386. [key: string]: string
  387. }
  388. }
  389. export type ExamStatus =
  390. | 'PREPARING' // 正在准备试题,通常是正在PUSH试题
  391. | 'UNAVAILABLE' // 考试不可用,通常是PUSH试题失败
  392. | 'READY' // 考试已准备好,在考试尚未开始时使用,不持久化到数据库中
  393. | 'AVAILABLE' // 考试可用,表示考试正在进行,持久化时考试从准备好到考试被关闭均为此状态
  394. | 'FINISHED' // 考试已完成,在考试结束后使用,不持久化到数据库中
  395. | 'CLOSED' // 考试已关闭,表示考试生命周期结束,所有试卷均被存档
  396. export type BuildStatus =
  397. | 'SUCCESS' // 构建成功,表示没有错误
  398. | 'UNSTABLE' // 构建不稳定,表示有测试错误等非致命错误
  399. | 'FAILURE' // 构建失败,表示有语法错误等致命错误
  400. | 'TIMEOUT' // 构建超时,表示运行测试时超时
  401. | 'WAITING' // 等待构建,表示构建尚未开始
  402. | 'RUNNING' // 正在构建,表示构建正在进行
  403. export default api;