/extra/testing/tests_examples.js

https://gitlab.com/vprihogenko/cr · JavaScript · 455 lines · 368 code · 70 blank · 17 comment · 0 complexity · da8201e3a3d2464e2564c36a11dcb1be MD5 · raw file

  1. var tests = [];
  2. var key = "key";
  3. test = {desc: "call timeout",
  4. lang: "java",
  5. req: {
  6. "userName": "any name",
  7. "serverSecret": key,
  8. "code": "#include <iostream>\n using namespace std;\n int main() {string greeting;\n cin >> greeting;\n for(int i=0; i<10000000000000; i++){} \n cout<< greeting << endl;\n return 0;}",
  9. "language":"cpp",
  10. "testCases":["test1","std2"]
  11. },
  12. "resBody": {
  13. "code": 200,
  14. "response": {
  15. "dockerError": null,
  16. "compilerErrors": null,
  17. "stdout": ["", ""],
  18. "stderr": [
  19. "Time is out of running command >> echo \"test1\" | docker run --name=1456447004216 -i -m 512m --net none --rm -v /opt/shpp/coderunner/dockerShared/1456447004216:/opt/data --log-driver=json-file --log-opt max-size=1k cpp_img start",
  20. "docker: Error response from daemon: Conflict. The name \"/1456447004216\" is already in use by container e4bf434edbb3453ce6481806a325e42f4bf966080d22790e6a36e45cb2075f0d. You have to remove (or rename) that container to be able to reuse that name..\nSee 'docker run --help'.\nError: Command failed: docker: Error response from daemon: Conflict. The name \"/1456447004216\" is already in use by container e4bf434edbb3453ce6481806a325e42f4bf966080d22790e6a36e45cb2075f0d. You have to remove (or rename) that container to be able to reuse that name..\nSee 'docker run --help'.\n"
  21. ]
  22. }
  23. }
  24. };
  25. tests.push(test);
  26. //===============================================================================================================================================================================
  27. var test = {desc: "simple stdout c++",
  28. lang: "cpp",
  29. req: {
  30. "userName": "any name",
  31. "serverSecret": key,
  32. "code": "#include <iostream> \n #include <iostream>\n using namespace std;\n int main() {string greeting;\n cin >> greeting;\n cout << 11111 << greeting << endl;\n return 0;}",
  33. "language":"cpp",
  34. "testCases":["std1","std2"]
  35. },
  36. "resBody": {
  37. "code": 200,
  38. "response": {
  39. "dockerError": null,
  40. "compilerErrors": null,
  41. "stdout": ["11111std1\n", "11111std2\n"],
  42. "stderr": ["",""]
  43. }
  44. }
  45. };
  46. tests.push(test);
  47. //===============================================================================================================================================================================
  48. test = {desc: "simple adding c++",
  49. lang: "cpp",
  50. req: {
  51. "userName": "any name",
  52. "serverSecret": key,
  53. "code": "#include <iostream>\nusing namespace std;\nint main(){int a = 0; \n int b = 0;\ncin >> a;cin >> b;\ncout<<a<<\" \"<<b<<\" \"<<\"res:\"<<a+b<<endl;\nfor(long i=0; i<100;i++){};return 0;}",
  54. "language":"cpp",
  55. "testCases":["2 3","4 5"]
  56. },
  57. "resBody": {
  58. "code": 200,
  59. "response": {
  60. "dockerError": null,
  61. "compilerErrors": null,
  62. "stdout": ["2 3 res:5\n", "4 5 res:9\n"],
  63. "stderr": ["", ""]
  64. }
  65. }
  66. };
  67. tests.push(test);
  68. //===============================================================================================================================================================================
  69. test = {desc: "wrong secret key",
  70. lang: "cpp",
  71. req: {
  72. "userName": "any name",
  73. "serverSecret": "secret_key",
  74. "code": "",
  75. "language":"",
  76. "testCases":[]
  77. },
  78. "resBody": {
  79. "error": {
  80. "code": "403",
  81. "message": "Access denied"
  82. }
  83. }
  84. };
  85. tests.push(test);
  86. //===============================================================================================================================================================================
  87. test = {desc: "suspicious cpp code",
  88. lang: "cpp",
  89. req: {
  90. "userName": "any name",
  91. "serverSecret": key,
  92. "code": "#include <iostream> \n #include <fstream> \n #include <thread> \n __asm__()\n using namespace std;\n int main() {string greeting;\n cin >> greeting;\n for(int i=0; i<10; i++){} \n cout<< greeting << endl;\n return 0;}",
  93. "language":"cpp",
  94. "testCases":["test1","std2"]
  95. },
  96. "resBody": {
  97. "code": 422,
  98. "response": [
  99. {
  100. "danger-level": 2,
  101. "text": "#include <fstream>",
  102. "comment": "Not allowed to use"
  103. },
  104. {
  105. "danger-level": 2,
  106. "text": "#include <thread>",
  107. "comment": "Not allowed to use"
  108. },
  109. {
  110. "danger-level": 3,
  111. "text": "asm",
  112. "comment": "Not allowed to use"
  113. }
  114. ]
  115. }
  116. };
  117. tests.push(test);
  118. //===============================================================================================================================================================================
  119. test = {desc: "suspicious java code",
  120. lang: "java",
  121. req: {
  122. "userName": "any name",
  123. "serverSecret": key,
  124. "code": "import java.awt.*; \n import java.util.*; Class<> \n import java.util.Scanner; \npublic class Main {public static void main(String[] args) {System.out.println(\"Hello world\");}",
  125. "language":"java",
  126. "testCases":[]
  127. },
  128. "resBody": {
  129. "code": 422,
  130. "response": [
  131. {
  132. "danger-level": 2,
  133. "text": "import java.awt.*",
  134. "comment": "Not allowed to use"
  135. },
  136. {
  137. "danger-level": 2,
  138. "text": "import java.util.*",
  139. "comment": "Not allowed to use"
  140. },
  141. {
  142. "danger-level": 3,
  143. "text": "Class",
  144. "comment": "Not allowed to use"
  145. }
  146. ]
  147. }
  148. };
  149. tests.push(test);
  150. //===============================================================================================================================================================================
  151. test = {desc: "exeeded limit test cases",
  152. lang: "cpp",
  153. req: {
  154. "userName": "any name",
  155. "serverSecret": key,
  156. "code": "#include <iostream> \n ...",
  157. "language":"cpp",
  158. "testCases":["std1","std2", "std1","std2", "std1","std2", "std1","std2", "std1","std2", "std1","std2", "std1","std2"]
  159. },
  160. "resBody": {
  161. "code": 422,
  162. "response": [
  163. {
  164. "danger-level": 1,
  165. "text": "Test Cases",
  166. "comment": "limit exceeded"
  167. }
  168. ]
  169. }
  170. };
  171. tests.push(test);
  172. //===============================================================================================================================================================================
  173. test = {desc: "suspicious test cases",
  174. lang: "cpp",
  175. req: {
  176. "userName": "any name",
  177. "serverSecret": key,
  178. "code": "#include <iostream> \n using namespace std;\n int main() {string greeting;\n cin >> greeting;\n for(int i=0; i<10; i++){} \n cout<< greeting << endl;\n return 0;}",
  179. "language":"cpp",
  180. "testCases":["¬¢£¥§™","¥§™"]
  181. },
  182. "resBody": {
  183. "code": 422,
  184. "response": [
  185. {
  186. "danger-level": 2,
  187. "text": "Test case #1",
  188. "comment": "contains forbidden symbols"
  189. },
  190. {
  191. "danger-level": 2,
  192. "text": "Test case #2",
  193. "comment": "contains forbidden symbols"
  194. }
  195. ]
  196. }
  197. };
  198. tests.push(test);
  199. //===============================================================================================================================================================================
  200. test = {desc: "exeeded charecters limit test cases",
  201. lang: "cpp",
  202. req: {
  203. "userName": "any name",
  204. "serverSecret": key,
  205. "code": "#include <iostream> \n using namespace std;\n int main() {string greeting;\n cin >> greeting;\n for(int i=0; i<10; i++){} \n cout<< greeting << endl;\n return 0;}",
  206. "language":"cpp",
  207. "testCases":["test1 "," std2"]
  208. },
  209. "resBody": {
  210. "code": 422,
  211. "response": [
  212. {
  213. "danger-level": 1,
  214. "text": "Test case #1",
  215. "comment": "The characters limit exceeded"
  216. },
  217. {
  218. "danger-level": 1,
  219. "text": "Test case #2",
  220. "comment": "The characters limit exceeded"
  221. }
  222. ]
  223. }
  224. };
  225. tests.push(test);
  226. //===============================================================================================================================================================================
  227. test = {desc: "empty userName",
  228. lang: "cpp",
  229. req: {
  230. "userName": "",
  231. "serverSecret": key,
  232. "code": "#include <iostream>\n using namespace std;\n int main() {string greeting;\n cin >> greeting;\n for(int i=0; i<10; i++){} \n cout<< greeting << endl;\n return 0;}",
  233. "language":"cpp",
  234. "testCases":["std1","std2", "std1","std2", "std1","std2", "std1","std2", "std1","std2", "std1","std2", "std1","std2"]
  235. },
  236. "resBody": {
  237. "error": {
  238. "code": "400",
  239. "message": "Wrong parameters"
  240. }
  241. }
  242. };
  243. tests.push(test);
  244. //===============================================================================================================================================================================
  245. test = {desc: "empty serverSecret",
  246. lang: "cpp",
  247. req: {
  248. "userName": "any name",
  249. "serverSecret": "",
  250. "code": "#include <iostream>\n using namespace std;\n int main() {string greeting;\n cin >> greeting;\n for(int i=0; i<10; i++){} \n cout<< greeting << endl;\n return 0;}",
  251. "language":"cpp",
  252. "testCases":["std1","std2", "std1","std2", "std1","std2", "std1","std2", "std1","std2", "std1","std2", "std1","std2"]
  253. },
  254. "resBody": {
  255. "error": {
  256. "code": "400",
  257. "message": "Wrong parameters"
  258. }
  259. }
  260. };
  261. tests.push(test);
  262. //===============================================================================================================================================================================
  263. test = {desc: "empty code",
  264. lang: "cpp",
  265. req: {
  266. "userName": "any name",
  267. "serverSecret": key,
  268. "code": "",
  269. "language":"cpp",
  270. "testCases":["std1","std2", "std1","std2", "std1","std2", "std1","std2", "std1","std2", "std1","std2", "std1","std2"]
  271. },
  272. "resBody": {
  273. "error": {
  274. "code": "400",
  275. "message": "Wrong parameters"
  276. }
  277. }
  278. };
  279. tests.push(test);
  280. //===============================================================================================================================================================================
  281. test = {desc: "empty language",
  282. lang: "cpp",
  283. req: {
  284. "userName": "any name",
  285. "serverSecret": key,
  286. "code": "#include <iostream>\n using namespace std;\n int main() {string greeting;\n cin >> greeting;\n for(int i=0; i<10; i++){} \n cout<< greeting << endl;\n return 0;}",
  287. "language":"",
  288. "testCases":["std1","std2", "std1","std2", "std1","std2", "std1","std2", "std1","std2", "std1","std2", "std1","std2"]
  289. },
  290. "resBody": {
  291. "error": {
  292. "code": "400",
  293. "message": "Wrong parameters"
  294. }
  295. }
  296. };
  297. tests.push(test);
  298. //===============================================================================================================================================================================
  299. test = {desc: "empty testCases",
  300. lang: "cpp",
  301. req: {
  302. "userName": "any name",
  303. "serverSecret": key,
  304. "code": "#include <iostream>\n using namespace std;\n int main() {string greeting;\n cin >> greeting;\n for(int i=0; i<10; i++){} \n cout<< greeting << endl;\n return 0;}",
  305. "language":"cpp"
  306. },
  307. "resBody": {
  308. "error": {
  309. "code": "400",
  310. "message": "Wrong parameters"
  311. }
  312. }
  313. };
  314. tests.push(test);
  315. //===============================================================================================================================================================================
  316. test = {desc: "simple adding java",
  317. lang: "java",
  318. req: {
  319. "userName": "any name",
  320. "serverSecret": key,
  321. "code": "import java.util.Scanner;\n public class test {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int a = in.nextInt();\n int b = in.nextInt();\n System.out.print(a+b);\n }\n}",
  322. "language":"java",
  323. "testCases":["2 4", "4 5"]
  324. },
  325. "resBody": {
  326. "code": 200,
  327. "response": {
  328. "dockerError": null,
  329. "compilerErrors": null,
  330. "stdout": ["6", "9"],
  331. "stderr": ["", ""]
  332. }
  333. }
  334. };
  335. tests.push(test);
  336. //===============================================================================================================================================================================
  337. test = {desc: "devision by zero java",
  338. lang: "java",
  339. req: {
  340. "userName": "any name",
  341. "serverSecret": key,
  342. "code": "import java.util.Scanner;\n public class test {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n for(int i=0; i<1000000; i++){int t = 5/i;} \n int a = in.nextInt();\n int b = in.nextInt();\n System.out.print(a+b);\n }\n}",
  343. "language":"java",
  344. "testCases":["2 4", "4 5"]
  345. },
  346. "resBody": {
  347. "code": 200,
  348. "response": {
  349. "dockerError": null,
  350. "compilerErrors": null,
  351. "stdout": [
  352. "",
  353. ""
  354. ],
  355. "stderr": [
  356. "Exception in thread \"main\" java.lang.ArithmeticException: / by zero\n\tat code.main(code.java:5)\nError: Command failed: Exception in thread \"main\" java.lang.ArithmeticException: / by zero\n\tat code.main(code.java:5)\n",
  357. "Exception in thread \"main\" java.lang.ArithmeticException: / by zero\n\tat code.main(code.java:5)\nError: Command failed: Exception in thread \"main\" java.lang.ArithmeticException: / by zero\n\tat code.main(code.java:5)\n"
  358. ]
  359. }
  360. }
  361. };
  362. tests.push(test);
  363. //===============================================================================================================================================================================
  364. test = {desc: "compile error java",
  365. lang: "java",
  366. req: {
  367. "userName": "any name",
  368. "serverSecret": key,
  369. "code": "import java.util.Scanner;\n public class test {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n for(int i=0; i<1000000 i++){} \n int a = in.nextInt();\n int b = in.nextInt();\n System.out.print(a+b);\n }\n}",
  370. "language":"java",
  371. "testCases":["2 4", "4 5"]
  372. },
  373. "resBody": {
  374. "code": 200,
  375. "response": {
  376. "dockerError": null,
  377. "compilerErrors": "code.java:5: error: ';' expected\n for(int i=0; i<1000000 i++){} \n ^\n1 error\n",
  378. "stdout": [],
  379. "stderr": []
  380. }
  381. }
  382. };
  383. tests.push(test);
  384. //===============================================================================================================================================================================
  385. module.exports = tests;