How to use check_status method in avocado

Best Python code snippet using avocado_python

correction.test.js

Source:correction.test.js Github

copy

Full Screen

1import { assessItem, STATUS_BAD_FORM, STATUS_BAD_UNIT, STATUS_CORRECT, STATUS_EMPTY, STATUS_INCORRECT, STATUS_UNOPTIMAL_FORM } from '../src/features/calcul-mental/correction'2import generateQuestion from '../src/features/calcul-mental/generateQuestion'3describe('testing empty answer', () => {4 const specs = [[5 {6 expressions: ['1+2'],7 },8 {9 answer: '',10 check_status: STATUS_EMPTY11 },12 ],13 [14 {15 choices: [],16 },17 {18 answer_choice: null,19 check_status: STATUS_EMPTY20 }21 ]]22 test.each(specs)('', (q, check) => {23 const generated = generateQuestion(q)24 const item = {25 ...generated,26 ...check27 }28 assessItem(item)29 expect(item.status).toBe(item.check_status)30 })31})32describe('testing correct answer (no unit)', () => {33 const specs = [[34 {35 expressions: ['2+3'],36 },37 {38 answer: '5',39 check_status: STATUS_CORRECT40 },41 ],42 [43 {44 expressions: ['2,3'],45 'result-type': 'decimal',46 },47 {48 answer: '2,3',49 check_status: STATUS_CORRECT50 },51 ],52 [53 {54 expressions: ['1,2'],55 },56 {57 answer: '6/5',58 check_status: STATUS_CORRECT59 },60 ],61 [62 {63 choices: [['oui', 'non']],64 solutions: [[0]],65 },66 {67 answer_choice: 0,68 check_status: STATUS_CORRECT69 }70 ]]71 test.each(specs)('', (q, check) => {72 let answer_choice_text73 let new_answer_choice74 const generated = generateQuestion(q)75 if (q.choices) {76 answer_choice_text = q.choices[0][check.answer_choice]77 new_answer_choice = generated.choices.indexOf(answer_choice_text)78 check.answer_choice = new_answer_choice79 }80 const item = {81 ...generated,82 ...check83 }84 assessItem(item)85 expect(item.status).toBe(item.check_status)86 })87})88describe('testing correct answer (with same unit)', () => {89 const specs = [[90 {91 expressions: ['2 cm + 3 cm'],92 },93 {94 answer: '5 cm',95 check_status: STATUS_CORRECT96 },97 ],98 ]99 test.each(specs)('', (q, check) => {100 const generated = generateQuestion(q)101 const item = {102 ...generated,103 ...check104 }105 assessItem(item)106 expect(item.status).toBe(item.check_status)107 })108})109describe('testing correct answer (with different unit)', () => {110 const specs = [[111 {112 expressions: ['2 m + 3 m'],113 },114 {115 answer: '500 cm',116 check_status: STATUS_CORRECT117 },118 ],119 ]120 test.each(specs)('', (q, check) => {121 const generated = generateQuestion(q)122 const item = {123 ...generated,124 ...check125 }126 assessItem(item)127 expect(item.status).toBe(item.check_status)128 })129})130describe('testing incorrect answer', () => {131 const specs = [[132 {133 expressions: ['3+4'],134 },135 {136 answer: '6',137 check_status: STATUS_INCORRECT138 },139 ],140 [141 {142 choices: [['oui', 'non']],143 solutions: [[0]],144 },145 {146 answer_choice: 1,147 check_status: STATUS_INCORRECT148 }149 ]]150 test.each(specs)('', (q, check) => {151 let answer_choice_text152 let new_answer_choice153 const generated = generateQuestion(q)154 if (q.choices) {155 answer_choice_text = q.choices[0][check.answer_choice]156 new_answer_choice = generated.choices.indexOf(answer_choice_text)157 check.answer_choice = new_answer_choice158 }159 const item = {160 ...generated,161 ...check162 }163 assessItem(item)164 expect(item.status).toBe(item.check_status)165 })166})167describe('testing incorrect answer (with unit)', () => {168 const specs = [[169 {170 expressions: ['2 cm + 3 cm'],171 },172 {173 answer: '6 cm',174 check_status: STATUS_INCORRECT175 },176 ],177 ]178 test.each(specs)('', (q, check) => {179 const generated = generateQuestion(q)180 const item = {181 ...generated,182 ...check183 }184 assessItem(item)185 expect(item.status).toBe(item.check_status)186 })187})188describe('testing incorrect answer (incorrect unit)', () => {189 const specs = [[190 {191 expressions: ['2 cm + 3 cm'],192 },193 {194 answer: '5 m',195 check_status: STATUS_INCORRECT196 },197 ],198 ]199 test.each(specs)('', (q, check) => {200 const generated = generateQuestion(q)201 const item = {202 ...generated,203 ...check204 }205 assessItem(item)206 expect(item.status).toBe(item.check_status)207 })208})209describe('testing incorrect answer (forgotten unit)', () => {210 const specs = [[211 {212 expressions: ['2 cm + 3 cm'],213 },214 {215 answer: '5',216 check_status: STATUS_INCORRECT217 },218 ],219 ]220 test.each(specs)('', (q, check) => {221 const generated = generateQuestion(q)222 const item = {223 ...generated,224 ...check225 }226 assessItem(item)227 expect(item.status).toBe(item.check_status)228 })229})230describe('testing correct answer with specified unit (require-specific-unit)', () => {231 const specs = [[232 {233 expressions: ['2 m + 3 m'],234 unit: 'm',235 options: ['require-specific-unit']236 },237 {238 answer: '5m',239 check_status: STATUS_CORRECT240 },241 ],242 ]243 test.each(specs)('', (q, check) => {244 const generated = generateQuestion(q)245 const item = {246 ...generated,247 ...check248 }249 assessItem(item)250 expect(item.status).toBe(item.check_status)251 })252})253describe('testing incorrect answer with specified unit (require-specific-unit)', () => {254 const specs = [[255 {256 expressions: ['2 m + 3 m'],257 unit: 'm',258 options: ['require-specific-unit']259 },260 {261 answer: '6m',262 check_status: STATUS_INCORRECT263 },264 ],265 ]266 test.each(specs)('', (q, check) => {267 const generated = generateQuestion(q)268 const item = {269 ...generated,270 ...check271 }272 assessItem(item)273 expect(item.status).toBe(item.check_status)274 })275})276describe('testing incorrect answer with specified unit (require-specific-unit) (2)', () => {277 const specs = [[278 {279 expressions: ['2 m + 3 m'],280 unit: 'm',281 options: ['require-specific-unit']282 },283 {284 answer: '5 cm',285 check_status: STATUS_INCORRECT286 },287 ],288 ]289 test.each(specs)('', (q, check) => {290 const generated = generateQuestion(q)291 const item = {292 ...generated,293 ...check294 }295 assessItem(item)296 expect(item.status).toBe(item.check_status)297 })298})299describe('testing forgotten unit answer with specified unit (require-specific-unit)', () => {300 const specs = [[301 {302 expressions: ['2 m + 3 m'],303 unit: 'm',304 options: ['require-specific-unit']305 },306 {307 answer: '5',308 check_status: STATUS_INCORRECT309 },310 ],311 ]312 test.each(specs)('', (q, check) => {313 const generated = generateQuestion(q)314 const item = {315 ...generated,316 ...check317 }318 assessItem(item)319 expect(item.status).toBe(item.check_status)320 })321})322describe('testing bad unit answer with specified unit (require-specific-unit)', () => {323 const specs = [[324 {325 expressions: ['2 m + 3 m'],326 unit: 'm',327 options: ['require-specific-unit']328 },329 {330 answer: '500 cm',331 check_status: STATUS_BAD_UNIT332 },333 ],334 ]335 test.each(specs)('', (q, check) => {336 const generated = generateQuestion(q)337 const item = {338 ...generated,339 ...check340 }341 assessItem(item)342 expect(item.status).toBe(item.check_status)343 })344})345describe('testing correct answer with specified unit (no-penalty-for-not-respected-unit)', () => {346 const specs = [[347 {348 expressions: ['2 m + 3 m'],349 unit: 'm',350 options: ['no-penalty-for-not-respected-unit']351 },352 {353 answer: '5m',354 check_status: STATUS_CORRECT355 },356 ],357 ]358 test.each(specs)('', (q, check) => {359 const generated = generateQuestion(q)360 const item = {361 ...generated,362 ...check363 }364 assessItem(item)365 expect(item.status).toBe(item.check_status)366 })367})368describe('testing incorrect answer with specified unit (no-penalty-for-not-respected-unit)', () => {369 const specs = [[370 {371 expressions: ['2 m + 3 m'],372 unit: 'm',373 options: ['no-penalty-for-not-respected-unit']374 },375 {376 answer: '6m',377 check_status: STATUS_INCORRECT378 },379 ],380 ]381 test.each(specs)('', (q, check) => {382 const generated = generateQuestion(q)383 const item = {384 ...generated,385 ...check386 }387 assessItem(item)388 expect(item.status).toBe(item.check_status)389 })390})391describe('testing incorrect answer with specified unit (no-penalty-for-not-respected-unit) (2)', () => {392 const specs = [[393 {394 expressions: ['2 m + 3 m'],395 unit: 'm',396 options: ['no-penalty-for-not-respected-unit']397 },398 {399 answer: '5 cm',400 check_status: STATUS_INCORRECT401 },402 ],403 ]404 test.each(specs)('', (q, check) => {405 const generated = generateQuestion(q)406 const item = {407 ...generated,408 ...check409 }410 assessItem(item)411 expect(item.status).toBe(item.check_status)412 })413})414describe('testing forgotten unit answer with specified unit (no-penalty-for-not-respected-unit)', () => {415 const specs = [[416 {417 expressions: ['2 m + 3 m'],418 unit: 'm',419 options: ['no-penalty-for-not-respected-unit']420 },421 {422 answer: '5',423 check_status: STATUS_INCORRECT424 },425 ],426 ]427 test.each(specs)('', (q, check) => {428 const generated = generateQuestion(q)429 const item = {430 ...generated,431 ...check432 }433 assessItem(item)434 expect(item.status).toBe(item.check_status)435 })436})437describe('testing bad unit answer with specified unit (no-penalty-for-not-respected-unit)', () => {438 const specs = [[439 {440 expressions: ['2 m + 3 m'],441 unit: 'm',442 options: ['no-penalty-for-not-respected-unit']443 },444 {445 answer: '500 cm',446 check_status: STATUS_CORRECT447 },448 ],449 ]450 test.each(specs)('', (q, check) => {451 const generated = generateQuestion(q)452 const item = {453 ...generated,454 ...check455 }456 assessItem(item)457 expect(item.status).toBe(item.check_status)458 })459})460describe('testing correct answer with specified unit', () => {461 const specs = [[462 {463 expressions: ['2 m + 3 m'],464 unit: 'm',465 },466 {467 answer: '5m',468 check_status: STATUS_CORRECT469 },470 ],471 ]472 test.each(specs)('', (q, check) => {473 const generated = generateQuestion(q)474 const item = {475 ...generated,476 ...check477 }478 assessItem(item)479 expect(item.status).toBe(item.check_status)480 })481})482describe('testing incorrect answer with specified unit', () => {483 const specs = [[484 {485 expressions: ['2 m + 3 m'],486 unit: 'm',487 },488 {489 answer: '6m',490 check_status: STATUS_INCORRECT491 },492 ],493 ]494 test.each(specs)('', (q, check) => {495 const generated = generateQuestion(q)496 const item = {497 ...generated,498 ...check499 }500 assessItem(item)501 expect(item.status).toBe(item.check_status)502 })503})504describe('testing forgotten unit answer with specified unit', () => {505 const specs = [[506 {507 expressions: ['2 m + 3 m'],508 unit: 'm',509 },510 {511 answer: '5',512 check_status: STATUS_INCORRECT513 },514 ],515 ]516 test.each(specs)('', (q, check) => {517 const generated = generateQuestion(q)518 const item = {519 ...generated,520 ...check521 }522 assessItem(item)523 expect(item.status).toBe(item.check_status)524 })525})526describe('testing incorrect answer with specified unit', () => {527 const specs = [[528 {529 expressions: ['2 m + 3 m'],530 unit: 'm',531 },532 {533 answer: '5 cm',534 check_status: STATUS_INCORRECT535 },536 ],537 ]538 test.each(specs)('', (q, check) => {539 const generated = generateQuestion(q)540 const item = {541 ...generated,542 ...check543 }544 assessItem(item)545 expect(item.status).toBe(item.check_status)546 })547})548describe('testing bad unit answer with specified unit', () => {549 const specs = [[550 {551 expressions: ['2 m + 3 m'],552 unit: 'm',553 },554 {555 answer: '500 cm',556 check_status: STATUS_UNOPTIMAL_FORM557 },558 ],559 ]560 test.each(specs)('', (q, check) => {561 const generated = generateQuestion(q)562 const item = {563 ...generated,564 ...check565 }566 assessItem(item)567 expect(item.status).toBe(item.check_status)568 })569})570describe('testing correct answer with extraneous zeros (require-no-extraneaous-zeros)', () => {571 const specs = [[572 {573 expressions: ['2+3'],574 options: ['require-no-extraneaous-zeros']575 },576 {577 answer: '5,0',578 check_status: STATUS_BAD_FORM579 },580 ],581 [582 {583 expressions: ['5,1'],584 options: ['require-no-extraneaous-zeros']585 },586 {587 answer: '5,10',588 check_status: STATUS_BAD_FORM589 },590 ],591 [592 {593 expressions: ['2+3'],594 options: ['require-no-extraneaous-zeros']595 },596 {597 answer: '05',598 check_status: STATUS_BAD_FORM599 },600 ]601 ]602 test.each(specs)('', (q, check) => {603 const generated = generateQuestion(q)604 const item = {605 ...generated,606 ...check607 }608 assessItem(item)609 expect(item.status).toBe(item.check_status)610 })611})612describe('testing correct answer with extraneous zeros (no-penalty-for-extraneous-zeros)', () => {613 const specs = [[614 {615 expressions: ['2+3'],616 options: ['no-penalty-for-extraneous-zeros']617 },618 {619 answer: '5,0',620 check_status: STATUS_CORRECT621 },622 ],623 [624 {625 expressions: ['2+3'],626 options: ['no-penalty-for-extraneous-zeros']627 },628 {629 answer: '05',630 check_status: STATUS_CORRECT631 },632 ]633 ]634 test.each(specs)('', (q, check) => {635 const generated = generateQuestion(q)636 const item = {637 ...generated,638 ...check639 }640 assessItem(item)641 expect(item.status).toBe(item.check_status)642 })643})644describe('testing correct answer with extraneous zeros', () => {645 const specs = [[646 {647 expressions: ['2+3'],648 },649 {650 answer: '5,0',651 check_status: STATUS_UNOPTIMAL_FORM652 },653 ],654 [655 {656 expressions: ['2+3'],657 },658 {659 answer: '05',660 check_status: STATUS_UNOPTIMAL_FORM661 },662 ]663 ]664 test.each(specs)('', (q, check) => {665 const generated = generateQuestion(q)666 const item = {667 ...generated,668 ...check669 }670 assessItem(item)671 expect(item.status).toBe(item.check_status)672 })673})674describe('testing correct answer with extraneous brackets (require-no-extraneaous-brackets)', () => {675 const specs = [676 [677 {678 expressions: ['2+3'],679 options: ['require-no-extraneaous-brackets']680 },681 {682 answer: '(5)',683 check_status: STATUS_BAD_FORM684 },685 ],686 [687 {688 expressions: ['-2+a'],689 options: ['require-no-extraneaous-brackets']690 },691 {692 answer: '(-2)+a',693 check_status: STATUS_BAD_FORM694 },695 ],696 [697 {698 expressions: ['a-(c+d)'],699 options: ['require-no-extraneaous-brackets']700 },701 {702 answer: 'a-((c+d))',703 check_status: STATUS_BAD_FORM704 },705 ],706 [707 {708 expressions: ['a+(c+d)'],709 options: ['require-no-extraneaous-brackets']710 },711 {712 answer: 'a+(c+d)',713 check_status: STATUS_BAD_FORM714 },715 ],716 [717 {718 expressions: ['(a+c)+d'],719 options: ['require-no-extraneaous-brackets']720 },721 {722 answer: '(a+c)+d',723 check_status: STATUS_BAD_FORM724 },725 ],726 [727 {728 expressions: ['a+(c-d)'],729 options: ['require-no-extraneaous-brackets']730 },731 {732 answer: 'a+(c-d)',733 check_status: STATUS_BAD_FORM734 },735 ],736 [737 {738 expressions: ['(a-c)+d'],739 options: ['require-no-extraneaous-brackets']740 },741 {742 answer: '(a-c)+d',743 check_status: STATUS_BAD_FORM744 },745 ],746 [747 {748 expressions: ['a+(c*d)'],749 options: ['require-no-extraneaous-brackets']750 },751 {752 answer: 'a+(c*d)',753 check_status: STATUS_BAD_FORM754 },755 ],756 [757 {758 expressions: ['(c*d)+a'],759 options: ['require-no-extraneaous-brackets']760 },761 {762 answer: '(c*d)+a',763 check_status: STATUS_BAD_FORM764 },765 ],766 [767 {768 expressions: ['a+(c:d)'],769 options: ['require-no-extraneaous-brackets']770 },771 {772 answer: 'a+(c:d)',773 check_status: STATUS_BAD_FORM774 },775 ],776 [777 {778 expressions: ['(c:d)+a'],779 options: ['require-no-extraneaous-brackets']780 },781 {782 answer: '(c:d)+a',783 check_status: STATUS_BAD_FORM784 },785 ],786 [787 {788 expressions: ['a+(c/d)'],789 options: ['require-no-extraneaous-brackets']790 },791 {792 answer: 'a+(c/d)',793 check_status: STATUS_BAD_FORM794 },795 ],796 [797 {798 expressions: ['(c/d)+a'],799 options: ['require-no-extraneaous-brackets']800 },801 {802 answer: '(c/d)+a',803 check_status: STATUS_BAD_FORM804 },805 ],806 [807 {808 expressions: ['a+(c^d)'],809 options: ['require-no-extraneaous-brackets']810 },811 {812 answer: 'a+(c^d)',813 check_status: STATUS_BAD_FORM814 },815 ],816 [817 {818 expressions: ['(c^d)+a'],819 options: ['require-no-extraneaous-brackets']820 },821 {822 answer: '(c^d)+a',823 check_status: STATUS_BAD_FORM824 },825 ],826 [827 {828 expressions: ['(a+c)-d'],829 options: ['require-no-extraneaous-brackets']830 },831 {832 answer: '(a+c)-d',833 check_status: STATUS_BAD_FORM834 },835 ],836 [837 {838 expressions: ['(a-c)-d'],839 options: ['require-no-extraneaous-brackets']840 },841 {842 answer: '(a-c)-d',843 check_status: STATUS_BAD_FORM844 },845 ],846 [847 {848 expressions: ['a-(c*d)'],849 options: ['require-no-extraneaous-brackets']850 },851 {852 answer: 'a-(c*d)',853 check_status: STATUS_BAD_FORM854 },855 ],856 [857 {858 expressions: ['(c*d)-a'],859 options: ['require-no-extraneaous-brackets']860 },861 {862 answer: '(c*d)-a',863 check_status: STATUS_BAD_FORM864 },865 ],866 [867 {868 expressions: ['a-(c:d)'],869 options: ['require-no-extraneaous-brackets']870 },871 {872 answer: 'a-(c:d)',873 check_status: STATUS_BAD_FORM874 },875 ],876 [877 {878 expressions: ['(c:d)-a'],879 options: ['require-no-extraneaous-brackets']880 },881 {882 answer: '(c:d)-a',883 check_status: STATUS_BAD_FORM884 },885 ],886 [887 {888 expressions: ['a-(c/d)'],889 options: ['require-no-extraneaous-brackets']890 },891 {892 answer: 'a-(c/d)',893 check_status: STATUS_BAD_FORM894 },895 ],896 [897 {898 expressions: ['(c/d)-a'],899 options: ['require-no-extraneaous-brackets']900 },901 {902 answer: '(c/d)-a',903 check_status: STATUS_BAD_FORM904 },905 ],906 [907 {908 expressions: ['a-(c^d)'],909 options: ['require-no-extraneaous-brackets']910 },911 {912 answer: 'a-(c^d)',913 check_status: STATUS_BAD_FORM914 },915 ],916 [917 {918 expressions: ['(c^d)-a'],919 options: ['require-no-extraneaous-brackets']920 },921 {922 answer: '(c^d)-a',923 check_status: STATUS_BAD_FORM924 },925 ],926 [927 {928 expressions: ['a*(c*d)'],929 options: ['require-no-extraneaous-brackets']930 },931 {932 answer: 'a*(c*d)',933 check_status: STATUS_BAD_FORM934 },935 ],936 [937 {938 expressions: ['(c*d)*a'],939 options: ['require-no-extraneaous-brackets']940 },941 {942 answer: '(c*d)*a',943 check_status: STATUS_BAD_FORM944 },945 ],946 [947 {948 expressions: ['a*(c:d)'],949 options: ['require-no-extraneaous-brackets']950 },951 {952 answer: 'a*(c:d)',953 check_status: STATUS_BAD_FORM954 },955 ],956 [957 {958 expressions: ['(c:d)*a'],959 options: ['require-no-extraneaous-brackets']960 },961 {962 answer: '(c:d)*a',963 check_status: STATUS_BAD_FORM964 },965 ],966 [967 {968 expressions: ['a*(c/d)'],969 options: ['require-no-extraneaous-brackets']970 },971 {972 answer: 'a*(c/d)',973 check_status: STATUS_BAD_FORM974 },975 ],976 [977 {978 expressions: ['(c/d)*a'],979 options: ['require-no-extraneaous-brackets']980 },981 {982 answer: '(c/d)*a',983 check_status: STATUS_BAD_FORM984 },985 ],986 [987 {988 expressions: ['a*(c^d)'],989 options: ['require-no-extraneaous-brackets']990 },991 {992 answer: 'a*(c^d)',993 check_status: STATUS_BAD_FORM994 },995 ],996 [997 {998 expressions: ['(c^d)*a'],999 options: ['require-no-extraneaous-brackets']1000 },1001 {1002 answer: '(c^d)*a',1003 check_status: STATUS_BAD_FORM1004 },1005 ],1006 [1007 {1008 expressions: ['(c*d):a'],1009 options: ['require-no-extraneaous-brackets']1010 },1011 {1012 answer: '(c*d):a',1013 check_status: STATUS_BAD_FORM1014 },1015 ],1016 [1017 {1018 expressions: ['(c:d):a'],1019 options: ['require-no-extraneaous-brackets']1020 },1021 {1022 answer: '(c:d):a',1023 check_status: STATUS_BAD_FORM1024 },1025 ],1026 [1027 {1028 expressions: ['(c/d):a'],1029 options: ['require-no-extraneaous-brackets']1030 },1031 {1032 answer: '(c/d):a',1033 check_status: STATUS_BAD_FORM1034 },1035 ],1036 [1037 {1038 expressions: ['a:(c^d)'],1039 options: ['require-no-extraneaous-brackets']1040 },1041 {1042 answer: 'a:(c^d)',1043 check_status: STATUS_BAD_FORM1044 },1045 ],1046 [1047 {1048 expressions: ['(c^d):a'],1049 options: ['require-no-extraneaous-brackets']1050 },1051 {1052 answer: '(c^d):a',1053 check_status: STATUS_BAD_FORM1054 },1055 ],1056 [1057 {1058 expressions: ['(c*d)/a'],1059 options: ['require-no-extraneaous-brackets']1060 },1061 {1062 answer: '(c*d)/a',1063 check_status: STATUS_BAD_FORM1064 },1065 ],1066 [1067 {1068 expressions: ['(c:d)/a'],1069 options: ['require-no-extraneaous-brackets']1070 },1071 {1072 answer: '(c:d)/a',1073 check_status: STATUS_BAD_FORM1074 },1075 ],1076 [1077 {1078 expressions: ['(c/d)/a'],1079 options: ['require-no-extraneaous-brackets']1080 },1081 {1082 answer: '(c/d)/a',1083 check_status: STATUS_BAD_FORM1084 },1085 ],1086 [1087 {1088 expressions: ['a/(c^d)'],1089 options: ['require-no-extraneaous-brackets']1090 },1091 {1092 answer: 'a/(c^d)',1093 check_status: STATUS_BAD_FORM1094 },1095 ],1096 [1097 {1098 expressions: ['(c^d)/a'],1099 options: ['require-no-extraneaous-brackets']1100 },1101 {1102 answer: '(c^d)/a',1103 check_status: STATUS_BAD_FORM1104 },1105 ],1106 [1107 {1108 expressions: ['a/b'],1109 options: ['require-no-extraneaous-brackets']1110 },1111 {1112 answer: '(a)/b',1113 check_status: STATUS_BAD_FORM1114 },1115 ],1116 [1117 {1118 expressions: ['a/b'],1119 options: ['require-no-extraneaous-brackets']1120 },1121 {1122 answer: 'a/(b)',1123 check_status: STATUS_BAD_FORM1124 },1125 ],1126 [1127 {1128 expressions: ['a/b'],1129 options: ['require-no-extraneaous-brackets']1130 },1131 {1132 answer: '(a)/(b)',1133 check_status: STATUS_BAD_FORM1134 },1135 ],1136 [1137 {1138 expressions: ['{a+b}/b'],1139 options: ['require-no-extraneaous-brackets']1140 },1141 {1142 answer: '(a+b)/b',1143 check_status: STATUS_BAD_FORM1144 },1145 ],1146 [1147 {1148 expressions: ['a/{a+b}'],1149 options: ['require-no-extraneaous-brackets']1150 },1151 {1152 answer: 'a/(a+b)',1153 check_status: STATUS_BAD_FORM1154 },1155 ],1156 [1157 {1158 expressions: ['{a+b}/{a+b}'],1159 options: ['require-no-extraneaous-brackets']1160 },1161 {1162 answer: '(a+b)/(a+b)',1163 check_status: STATUS_BAD_FORM1164 },1165 ],1166 [1167 {1168 expressions: ['a^b'],1169 options: ['require-no-extraneaous-brackets']1170 },1171 {1172 answer: 'a^(b)',1173 check_status: STATUS_BAD_FORM1174 },1175 ],1176 [1177 {1178 expressions: ['a^b'],1179 options: ['require-no-extraneaous-brackets']1180 },1181 {1182 answer: '(a)^b',1183 check_status: STATUS_BAD_FORM1184 },1185 ],1186 [1187 {1188 expressions: ['a^b'],1189 options: ['require-no-extraneaous-brackets']1190 },1191 {1192 answer: '(a)^(b)',1193 check_status: STATUS_BAD_FORM1194 },1195 ],1196 [1197 {1198 expressions: ['a^{a+b}'],1199 options: ['require-no-extraneaous-brackets']1200 },1201 {1202 answer: 'a^(a+b)',1203 check_status: STATUS_BAD_FORM1204 },1205 ],1206 ]1207 test.each(specs)('', (q, check) => {1208 const generated = generateQuestion(q)1209 const item = {1210 ...generated,1211 ...check1212 }1213 assessItem(item)1214 expect(item.status).toBe(item.check_status)1215 })1216})1217describe('testing correct answer with extraneous brackets (no-penalty-for-extraneous-brackets)', () => {1218 const specs = [1219 ['2+3',1220 {1221 expressions: ['2+3'],1222 options: ['no-penalty-for-extraneous-brackets']1223 },1224 {1225 answer: '(5)',1226 check_status: STATUS_CORRECT1227 },1228 ],1229 ['-2+a',1230 {1231 expressions: ['-2+a'],1232 options: ['no-penalty-for-extraneous-brackets']1233 },1234 {1235 answer: '(-2)+a',1236 check_status: STATUS_CORRECT1237 },1238 ],1239 ['a-(c+d)',1240 {1241 expressions: ['a-(c+d)'],1242 solutions: [['a-(c+d)']],1243 options: ['no-penalty-for-extraneous-brackets']1244 },1245 {1246 answer: 'a-((c+d))',1247 check_status: STATUS_CORRECT1248 },1249 ],1250 ['a+c+d',1251 {1252 expressions: ['a+c+d'],1253 options: ['no-penalty-for-extraneous-brackets']1254 },1255 {1256 answer: 'a+(c+d)',1257 check_status: STATUS_CORRECT1258 },1259 ],1260 ['a+c+d',1261 {1262 expressions: ['a+c+d'],1263 options: ['no-penalty-for-extraneous-brackets']1264 },1265 {1266 answer: '(a+c)+d',1267 check_status: STATUS_CORRECT1268 },1269 ],1270 ['a+c-d',1271 {1272 expressions: ['a+c-d'],1273 options: ['no-penalty-for-extraneous-brackets']1274 },1275 {1276 answer: 'a+(c-d)',1277 check_status: STATUS_CORRECT1278 },1279 ],1280 ['a-c+d',1281 {1282 expressions: ['a-c+d'],1283 options: ['no-penalty-for-extraneous-brackets']1284 },1285 {1286 answer: '(a-c)+d',1287 check_status: STATUS_CORRECT1288 },1289 ],1290 ['a+c*d',1291 {1292 expressions: ['a+c*d'],1293 options: ['no-penalty-for-extraneous-brackets']1294 },1295 {1296 answer: 'a+(cd)',1297 check_status: STATUS_CORRECT1298 },1299 ],1300 ['c*d+a',1301 {1302 expressions: ['c*d+a'],1303 options: ['no-penalty-for-extraneous-brackets']1304 },1305 {1306 answer: '(cd)+a',1307 check_status: STATUS_CORRECT1308 },1309 ],1310 ['a+c:d',1311 {1312 expressions: ['a+c:d'],1313 solutions: [['a+c:d']],1314 options: ['no-penalty-for-extraneous-brackets']1315 },1316 {1317 answer: 'a+(c:d)',1318 check_status: STATUS_CORRECT1319 },1320 ],1321 ['c:d+a',1322 {1323 expressions: ['c:d+a'],1324 solutions: [['c:d+a']],1325 options: ['no-penalty-for-extraneous-brackets']1326 },1327 {1328 answer: '(c:d)+a',1329 check_status: STATUS_CORRECT1330 },1331 ],1332 ['a+c/d',1333 {1334 expressions: ['a+c/d'],1335 solutions: [['a+c/d']],1336 options: ['no-penalty-for-extraneous-brackets']1337 },1338 {1339 answer: 'a+(c/d)',1340 check_status: STATUS_CORRECT1341 },1342 ],1343 ['c/d+a',1344 {1345 expressions: ['c/d+a'],1346 solutions: [['c/d+a']],1347 options: ['no-penalty-for-extraneous-brackets']1348 },1349 {1350 answer: '(c/d)+a',1351 check_status: STATUS_CORRECT1352 },1353 ],1354 ['a+c^d',1355 {1356 expressions: ['a+c^d'],1357 options: ['no-penalty-for-extraneous-brackets']1358 },1359 {1360 answer: 'a+(c^d)',1361 check_status: STATUS_CORRECT1362 },1363 ],1364 ['c^d+a',1365 {1366 expressions: ['c^d+a'],1367 options: ['no-penalty-for-extraneous-brackets']1368 },1369 {1370 answer: '(c^d)+a',1371 check_status: STATUS_CORRECT1372 },1373 ],1374 ['a+c-d',1375 {1376 expressions: ['a+c-d'],1377 options: ['no-penalty-for-extraneous-brackets']1378 },1379 {1380 answer: '(a+c)-d',1381 check_status: STATUS_CORRECT1382 },1383 ],1384 ['a-c-d',1385 {1386 expressions: ['a-c-d'],1387 options: ['no-penalty-for-extraneous-brackets']1388 },1389 {1390 answer: '(a-c)-d',1391 check_status: STATUS_CORRECT1392 },1393 ],1394 ['a-c*d',1395 {1396 expressions: ['a-c*d'],1397 options: ['no-penalty-for-extraneous-brackets']1398 },1399 {1400 answer: 'a-(cd)',1401 check_status: STATUS_CORRECT1402 },1403 ],1404 ['c*d-a',1405 {1406 expressions: ['c*d-a'],1407 options: ['no-penalty-for-extraneous-brackets']1408 },1409 {1410 answer: '(cd)-a',1411 check_status: STATUS_CORRECT1412 },1413 ],1414 ['a-c:d',1415 {1416 expressions: ['a-c:d'],1417 solutions: [['a-c:d']],1418 options: ['no-penalty-for-extraneous-brackets']1419 },1420 {1421 answer: 'a-(c:d)',1422 check_status: STATUS_CORRECT1423 },1424 ],1425 ['c:d-a',1426 {1427 expressions: ['c:d-a'],1428 solutions: [['c:d-a']],1429 options: ['no-penalty-for-extraneous-brackets']1430 },1431 {1432 answer: '(c:d)-a',1433 check_status: STATUS_CORRECT1434 },1435 ],1436 ['a-c/d',1437 {1438 expressions: ['a-c/d'],1439 solutions: [['a-c/d']],1440 options: ['no-penalty-for-extraneous-brackets']1441 },1442 {1443 answer: 'a-(c/d)',1444 check_status: STATUS_CORRECT1445 },1446 ],1447 ['c/d-a',1448 {1449 expressions: ['c/d-a'],1450 solutions: [['c/d-a']],1451 options: ['no-penalty-for-extraneous-brackets']1452 },1453 {1454 answer: '(c/d)-a',1455 check_status: STATUS_CORRECT1456 },1457 ],1458 ['a-c^d',1459 {1460 expressions: ['a-c^d'],1461 options: ['no-penalty-for-extraneous-brackets']1462 },1463 {1464 answer: 'a-(c^d)',1465 check_status: STATUS_CORRECT1466 },1467 ],1468 ['c^d-a',1469 {1470 expressions: ['c^d-a'],1471 options: ['no-penalty-for-extraneous-brackets']1472 },1473 {1474 answer: '(c^d)-a',1475 check_status: STATUS_CORRECT1476 },1477 ],1478 ['a*c*d',1479 {1480 expressions: ['a*c*d'],1481 options: ['no-penalty-for-extraneous-brackets']1482 },1483 {1484 answer: 'a(cd)',1485 check_status: STATUS_CORRECT1486 },1487 ],1488 ['c*d*a',1489 {1490 expressions: ['c*d*a'],1491 options: ['no-penalty-for-extraneous-brackets']1492 },1493 {1494 answer: '(cd)a',1495 check_status: STATUS_CORRECT1496 },1497 ],1498 ['a*c:d',1499 {1500 expressions: ['a*c:d'],1501 solutions: [['a*c:d']],1502 options: ['no-penalty-for-extraneous-brackets']1503 },1504 {1505 answer: 'a(c:d)',1506 check_status: STATUS_CORRECT1507 },1508 ],1509 ['c:d*a',1510 {1511 expressions: ['c:d*a'],1512 solutions: [['c:d*a']],1513 options: ['no-penalty-for-extraneous-brackets']1514 },1515 {1516 answer: '(c:d)a',1517 check_status: STATUS_CORRECT1518 },1519 ],1520 ['a*c/d',1521 {1522 expressions: ['a*c/d'],1523 solutions: [['a*c/d']],1524 options: ['no-penalty-for-extraneous-brackets']1525 },1526 {1527 answer: 'a(c/d)',1528 check_status: STATUS_CORRECT1529 },1530 ],1531 ['c/d*a',1532 {1533 expressions: ['c/d*a'],1534 solutions: [['c/d*a']],1535 options: ['no-penalty-for-extraneous-brackets']1536 },1537 {1538 answer: '(c/d)a',1539 check_status: STATUS_CORRECT1540 },1541 ],1542 ['a*c^d',1543 {1544 expressions: ['a*c^d'],1545 options: ['no-penalty-for-extraneous-brackets']1546 },1547 {1548 answer: 'a(c^d)',1549 check_status: STATUS_CORRECT1550 },1551 ],1552 ['c^d*a',1553 {1554 expressions: ['c^d*a'],1555 options: ['no-penalty-for-extraneous-brackets']1556 },1557 {1558 answer: '(c^d)a',1559 check_status: STATUS_CORRECT1560 },1561 ],1562 ['c*d:a',1563 {1564 expressions: ['c*d:a'],1565 solutions: [['c*d:a']],1566 options: ['no-penalty-for-extraneous-brackets']1567 },1568 {1569 answer: '(cd):a',1570 check_status: STATUS_CORRECT1571 },1572 ],1573 ['c:d:a',1574 {1575 expressions: ['c:d:a'],1576 solutions: [['c:d:a']],1577 options: ['no-penalty-for-extraneous-brackets']1578 },1579 {1580 answer: '(c:d):a',1581 check_status: STATUS_CORRECT1582 },1583 ],1584 ['c/d:a',1585 {1586 expressions: ['c/d:a'],1587 solutions: [['c/d:a']],1588 options: ['no-penalty-for-extraneous-brackets']1589 },1590 {1591 answer: '(c/d):a',1592 check_status: STATUS_CORRECT1593 },1594 ],1595 ['a:c^d',1596 {1597 expressions: ['a:c^d'],1598 solutions: [['a:c^d']],1599 options: ['no-penalty-for-extraneous-brackets']1600 },1601 {1602 answer: 'a:(c^d)',1603 check_status: STATUS_CORRECT1604 },1605 ],1606 ['c^d:a',1607 {1608 expressions: ['c^d:a'],1609 solutions: [['c^d:a']],1610 options: ['no-penalty-for-extraneous-brackets']1611 },1612 {1613 answer: '(c^d):a',1614 check_status: STATUS_CORRECT1615 },1616 ],1617 ['c*d/a',1618 {1619 expressions: ['c*d/a'],1620 solutions: [['c*d/a']],1621 options: ['no-penalty-for-extraneous-brackets']1622 },1623 {1624 answer: '(cd)/a',1625 check_status: STATUS_CORRECT1626 },1627 ],1628 ['c:d/a',1629 {1630 expressions: ['c:d/a'],1631 solutions: [['c:d/a']],1632 options: ['no-penalty-for-extraneous-brackets']1633 },1634 {1635 answer: '(c:d)/a',1636 check_status: STATUS_CORRECT1637 },1638 ],1639 ['c/d/a',1640 {1641 expressions: ['c/d/a'],1642 solutions: [['c/d/a']],1643 options: ['no-penalty-for-extraneous-brackets']1644 },1645 {1646 answer: '(c/d)/a',1647 check_status: STATUS_CORRECT1648 },1649 ],1650 ['a/c^d',1651 {1652 expressions: ['a/c^d'],1653 solutions: [['a/c^d']],1654 options: ['no-penalty-for-extraneous-brackets']1655 },1656 {1657 answer: 'a/(c^d)',1658 check_status: STATUS_CORRECT1659 },1660 ],1661 ['c^d/a',1662 {1663 expressions: ['c^d/a'],1664 solutions: [['c^d/a']],1665 options: ['no-penalty-for-extraneous-brackets']1666 },1667 {1668 answer: '(c^d)/a',1669 check_status: STATUS_CORRECT1670 },1671 ],1672 ['a/b',1673 {1674 expressions: ['a/b'],1675 solutions: [['a/b']],1676 options: ['no-penalty-for-extraneous-brackets']1677 },1678 {1679 answer: '(a)/b',1680 check_status: STATUS_CORRECT1681 },1682 ],1683 ['a/b',1684 {1685 expressions: ['a/b'],1686 solutions: [['a/b']],1687 options: ['no-penalty-for-extraneous-brackets']1688 },1689 {1690 answer: 'a/(b)',1691 check_status: STATUS_CORRECT1692 },1693 ],1694 ['a/b',1695 {1696 expressions: ['a/b'],1697 solutions: [['a/b']],1698 options: ['no-penalty-for-extraneous-brackets']1699 },1700 {1701 answer: '(a)/(b)',1702 check_status: STATUS_CORRECT1703 },1704 ],1705 ['{a+b}/b',1706 {1707 expressions: ['{a+b}/b'],1708 solutions: [['{a+b}/b']],1709 options: ['no-penalty-for-extraneous-brackets']1710 },1711 {1712 answer: '(a+b)/b',1713 check_status: STATUS_CORRECT1714 },1715 ],1716 ['a/{a+b}',1717 {1718 expressions: ['a/{a+b}'],1719 solutions: [['a/{a+b}']],1720 options: ['no-penalty-for-extraneous-brackets']1721 },1722 {1723 answer: 'a/(a+b)',1724 check_status: STATUS_CORRECT1725 },1726 ],1727 ['{a+b}/{a+b}',1728 {1729 expressions: ['{a+b}/{a+b}'],1730 solutions: [['{a+b}/{a+b}']],1731 options: ['no-penalty-for-extraneous-brackets']1732 },1733 {1734 answer: '(a+b)/(a+b)',1735 check_status: STATUS_CORRECT1736 },1737 ],1738 ['a^b',1739 {1740 expressions: ['a^b'],1741 options: ['no-penalty-for-extraneous-brackets']1742 },1743 {1744 answer: 'a^(b)',1745 check_status: STATUS_CORRECT1746 },1747 ],1748 ['a^b',1749 {1750 expressions: ['a^b'],1751 options: ['no-penalty-for-extraneous-brackets']1752 },1753 {1754 answer: '(a)^b',1755 check_status: STATUS_CORRECT1756 },1757 ],1758 ['a^b',1759 {1760 expressions: ['a^b'],1761 options: ['no-penalty-for-extraneous-brackets']1762 },1763 {1764 answer: '(a)^(b)',1765 check_status: STATUS_CORRECT1766 },1767 ],1768 ['a^{a+b}',1769 {1770 expressions: ['a^{a+b}'],1771 options: ['no-penalty-for-extraneous-brackets']1772 },1773 {1774 answer: 'a^(a+b)',1775 check_status: STATUS_CORRECT1776 },1777 ],1778 ]1779 test.each(specs)('%s', (s, q, check) => {1780 const generated = generateQuestion(q)1781 const item = {1782 ...generated,1783 ...check1784 }1785 assessItem(item)1786 expect(item.status).toBe(item.check_status)1787 })1788})1789describe('testing correct answer with extraneous brackets (no-penalty-for-extraneous-brackets-in-first-negative-term)', () => {1790 const specs = [[1791 {1792 expressions: ['2+3'],1793 options: ['no-penalty-for-extraneous-brackets-in-first-negative-term']1794 },1795 {1796 answer: '(5)',1797 check_status: STATUS_UNOPTIMAL_FORM1798 },1799 ],1800 [1801 {1802 expressions: ['-2+a'],1803 options: ['no-penalty-for-extraneous-brackets-in-first-negative-term']1804 },1805 {1806 answer: '(-2)+a',1807 check_status: STATUS_CORRECT1808 },1809 ],1810 ]1811 test.each(specs)('', (q, check) => {1812 const generated = generateQuestion(q)1813 const item = {1814 ...generated,1815 ...check1816 }1817 assessItem(item)1818 expect(item.status).toBe(item.check_status)1819 })1820})1821describe('testing correct answer with extraneous brackets', () => {1822 const specs = [1823 ['2+3',1824 {1825 expressions: ['2+3'],1826 },1827 {1828 answer: '(5)',1829 check_status: STATUS_UNOPTIMAL_FORM1830 },1831 ],1832 ['-2+a',1833 {1834 expressions: ['-2+a'],1835 },1836 {1837 answer: '(-2)+a',1838 check_status: STATUS_UNOPTIMAL_FORM1839 },1840 ],1841 ['a-(c+d)',1842 {1843 expressions: ['a-(c+d)'],1844 solutions: [['a-(c+d)']],1845 },1846 {1847 answer: 'a-((c+d))',1848 check_status: STATUS_UNOPTIMAL_FORM1849 },1850 ],1851 ['a+c+d',1852 {1853 expressions: ['a+c+d'],1854 },1855 {1856 answer: 'a+(c+d)',1857 check_status: STATUS_UNOPTIMAL_FORM1858 },1859 ],1860 ['a+c+d',1861 {1862 expressions: ['a+c+d'],1863 },1864 {1865 answer: '(a+c)+d',1866 check_status: STATUS_UNOPTIMAL_FORM1867 },1868 ],1869 ['a+c-d',1870 {1871 expressions: ['a+c-d'],1872 },1873 {1874 answer: 'a+(c-d)',1875 check_status: STATUS_UNOPTIMAL_FORM1876 },1877 ],1878 ['a-c+d',1879 {1880 expressions: ['a-c+d'],1881 },1882 {1883 answer: '(a-c)+d',1884 check_status: STATUS_UNOPTIMAL_FORM1885 },1886 ],1887 ['a+c*d',1888 {1889 expressions: ['a+c*d'],1890 },1891 {1892 answer: 'a+(cd)',1893 check_status: STATUS_UNOPTIMAL_FORM1894 },1895 ],1896 ['c*d+a',1897 {1898 expressions: ['c*d+a'],1899 },1900 {1901 answer: '(cd)+a',1902 check_status: STATUS_UNOPTIMAL_FORM1903 },1904 ],1905 ['a+c:d',1906 {1907 expressions: ['a+c:d'],1908 solutions: [['a+c:d']],1909 },1910 {1911 answer: 'a+(c:d)',1912 check_status: STATUS_UNOPTIMAL_FORM1913 },1914 ],1915 ['c:d+a',1916 {1917 expressions: ['c:d+a'],1918 solutions: [['c:d+a']],1919 },1920 {1921 answer: '(c:d)+a',1922 check_status: STATUS_UNOPTIMAL_FORM1923 },1924 ],1925 ['a+c/d',1926 {1927 expressions: ['a+c/d'],1928 solutions: [['a+c/d']],1929 },1930 {1931 answer: 'a+(c/d)',1932 check_status: STATUS_UNOPTIMAL_FORM1933 },1934 ],1935 ['c/d+a',1936 {1937 expressions: ['c/d+a'],1938 solutions: [['c/d+a']],1939 },1940 {1941 answer: '(c/d)+a',1942 check_status: STATUS_UNOPTIMAL_FORM1943 },1944 ],1945 ['a+c^d',1946 {1947 expressions: ['a+c^d'],1948 },1949 {1950 answer: 'a+(c^d)',1951 check_status: STATUS_UNOPTIMAL_FORM1952 },1953 ],1954 ['c^d+a',1955 {1956 expressions: ['c^d+a'],1957 },1958 {1959 answer: '(c^d)+a',1960 check_status: STATUS_UNOPTIMAL_FORM1961 },1962 ],1963 ['a+c-d',1964 {1965 expressions: ['a+c-d'],1966 },1967 {1968 answer: '(a+c)-d',1969 check_status: STATUS_UNOPTIMAL_FORM1970 },1971 ],1972 ['a-c-d',1973 {1974 expressions: ['a-c-d'],1975 },1976 {1977 answer: '(a-c)-d',1978 check_status: STATUS_UNOPTIMAL_FORM1979 },1980 ],1981 ['a-c*d',1982 {1983 expressions: ['a-c*d'],1984 },1985 {1986 answer: 'a-(cd)',1987 check_status: STATUS_UNOPTIMAL_FORM1988 },1989 ],1990 ['c*d-a',1991 {1992 expressions: ['c*d-a'],1993 },1994 {1995 answer: '(cd)-a',1996 check_status: STATUS_UNOPTIMAL_FORM1997 },1998 ],1999 ['a-c:d',2000 {2001 expressions: ['a-c:d'],2002 solutions: [['a-c:d']],2003 },2004 {2005 answer: 'a-(c:d)',2006 check_status: STATUS_UNOPTIMAL_FORM2007 },2008 ],2009 ['c:d-a',2010 {2011 expressions: ['c:d-a'],2012 solutions: [['c:d-a']],2013 },2014 {2015 answer: '(c:d)-a',2016 check_status: STATUS_UNOPTIMAL_FORM2017 },2018 ],2019 ['a-c/d',2020 {2021 expressions: ['a-c/d'],2022 solutions: [['a-c/d']],2023 },2024 {2025 answer: 'a-(c/d)',2026 check_status: STATUS_UNOPTIMAL_FORM2027 },2028 ],2029 ['c/d-a',2030 {2031 expressions: ['c/d-a'],2032 solutions: [['c/d-a']],2033 },2034 {2035 answer: '(c/d)-a',2036 check_status: STATUS_UNOPTIMAL_FORM2037 },2038 ],2039 ['a-c^d',2040 {2041 expressions: ['a-c^d'],2042 },2043 {2044 answer: 'a-(c^d)',2045 check_status: STATUS_UNOPTIMAL_FORM2046 },2047 ],2048 ['c^d-a',2049 {2050 expressions: ['c^d-a'],2051 },2052 {2053 answer: '(c^d)-a',2054 check_status: STATUS_UNOPTIMAL_FORM2055 },2056 ],2057 ['a*c*d',2058 {2059 expressions: ['a*c*d'],2060 },2061 {2062 answer: 'a(cd)',2063 check_status: STATUS_UNOPTIMAL_FORM2064 },2065 ],2066 ['c*d*a',2067 {2068 expressions: ['c*d*a'],2069 },2070 {2071 answer: '(cd)a',2072 check_status: STATUS_UNOPTIMAL_FORM2073 },2074 ],2075 ['a*c:d',2076 {2077 expressions: ['a*c:d'],2078 solutions: [['a*c:d']],2079 },2080 {2081 answer: 'a(c:d)',2082 check_status: STATUS_UNOPTIMAL_FORM2083 },2084 ],2085 ['c:d*a',2086 {2087 expressions: ['c:d*a'],2088 solutions: [['c:d*a']],2089 },2090 {2091 answer: '(c:d)a',2092 check_status: STATUS_UNOPTIMAL_FORM2093 },2094 ],2095 ['a*c/d',2096 {2097 expressions: ['a*c/d'],2098 solutions: [['a*c/d']],2099 },2100 {2101 answer: 'a(c/d)',2102 check_status: STATUS_UNOPTIMAL_FORM2103 },2104 ],2105 ['c/d*a',2106 {2107 expressions: ['c/d*a'],2108 solutions: [['c/d*a']],2109 },2110 {2111 answer: '(c/d)a',2112 check_status: STATUS_UNOPTIMAL_FORM2113 },2114 ],2115 ['a*c^d',2116 {2117 expressions: ['a*c^d'],2118 },2119 {2120 answer: 'a(c^d)',2121 check_status: STATUS_UNOPTIMAL_FORM2122 },2123 ],2124 ['c^d*a',2125 {2126 expressions: ['c^d*a'],2127 },2128 {2129 answer: '(c^d)a',2130 check_status: STATUS_UNOPTIMAL_FORM2131 },2132 ],2133 ['c*d:a',2134 {2135 expressions: ['c*d:a'],2136 solutions: [['c*d:a']],2137 },2138 {2139 answer: '(cd):a',2140 check_status: STATUS_UNOPTIMAL_FORM2141 },2142 ],2143 ['c:d:a',2144 {2145 expressions: ['c:d:a'],2146 solutions: [['c:d:a']],2147 },2148 {2149 answer: '(c:d):a',2150 check_status: STATUS_UNOPTIMAL_FORM2151 },2152 ],2153 ['c/d:a',2154 {2155 expressions: ['c/d:a'],2156 solutions: [['c/d:a']],2157 },2158 {2159 answer: '(c/d):a',2160 check_status: STATUS_UNOPTIMAL_FORM2161 },2162 ],2163 ['a:c^d',2164 {2165 expressions: ['a:c^d'],2166 solutions: [['a:c^d']],2167 },2168 {2169 answer: 'a:(c^d)',2170 check_status: STATUS_UNOPTIMAL_FORM2171 },2172 ],2173 ['c^d:a',2174 {2175 expressions: ['c^d:a'],2176 solutions: [['c^d:a']],2177 },2178 {2179 answer: '(c^d):a',2180 check_status: STATUS_UNOPTIMAL_FORM2181 },2182 ],2183 ['c*d/a',2184 {2185 expressions: ['c*d/a'],2186 solutions: [['c*d/a']],2187 },2188 {2189 answer: '(cd)/a',2190 check_status: STATUS_UNOPTIMAL_FORM2191 },2192 ],2193 ['c:d/a',2194 {2195 expressions: ['c:d/a'],2196 solutions: [['c:d/a']],2197 },2198 {2199 answer: '(c:d)/a',2200 check_status: STATUS_UNOPTIMAL_FORM2201 },2202 ],2203 ['c/d/a',2204 {2205 expressions: ['c/d/a'],2206 solutions: [['c/d/a']],2207 },2208 {2209 answer: '(c/d)/a',2210 check_status: STATUS_UNOPTIMAL_FORM2211 },2212 ],2213 ['a/c^d',2214 {2215 expressions: ['a/c^d'],2216 solutions: [['a/c^d']],2217 },2218 {2219 answer: 'a/(c^d)',2220 check_status: STATUS_UNOPTIMAL_FORM2221 },2222 ],2223 ['c^d/a',2224 {2225 expressions: ['c^d/a'],2226 solutions: [['c^d/a']],2227 },2228 {2229 answer: '(c^d)/a',2230 check_status: STATUS_UNOPTIMAL_FORM2231 },2232 ],2233 ['a/b',2234 {2235 expressions: ['a/b'],2236 solutions: [['a/b']],2237 },2238 {2239 answer: '(a)/b',2240 check_status: STATUS_UNOPTIMAL_FORM2241 },2242 ],2243 ['a/b',2244 {2245 expressions: ['a/b'],2246 solutions: [['a/b']],2247 },2248 {2249 answer: 'a/(b)',2250 check_status: STATUS_UNOPTIMAL_FORM2251 },2252 ],2253 ['a/b',2254 {2255 expressions: ['a/b'],2256 solutions: [['a/b']],2257 },2258 {2259 answer: '(a)/(b)',2260 check_status: STATUS_UNOPTIMAL_FORM2261 },2262 ],2263 ['{a+b}/b',2264 {2265 expressions: ['{a+b}/b'],2266 solutions: [['{a+b}/b']],2267 },2268 {2269 answer: '(a+b)/b',2270 check_status: STATUS_UNOPTIMAL_FORM2271 },2272 ],2273 ['a/{a+b}',2274 {2275 expressions: ['a/{a+b}'],2276 solutions: [['a/{a+b}']],2277 },2278 {2279 answer: 'a/(a+b)',2280 check_status: STATUS_UNOPTIMAL_FORM2281 },2282 ],2283 ['{a+b}/{a+b}',2284 {2285 expressions: ['{a+b}/{a+b}'],2286 solutions: [['{a+b}/{a+b}']],2287 },2288 {2289 answer: '(a+b)/(a+b)',2290 check_status: STATUS_UNOPTIMAL_FORM2291 },2292 ],2293 ['a^b',2294 {2295 expressions: ['a^b'],2296 },2297 {2298 answer: 'a^(b)',2299 check_status: STATUS_UNOPTIMAL_FORM2300 },2301 ],2302 ['a^b',2303 {2304 expressions: ['a^b'],2305 },2306 {2307 answer: '(a)^b',2308 check_status: STATUS_UNOPTIMAL_FORM2309 },2310 ],2311 ['a^b',2312 {2313 expressions: ['a^b'],2314 },2315 {2316 answer: '(a)^(b)',2317 check_status: STATUS_UNOPTIMAL_FORM2318 },2319 ],2320 ['a^{a+b}',2321 {2322 expressions: ['a^{a+b}'],2323 },2324 {2325 answer: 'a^(a+b)',2326 check_status: STATUS_UNOPTIMAL_FORM2327 },2328 ],2329 ]2330 test.each(specs)('%s', (s, q, check) => {2331 const generated = generateQuestion(q)2332 const item = {2333 ...generated,2334 ...check2335 }2336 assessItem(item)2337 expect(item.status).toBe(item.check_status)2338 })2339})2340describe('testing correct answer with extraneous signs (require-no-extraneaous-signs)', () => {2341 const specs = [2342 ['+1',2343 {2344 expressions: ['1'],2345 options: ['require-no-extraneaous-signs']2346 },2347 {2348 answer: '+1',2349 check_status: STATUS_BAD_FORM2350 },2351 ],2352 ['-(-1)',2353 {2354 expressions: ['1'],2355 options: ['require-no-extraneaous-signs']2356 },2357 {2358 answer: '-(-1)',2359 check_status: STATUS_BAD_FORM2360 },2361 ],2362 ['-(+1)',2363 {2364 expressions: ['-1'],2365 options: ['require-no-extraneaous-signs']2366 },2367 {2368 answer: '-(+1)',2369 check_status: STATUS_BAD_FORM2370 },2371 ],2372 ['+(+1)',2373 {2374 expressions: ['1'],2375 options: ['require-no-extraneaous-signs']2376 },2377 {2378 answer: '+(+1)',2379 check_status: STATUS_BAD_FORM2380 },2381 ],2382 ['+(-1)',2383 {2384 expressions: ['-1'],2385 options: ['require-no-extraneaous-signs']2386 },2387 {2388 answer: '+(-1)',2389 check_status: STATUS_BAD_FORM2390 },2391 ],2392 ['(-a)*(-b)',2393 {2394 expressions: ['a*b'],2395 options: ['require-no-extraneaous-signs']2396 },2397 {2398 answer: '(-a)*(-b)',2399 check_status: STATUS_BAD_FORM2400 },2401 ],2402 ['(-a)*b',2403 {2404 expressions: ['-a*b'],2405 options: ['require-no-extraneaous-signs']2406 },2407 {2408 answer: '(-a)*b',2409 check_status: STATUS_BAD_FORM2410 },2411 ],2412 ['a*(-b)',2413 {2414 expressions: ['-a*b'],2415 options: ['require-no-extraneaous-signs']2416 },2417 {2418 answer: 'a*(-b)',2419 check_status: STATUS_BAD_FORM2420 },2421 ],2422 ['(-a):(-b)',2423 {2424 expressions: ['a:b'],2425 options: ['require-no-extraneaous-signs']2426 },2427 {2428 answer: '(-a):(-b)',2429 check_status: STATUS_BAD_FORM2430 },2431 ],2432 ['(-a):b',2433 {2434 expressions: ['-a:b'],2435 options: ['require-no-extraneaous-signs']2436 },2437 {2438 answer: '(-a):b',2439 check_status: STATUS_BAD_FORM2440 },2441 ],2442 ['a:(-b)',2443 {2444 expressions: ['-a:b'],2445 options: ['require-no-extraneaous-signs']2446 },2447 {2448 answer: 'a:(-b)',2449 check_status: STATUS_BAD_FORM2450 },2451 ],2452 ['{-a}/{-b}',2453 {2454 expressions: ['a/b'],2455 options: ['require-no-extraneaous-signs']2456 },2457 {2458 answer: '{-a}/{-b}',2459 check_status: STATUS_BAD_FORM2460 },2461 ],2462 ['{-a}/b',2463 {2464 expressions: ['-a/b'],2465 options: ['require-no-extraneaous-signs']2466 },2467 {2468 answer: '{-a}/b',2469 check_status: STATUS_BAD_FORM2470 },2471 ],2472 ['a/{-b}',2473 {2474 expressions: ['-a/b'],2475 options: ['require-no-extraneaous-signs']2476 },2477 {2478 answer: 'a/{-b}',2479 check_status: STATUS_BAD_FORM2480 },2481 ],2482 ]2483 test.each(specs)('%s', (s, q, check) => {2484 const generated = generateQuestion(q)2485 const item = {2486 ...generated,2487 ...check2488 }2489 assessItem(item)2490 expect(item.status).toBe(item.check_status)2491 })2492})2493describe('testing correct answer with extraneous signs (no-penalty-for-extraneous-signs)', () => {2494 const specs = [2495 ['+1',2496 {2497 expressions: ['1'],2498 options: ['no-penalty-for-extraneous-signs']2499 },2500 {2501 answer: '+1',2502 check_status: STATUS_CORRECT2503 },2504 ],2505 ['-(-1)',2506 {2507 expressions: ['1'],2508 options: ['no-penalty-for-extraneous-signs']2509 },2510 {2511 answer: '-(-1)',2512 check_status: STATUS_CORRECT2513 },2514 ],2515 ['-(+1)',2516 {2517 expressions: ['-1'],2518 options: ['no-penalty-for-extraneous-signs']2519 },2520 {2521 answer: '-(+1)',2522 check_status: STATUS_CORRECT2523 },2524 ],2525 ['+(+1)',2526 {2527 expressions: ['1'],2528 options: ['no-penalty-for-extraneous-signs']2529 },2530 {2531 answer: '+(+1)',2532 check_status: STATUS_CORRECT2533 },2534 ],2535 ['+(-1)',2536 {2537 expressions: ['-1'],2538 options: ['no-penalty-for-extraneous-signs']2539 },2540 {2541 answer: '+(-1)',2542 check_status: STATUS_CORRECT2543 },2544 ],2545 ['(-a)*(-b)',2546 {2547 expressions: ['a*b'],2548 options: ['no-penalty-for-extraneous-signs']2549 },2550 {2551 answer: '(-a)(-b)',2552 check_status: STATUS_CORRECT2553 },2554 ],2555 ['(-a)*b',2556 {2557 expressions: ['-a*b'],2558 options: ['no-penalty-for-extraneous-signs']2559 },2560 {2561 answer: '(-a)b',2562 check_status: STATUS_CORRECT2563 },2564 ],2565 ['a*(-b)',2566 {2567 expressions: ['-a*b'],2568 options: ['no-penalty-for-extraneous-signs']2569 },2570 {2571 answer: 'a(-b)',2572 check_status: STATUS_CORRECT2573 },2574 ],2575 ['(-a):(-b)',2576 {2577 expressions: ['a:b'],2578 solutions: [['a:b']],2579 options: ['no-penalty-for-extraneous-signs']2580 },2581 {2582 answer: '(-a):(-b)',2583 check_status: STATUS_CORRECT2584 },2585 ],2586 ['(-a):b',2587 {2588 expressions: ['-a:b'],2589 solutions: [['-a:b']],2590 options: ['no-penalty-for-extraneous-signs']2591 },2592 {2593 answer: '(-a):b',2594 check_status: STATUS_CORRECT2595 },2596 ],2597 ['a:(-b)',2598 {2599 expressions: ['-a:b'],2600 solutions: [['-a:b']],2601 options: ['no-penalty-for-extraneous-signs']2602 },2603 {2604 answer: 'a:(-b)',2605 check_status: STATUS_CORRECT2606 },2607 ],2608 ['{-a}/{-b}',2609 {2610 expressions: ['a/b'],2611 solutions: [['a/b']],2612 options: ['no-penalty-for-extraneous-signs']2613 },2614 {2615 answer: '{-a}/{-b}',2616 check_status: STATUS_CORRECT2617 },2618 ],2619 ['{-a}/b',2620 {2621 expressions: ['-a/b'],2622 solutions: [['-a/b']],2623 options: ['no-penalty-for-extraneous-signs']2624 },2625 {2626 answer: '{-a}/b',2627 check_status: STATUS_CORRECT2628 },2629 ],2630 ['a/{-b}',2631 {2632 expressions: ['-a/b'],2633 solutions: [['-a/b']],2634 options: ['no-penalty-for-extraneous-signs']2635 },2636 {2637 answer: 'a/{-b}',2638 check_status: STATUS_CORRECT2639 },2640 ],2641 ]2642 test.each(specs)('%s', (s, q, check) => {2643 const generated = generateQuestion(q)2644 const item = {2645 ...generated,2646 ...check2647 }2648 assessItem(item)2649 expect(item.status).toBe(item.check_status)2650 })2651})2652describe('testing correct answer with extraneous signs', () => {2653 const specs = [2654 ['+1',2655 {2656 expressions: ['1'],2657 },2658 {2659 answer: '+1',2660 check_status: STATUS_UNOPTIMAL_FORM2661 },2662 ],2663 ['-(-1)',2664 {2665 expressions: ['1'],2666 },2667 {2668 answer: '-(-1)',2669 check_status: STATUS_UNOPTIMAL_FORM2670 },2671 ],2672 ['-(+1)',2673 {2674 expressions: ['-1'],2675 },2676 {2677 answer: '-(+1)',2678 check_status: STATUS_UNOPTIMAL_FORM2679 },2680 ],2681 ['+(+1)',2682 {2683 expressions: ['1'],2684 },2685 {2686 answer: '+(+1)',2687 check_status: STATUS_UNOPTIMAL_FORM2688 },2689 ],2690 ['+(-1)',2691 {2692 expressions: ['-1'],2693 },2694 {2695 answer: '+(-1)',2696 check_status: STATUS_UNOPTIMAL_FORM2697 },2698 ],2699 ['(-a)*(-b)',2700 {2701 expressions: ['a*b'],2702 },2703 {2704 answer: '(-a)(-b)',2705 check_status: STATUS_UNOPTIMAL_FORM2706 },2707 ],2708 ['(-a)*b',2709 {2710 expressions: ['-a*b'],2711 },2712 {2713 answer: '(-a)b',2714 check_status: STATUS_UNOPTIMAL_FORM2715 },2716 ],2717 ['a*(-b)',2718 {2719 expressions: ['-a*b'],2720 },2721 {2722 answer: 'a(-b)',2723 check_status: STATUS_UNOPTIMAL_FORM2724 },2725 ],2726 ['(-a):(-b)',2727 {2728 expressions: ['a:b'],2729 solutions: [['a:b']],2730 },2731 {2732 answer: '(-a):(-b)',2733 check_status: STATUS_UNOPTIMAL_FORM2734 },2735 ],2736 ['(-a):b',2737 {2738 expressions: ['-a:b'],2739 solutions: [['-a:b']],2740 },2741 {2742 answer: '(-a):b',2743 check_status: STATUS_UNOPTIMAL_FORM2744 },2745 ],2746 ['a:(-b)',2747 {2748 expressions: ['-a:b'],2749 solutions: [['-a:b']],2750 },2751 {2752 answer: 'a:(-b)',2753 check_status: STATUS_UNOPTIMAL_FORM2754 },2755 ],2756 ['{-a}/{-b}',2757 {2758 expressions: ['a/b'],2759 solutions: [['a/b']],2760 },2761 {2762 answer: '{-a}/{-b}',2763 check_status: STATUS_UNOPTIMAL_FORM2764 },2765 ],2766 ['{-a}/b',2767 {2768 expressions: ['-a/b'],2769 solutions: [['-a/b']],2770 },2771 {2772 answer: '{-a}/b',2773 check_status: STATUS_UNOPTIMAL_FORM2774 },2775 ],2776 ['a/{-b}',2777 {2778 expressions: ['-a/b'],2779 solutions: [['-a/b']],2780 },2781 {2782 answer: 'a/{-b}',2783 check_status: STATUS_UNOPTIMAL_FORM2784 },2785 ],2786 ]2787 test.each(specs)('%s', (s, q, check) => {2788 const generated = generateQuestion(q)2789 const item = {2790 ...generated,2791 ...check2792 }2793 assessItem(item)2794 expect(item.status).toBe(item.check_status)2795 })2796})2797describe('testing correct answer with correct spaces (require-correct-spaces)', () => {2798 const specs = [[2799 {2800 expressions: ['1234'],2801 options: ['require-correct-spaces']2802 },2803 {2804 answer: '1 234',2805 check_status: STATUS_CORRECT2806 },2807 ],2808 [2809 {2810 expressions: ['1234567890'],2811 options: ['require-correct-spaces']2812 },2813 {2814 answer: '1 234 567 890',2815 check_status: STATUS_CORRECT2816 },2817 ],2818 [2819 {2820 expressions: ['1,2345'],2821 options: ['require-correct-spaces'],2822 'result-type': 'decimal'2823 },2824 {2825 answer: '1,234 5',2826 check_status: STATUS_CORRECT2827 },2828 ],2829 ]2830 test.each(specs)('', (q, check) => {2831 const generated = generateQuestion(q)2832 const item = {2833 ...generated,2834 ...check2835 }2836 assessItem(item)2837 expect(item.status).toBe(item.check_status)2838 })2839})2840describe('testing correct answer with incorrect spaces (require-correct-spaces)', () => {2841 const specs = [[2842 {2843 expressions: ['1234'],2844 options: ['require-correct-spaces']2845 },2846 {2847 answer: '1234',2848 check_status: STATUS_BAD_FORM2849 },2850 ],2851 [2852 {2853 expressions: ['1234'],2854 options: ['require-correct-spaces']2855 },2856 {2857 answer: '1 2 3 4',2858 check_status: STATUS_BAD_FORM2859 },2860 ],2861 [2862 {2863 expressions: ['1,2345'],2864 options: ['require-correct-spaces']2865 },2866 {2867 answer: '1,2345',2868 check_status: STATUS_BAD_FORM2869 },2870 ],2871 ]2872 test.each(specs)('', (q, check) => {2873 const generated = generateQuestion(q)2874 const item = {2875 ...generated,2876 ...check2877 }2878 assessItem(item)2879 expect(item.status).toBe(item.check_status)2880 })2881})2882describe('testing correct answer with incorrect spaces (no-penalty-for-incorrect-spaces)', () => {2883 const specs = [[2884 {2885 expressions: ['1234'],2886 options: ['no-penalty-for-incorrect-spaces']2887 },2888 {2889 answer: '1234',2890 check_status: STATUS_CORRECT2891 },2892 ],2893 [2894 {2895 expressions: ['1234'],2896 options: ['no-penalty-for-incorrect-spaces']2897 },2898 {2899 answer: '1 2 3 4',2900 check_status: STATUS_CORRECT2901 },2902 ],2903 [2904 {2905 expressions: ['1,2345'],2906 options: ['no-penalty-for-incorrect-spaces'],2907 'result-type': 'decimal'2908 },2909 {2910 answer: '1,2345',2911 check_status: STATUS_CORRECT2912 },2913 ],2914 ]2915 test.each(specs)('', (q, check) => {2916 const generated = generateQuestion(q)2917 const item = {2918 ...generated,2919 ...check2920 }2921 assessItem(item)2922 expect(item.status).toBe(item.check_status)2923 })2924})2925describe('testing correct answer with incorrect spaces', () => {2926 const specs = [[2927 {2928 expressions: ['1234'],2929 },2930 {2931 answer: '1234',2932 check_status: STATUS_UNOPTIMAL_FORM2933 },2934 ],2935 [2936 {2937 expressions: ['1234'],2938 },2939 {2940 answer: '1 2 3 4',2941 check_status: STATUS_UNOPTIMAL_FORM2942 },2943 ],2944 [2945 {2946 expressions: ['1,2345'],2947 'result-type': 'decimal'2948 },2949 {2950 answer: '1,2345',2951 check_status: STATUS_UNOPTIMAL_FORM2952 },2953 ],2954 ]2955 test.each(specs)('', (q, check) => {2956 const generated = generateQuestion(q)2957 const item = {2958 ...generated,2959 ...check2960 }2961 assessItem(item)2962 expect(item.status).toBe(item.check_status)2963 })2964})2965describe('testing correct answer with implicit product (require-implicit-products)', () => {2966 const specs = [[2967 {2968 expressions: ['2*a'],2969 options: ['require-implicit-products']2970 },2971 {2972 answer: '2a',2973 check_status: STATUS_CORRECT2974 },2975 ],2976 [2977 {2978 expressions: ['(3+a)*b'],2979 options: ['require-implicit-products'],2980 solutions: [['(3+a)*b']]2981 },2982 {2983 answer: '(3+a)b',2984 check_status: STATUS_CORRECT2985 },2986 ],2987 ]2988 test.each(specs)('', (q, check) => {2989 const generated = generateQuestion(q)2990 const item = {2991 ...generated,2992 ...check2993 }2994 assessItem(item)2995 expect(item.status).toBe(item.check_status)2996 })2997})2998describe('testing correct answer with explicit product (require-implicit-products)', () => {2999 const specs = [[3000 {3001 expressions: ['2*a'],3002 options: ['require-implicit-products']3003 },3004 {3005 answer: '2*a',3006 check_status: STATUS_BAD_FORM3007 },3008 ],3009 [3010 {3011 expressions: ['(3+a)*b'],3012 options: ['require-implicit-products'],3013 solutions: [['(3+a)*b']]3014 },3015 {3016 answer: '(3+a)*b',3017 check_status: STATUS_BAD_FORM3018 },3019 ],3020 ]3021 test.each(specs)('', (q, check) => {3022 const generated = generateQuestion(q)3023 const item = {3024 ...generated,3025 ...check3026 }3027 assessItem(item)3028 expect(item.status).toBe(item.check_status)3029 })3030})3031describe('testing correct answer with implicit product (no-penalty-for-explicit-products)', () => {3032 const specs = [[3033 {3034 expressions: ['2*a'],3035 options: ['no-penalty-for-explicit-products']3036 },3037 {3038 answer: '2a',3039 check_status: STATUS_CORRECT3040 },3041 ],3042 [3043 {3044 expressions: ['(3+a)*b'],3045 options: ['no-penalty-for-explicit-products'],3046 solutions: [['(3+a)*b']]3047 },3048 {3049 answer: '(3+a)b',3050 check_status: STATUS_CORRECT3051 },3052 ],3053 ]3054 test.each(specs)('', (q, check) => {3055 const generated = generateQuestion(q)3056 const item = {3057 ...generated,3058 ...check3059 }3060 assessItem(item)3061 expect(item.status).toBe(item.check_status)3062 })3063})3064describe('testing correct answer with explicit product (no-penalty-for-explicit-products)', () => {3065 const specs = [[3066 {3067 expressions: ['2*a'],3068 options: ['no-penalty-for-explicit-products']3069 },3070 {3071 answer: '2*a',3072 check_status: STATUS_CORRECT3073 },3074 ],3075 [3076 {3077 expressions: ['(3+a)*b'],3078 options: ['no-penalty-for-explicit-products'],3079 solutions: [['(3+a)*b']]3080 },3081 {3082 answer: '(3+a)*b',3083 check_status: STATUS_CORRECT3084 },3085 ],3086 ]3087 test.each(specs)('', (q, check) => {3088 const generated = generateQuestion(q)3089 const item = {3090 ...generated,3091 ...check3092 }3093 assessItem(item)3094 expect(item.status).toBe(item.check_status)3095 })3096})3097describe('testing correct answer with implicit product', () => {3098 const specs = [[3099 {3100 expressions: ['2*a'],3101 },3102 {3103 answer: '2a',3104 check_status: STATUS_CORRECT3105 },3106 ],3107 [3108 {3109 expressions: ['(3+a)*b'],3110 solutions: [['(3+a)*b']]3111 },3112 {3113 answer: '(3+a)b',3114 check_status: STATUS_CORRECT3115 },3116 ],3117 ]3118 test.each(specs)('', (q, check) => {3119 const generated = generateQuestion(q)3120 const item = {3121 ...generated,3122 ...check3123 }3124 assessItem(item)3125 expect(item.status).toBe(item.check_status)3126 })3127})3128describe('testing correct answer with explicit product', () => {3129 const specs = [[3130 {3131 expressions: ['2*a'],3132 },3133 {3134 answer: '2*a',3135 check_status: STATUS_UNOPTIMAL_FORM3136 },3137 ],3138 [3139 {3140 expressions: ['(3+a)*b'],3141 solutions: [['(3+a)*b']]3142 },3143 {3144 answer: '(3+a)*b',3145 check_status: STATUS_UNOPTIMAL_FORM3146 },3147 ],3148 ]3149 test.each(specs)('', (q, check) => {3150 const generated = generateQuestion(q)3151 const item = {3152 ...generated,3153 ...check3154 }3155 assessItem(item)3156 expect(item.status).toBe(item.check_status)3157 })3158})3159describe('testing correct answer with factor one (require-no-factor-one)', () => {3160 const specs = [3161 ['1*1',3162 {3163 expressions: ['1'],3164 options: ['require-no-factor-one']3165 },3166 {3167 answer: '1*1',3168 check_status: STATUS_BAD_FORM3169 },3170 ],3171 ['1*a',3172 {3173 expressions: ['a'],3174 options: ['require-no-factor-one']3175 },3176 {3177 answer: '1*a',3178 check_status: STATUS_BAD_FORM3179 },3180 ],3181 ['a*1',3182 {3183 expressions: ['a'],3184 options: ['require-no-factor-one']3185 },3186 {3187 answer: 'a*1',3188 check_status: STATUS_BAD_FORM3189 },3190 ],3191 ['a*1*b',3192 {3193 expressions: ['a*b'],3194 options: ['require-no-factor-one']3195 },3196 {3197 answer: 'a*1*b',3198 check_status: STATUS_BAD_FORM3199 },3200 ],3201 ]3202 test.each(specs)('%s', (s, q, check) => {3203 const generated = generateQuestion(q)3204 const item = {3205 ...generated,3206 ...check3207 }3208 assessItem(item)3209 expect(item.status).toBe(item.check_status)3210 })3211})3212describe('testing correct answer with factor one (no-penalty-for-factor-one)', () => {3213 const specs = [3214 ['1*1',3215 {3216 expressions: ['1'],3217 options: ['no-penalty-for-factor-one']3218 },3219 {3220 answer: '1*1',3221 check_status: STATUS_CORRECT3222 },3223 ],3224 ['1*a',3225 {3226 expressions: ['a'],3227 options: ['no-penalty-for-factor-one']3228 },3229 {3230 answer: '1a',3231 check_status: STATUS_CORRECT3232 },3233 ],3234 ['a*1',3235 {3236 expressions: ['a'],3237 options: ['no-penalty-for-factor-one']3238 },3239 {3240 answer: 'a*1',3241 check_status: STATUS_CORRECT3242 },3243 ],3244 ['a*1*b',3245 {3246 expressions: ['a*b'],3247 options: ['no-penalty-for-factor-one']3248 },3249 {3250 answer: 'a*1b',3251 check_status: STATUS_CORRECT3252 },3253 ],3254 ]3255 test.each(specs)('%s', (s, q, check) => {3256 const generated = generateQuestion(q)3257 const item = {3258 ...generated,3259 ...check3260 }3261 assessItem(item)3262 expect(item.status).toBe(item.check_status)3263 })3264})3265describe('testing correct answer with factor one', () => {3266 const specs = [3267 ['1*1',3268 {3269 expressions: ['1'],3270 },3271 {3272 answer: '1*1',3273 check_status: STATUS_UNOPTIMAL_FORM3274 },3275 ],3276 ['1*a',3277 {3278 expressions: ['a'],3279 },3280 {3281 answer: '1a',3282 check_status: STATUS_UNOPTIMAL_FORM3283 },3284 ],3285 ['a*1',3286 {3287 expressions: ['a'],3288 },3289 {3290 answer: 'a*1',3291 check_status: STATUS_UNOPTIMAL_FORM3292 },3293 ],3294 ['a*1*b',3295 {3296 expressions: ['a*b'],3297 },3298 {3299 answer: 'a*1b',3300 check_status: STATUS_UNOPTIMAL_FORM3301 },3302 ],3303 ]3304 test.each(specs)('%s', (s, q, check) => {3305 const generated = generateQuestion(q)3306 const item = {3307 ...generated,3308 ...check3309 }3310 assessItem(item)3311 expect(item.status).toBe(item.check_status)3312 })3313})3314describe('testing correct answer with factor zero (require-no-factor-zero)', () => {3315 const specs = [3316 ['0*0',3317 {3318 expressions: ['0'],3319 options: ['require-no-factor-zero']3320 },3321 {3322 answer: '0*0',3323 check_status: STATUS_BAD_FORM3324 },3325 ],3326 ['0*a',3327 {3328 expressions: ['0'],3329 options: ['require-no-factor-zero']3330 },3331 {3332 answer: '0*a',3333 check_status: STATUS_BAD_FORM3334 },3335 ],3336 ['a*0',3337 {3338 expressions: ['0'],3339 options: ['require-no-factor-zero']3340 },3341 {3342 answer: 'a*0',3343 check_status: STATUS_BAD_FORM3344 },3345 ],3346 ['a*0*b',3347 {3348 expressions: ['0'],3349 options: ['require-no-factor-zero']3350 },3351 {3352 answer: 'a*0*b',3353 check_status: STATUS_BAD_FORM3354 },3355 ],3356 ]3357 test.each(specs)('%s', (s, q, check) => {3358 const generated = generateQuestion(q)3359 const item = {3360 ...generated,3361 ...check3362 }3363 assessItem(item)3364 expect(item.status).toBe(item.check_status)3365 })3366})3367describe('testing correct answer with factor zero (no-penalty-for-factor-zero)', () => {3368 const specs = [3369 ['0*0',3370 {3371 expressions: ['0'],3372 options: ['no-penalty-for-factor-zero']3373 },3374 {3375 answer: '0*0',3376 check_status: STATUS_CORRECT3377 },3378 ],3379 ['0*a',3380 {3381 expressions: ['0'],3382 options: ['no-penalty-for-factor-zero']3383 },3384 {3385 answer: '0a',3386 check_status: STATUS_CORRECT3387 },3388 ],3389 ['a*0',3390 {3391 expressions: ['0'],3392 options: ['no-penalty-for-factor-zero']3393 },3394 {3395 answer: 'a*0',3396 check_status: STATUS_CORRECT3397 },3398 ],3399 ['a*0*b',3400 {3401 expressions: ['0'],3402 options: ['no-penalty-for-factor-zero']3403 },3404 {3405 answer: 'a*0b',3406 check_status: STATUS_CORRECT3407 },3408 ],3409 ]3410 test.each(specs)('%s', (s, q, check) => {3411 const generated = generateQuestion(q)3412 const item = {3413 ...generated,3414 ...check3415 }3416 assessItem(item)3417 expect(item.status).toBe(item.check_status)3418 })3419})3420describe('testing correct answer with factor zero', () => {3421 const specs = [3422 ['0*0',3423 {3424 expressions: ['0'],3425 },3426 {3427 answer: '0*0',3428 check_status: STATUS_UNOPTIMAL_FORM3429 },3430 ],3431 ['0*a',3432 {3433 expressions: ['0'],3434 },3435 {3436 answer: '0a',3437 check_status: STATUS_UNOPTIMAL_FORM3438 },3439 ],3440 ['a*0',3441 {3442 expressions: ['0'],3443 },3444 {3445 answer: 'a*0',3446 check_status: STATUS_UNOPTIMAL_FORM3447 },3448 ],3449 ['a*0*b',3450 {3451 expressions: ['0'],3452 },3453 {3454 answer: 'a*0b',3455 check_status: STATUS_UNOPTIMAL_FORM3456 },3457 ],3458 ]3459 test.each(specs)('%s', (s, q, check) => {3460 const generated = generateQuestion(q)3461 const item = {3462 ...generated,3463 ...check3464 }3465 assessItem(item)3466 expect(item.status).toBe(item.check_status)3467 })3468})3469describe('testing correct answer with null term (require-no-null-terms)', () => {3470 const specs = [3471 ['0+0',3472 {3473 expressions: ['0'],3474 options: ['require-no-null-terms']3475 },3476 {3477 answer: '0+0',3478 check_status: STATUS_BAD_FORM3479 },3480 ],3481 ['0+a',3482 {3483 expressions: ['a'],3484 options: ['require-no-null-terms']3485 },3486 {3487 answer: '0+a',3488 check_status: STATUS_BAD_FORM3489 },3490 ],3491 ['a+0',3492 {3493 expressions: ['a'],3494 options: ['require-no-null-terms']3495 },3496 {3497 answer: 'a+0',3498 check_status: STATUS_BAD_FORM3499 },3500 ],3501 ['a+0+b',3502 {3503 expressions: ['a+b'],3504 options: ['require-no-null-terms']3505 },3506 {3507 answer: 'a+0+b',3508 check_status: STATUS_BAD_FORM3509 },3510 ],3511 ]3512 test.each(specs)('%s', (s, q, check) => {3513 const generated = generateQuestion(q)3514 const item = {3515 ...generated,3516 ...check3517 }3518 assessItem(item)3519 expect(item.status).toBe(item.check_status)3520 })3521})3522describe('testing correct answer with null term (no-penalty-for-null-terms)', () => {3523 const specs = [3524 ['0+0',3525 {3526 expressions: ['0'],3527 options: ['no-penalty-for-null-terms']3528 },3529 {3530 answer: '0+0',3531 check_status: STATUS_CORRECT3532 },3533 ],3534 ['0+a',3535 {3536 expressions: ['a'],3537 options: ['no-penalty-for-null-terms']3538 },3539 {3540 answer: '0+a',3541 check_status: STATUS_CORRECT3542 },3543 ],3544 ['a+0',3545 {3546 expressions: ['a'],3547 options: ['no-penalty-for-null-terms']3548 },3549 {3550 answer: 'a+0',3551 check_status: STATUS_CORRECT3552 },3553 ],3554 ['a+0+b',3555 {3556 expressions: ['a+b'],3557 options: ['no-penalty-for-null-terms']3558 },3559 {3560 answer: 'a+0+b',3561 check_status: STATUS_CORRECT3562 },3563 ],3564 ]3565 test.each(specs)('%s', (s, q, check) => {3566 const generated = generateQuestion(q)3567 const item = {3568 ...generated,3569 ...check3570 }3571 assessItem(item)3572 expect(item.status).toBe(item.check_status)3573 })3574})3575describe('testing correct answer with null term', () => {3576 const specs = [3577 ['0+0',3578 {3579 expressions: ['0'],3580 },3581 {3582 answer: '0*0',3583 check_status: STATUS_UNOPTIMAL_FORM3584 },3585 ],3586 ['0+a',3587 {3588 expressions: ['a'],3589 },3590 {3591 answer: '0+a',3592 check_status: STATUS_UNOPTIMAL_FORM3593 },3594 ],3595 ['a+0',3596 {3597 expressions: ['a'],3598 },3599 {3600 answer: 'a+0',3601 check_status: STATUS_UNOPTIMAL_FORM3602 },3603 ],3604 ['a+0+b',3605 {3606 expressions: ['a+b'],3607 },3608 {3609 answer: 'a+0+b',3610 check_status: STATUS_UNOPTIMAL_FORM3611 },3612 ],3613 ]3614 test.each(specs)('%s', (s, q, check) => {3615 const generated = generateQuestion(q)3616 const item = {3617 ...generated,3618 ...check3619 }3620 assessItem(item)3621 expect(item.status).toBe(item.check_status)3622 })3623})3624describe('testing correct answer with non reduced fraction (require-reduced-fractions)', () => {3625 const specs = [3626 ['4/2',3627 {3628 expressions: ['2'],3629 options: ['require-reduced-fractions']3630 },3631 {3632 answer: '4/2',3633 check_status: STATUS_BAD_FORM3634 },3635 ],3636 ['2/4',3637 {3638 expressions: ['1/2'],3639 options: ['require-reduced-fractions']3640 },3641 {3642 answer: '2/4',3643 check_status: STATUS_BAD_FORM3644 },3645 ],3646 ['a+2/4',3647 {3648 expressions: ['a+1/2'],3649 options: ['require-reduced-fractions']3650 },3651 {3652 answer: 'a+2/4',3653 check_status: STATUS_BAD_FORM3654 },3655 ],3656 ]3657 test.each(specs)('%s', (s, q, check) => {3658 const generated = generateQuestion(q)3659 const item = {3660 ...generated,3661 ...check3662 }3663 assessItem(item)3664 expect(item.status).toBe(item.check_status)3665 })3666})3667describe('testing correct answer with non reduced fraction (no-penalty-for-non-reduced-fractions)', () => {3668 const specs = [3669 ['4/2',3670 {3671 expressions: ['2'],3672 options: ['no-penalty-for-non-reduced-fractions']3673 },3674 {3675 answer: '4/2',3676 check_status: STATUS_CORRECT3677 },3678 ],3679 ['2/4',3680 {3681 expressions: ['1/2'],3682 options: ['no-penalty-for-non-reduced-fractions']3683 },3684 {3685 answer: '2/4',3686 check_status: STATUS_CORRECT3687 },3688 ],3689 ['a+2/4',3690 {3691 expressions: ['a+1/2'],3692 solutions: [['a+1/2']],3693 options: ['no-penalty-for-non-reduced-fractions']3694 },3695 {3696 answer: 'a+2/4',3697 check_status: STATUS_CORRECT3698 },3699 ],3700 ]3701 test.each(specs)('%s', (s, q, check) => {3702 const generated = generateQuestion(q)3703 const item = {3704 ...generated,3705 ...check3706 }3707 assessItem(item)3708 expect(item.status).toBe(item.check_status)3709 })3710})3711describe('testing correct answer with non reduced fraction', () => {3712 const specs = [3713 ['4/2',3714 {3715 expressions: ['2'],3716 },3717 {3718 answer: '4/2',3719 check_status: STATUS_UNOPTIMAL_FORM3720 },3721 ],3722 ['2/4',3723 {3724 expressions: ['1/2'],3725 },3726 {3727 answer: '2/4',3728 check_status: STATUS_UNOPTIMAL_FORM3729 },3730 ],3731 ['a+2/4',3732 {3733 expressions: ['a+1/2'],3734 solutions: [['a+1/2']],3735 },3736 {3737 answer: 'a+2/4',3738 check_status: STATUS_UNOPTIMAL_FORM3739 },3740 ],3741 ]3742 test.each(specs)('%s', (s, q, check) => {3743 const generated = generateQuestion(q)3744 const item = {3745 ...generated,3746 ...check3747 }3748 assessItem(item)3749 expect(item.status).toBe(item.check_status)3750 })3751})3752describe('testing correct answer with permuted terms (disallow-terms-permutation)', () => {3753 const specs = [3754 ['b+a',3755 {3756 expressions: ['a+b'],3757 options: ['disallow-terms-permutation']3758 },3759 {3760 answer: 'b+a',3761 check_status: STATUS_BAD_FORM3762 },3763 ],3764 ['b+a+c',3765 {3766 expressions: ['a+b+c'],3767 options: ['disallow-terms-permutation']3768 },3769 {3770 answer: 'b+a+c',3771 check_status: STATUS_BAD_FORM3772 },3773 ],3774 ]3775 test.each(specs)('%s', (s, q, check) => {3776 const generated = generateQuestion(q)3777 const item = {3778 ...generated,3779 ...check3780 }3781 assessItem(item)3782 expect(item.status).toBe(item.check_status)3783 })3784})3785describe('testing correct answer with permuted terms (penalty-for-terms-permutation)', () => {3786 const specs = [3787 ['b+a',3788 {3789 expressions: ['a+b'],3790 options: ['penalty-for-terms-permutation']3791 },3792 {3793 answer: 'b+a',3794 check_status: STATUS_UNOPTIMAL_FORM3795 },3796 ],3797 ['b+a+c',3798 {3799 expressions: ['a+b+c'],3800 options: ['penalty-for-terms-permutation']3801 },3802 {3803 answer: 'b+a+c',3804 check_status: STATUS_UNOPTIMAL_FORM3805 },3806 ],3807 ]3808 test.each(specs)('%s', (s, q, check) => {3809 const generated = generateQuestion(q)3810 const item = {3811 ...generated,3812 ...check3813 }3814 assessItem(item)3815 expect(item.status).toBe(item.check_status)3816 })3817})3818describe('testing correct answer with permuted terms', () => {3819 const specs = [3820 ['b+a',3821 {3822 expressions: ['a+b'],3823 },3824 {3825 answer: 'b+a',3826 check_status: STATUS_CORRECT3827 },3828 ],3829 ['b+a+c',3830 {3831 expressions: ['a+b+c'],3832 },3833 {3834 answer: 'b+a+c',3835 check_status: STATUS_CORRECT3836 },3837 ],3838 ]3839 test.each(specs)('%s', (s, q, check) => {3840 const generated = generateQuestion(q)3841 const item = {3842 ...generated,3843 ...check3844 }3845 assessItem(item)3846 expect(item.status).toBe(item.check_status)3847 })3848})3849describe('testing correct answer with permuted factors (disallow-factors-permutation)', () => {3850 const specs = [3851 ['b*a',3852 {3853 expressions: ['a*b'],3854 options: ['disallow-factors-permutation']3855 },3856 {3857 answer: 'b*a',3858 check_status: STATUS_BAD_FORM3859 },3860 ],3861 ['b*a*c',3862 {3863 expressions: ['a*b*c'],3864 options: ['disallow-factors-permutation']3865 },3866 {3867 answer: 'b*a*c',3868 check_status: STATUS_BAD_FORM3869 },3870 ],3871 ]3872 test.each(specs)('%s', (s, q, check) => {3873 const generated = generateQuestion(q)3874 const item = {3875 ...generated,3876 ...check3877 }3878 assessItem(item)3879 expect(item.status).toBe(item.check_status)3880 })3881})3882describe('testing correct answer with permuted factors (penalty-for-factors-permutation)', () => {3883 const specs = [3884 ['b*a',3885 {3886 expressions: ['a*b'],3887 options: ['penalty-for-factors-permutation']3888 },3889 {3890 answer: 'ba',3891 check_status: STATUS_UNOPTIMAL_FORM3892 },3893 ],3894 ['b*a*c',3895 {3896 expressions: ['a*b*c'],3897 options: ['penalty-for-factors-permutation']3898 },3899 {3900 answer: 'bac',3901 check_status: STATUS_UNOPTIMAL_FORM3902 },3903 ],3904 ]3905 test.each(specs)('%s', (s, q, check) => {3906 const generated = generateQuestion(q)3907 const item = {3908 ...generated,3909 ...check3910 }3911 assessItem(item)3912 expect(item.status).toBe(item.check_status)3913 })3914})3915describe('testing correct answer with permuted factors', () => {3916 const specs = [3917 ['b*a',3918 {3919 expressions: ['a*b'],3920 },3921 {3922 answer: 'ba',3923 check_status: STATUS_CORRECT3924 },3925 ],3926 ['b+a+c',3927 {3928 expressions: ['a*b*c'],3929 },3930 {3931 answer: 'bac',3932 check_status: STATUS_CORRECT3933 },3934 ],3935 ]3936 test.each(specs)('%s', (s, q, check) => {3937 const generated = generateQuestion(q)3938 const item = {3939 ...generated,3940 ...check3941 }3942 assessItem(item)3943 expect(item.status).toBe(item.check_status)3944 })3945})3946describe('testing correct answer with permuted terms or factors (disallow-terms-and-factors-permutation)', () => {3947 const specs = [3948 ['b*a',3949 {3950 expressions: ['a*b'],3951 options: ['disallow-terms-and-factors-permutation']3952 },3953 {3954 answer: 'b*a',3955 check_status: STATUS_BAD_FORM3956 },3957 ],3958 ['b*a*c',3959 {3960 expressions: ['a*b*c'],3961 options: ['disallow-terms-and-factors-permutation']3962 },3963 {3964 answer: 'b*a*c',3965 check_status: STATUS_BAD_FORM3966 },3967 ],3968 ['b+a',3969 {3970 expressions: ['a+b'],3971 options: ['disallow-terms-and-factors-permutation']3972 },3973 {3974 answer: 'b+a',3975 check_status: STATUS_BAD_FORM3976 },3977 ],3978 ['b+a+c',3979 {3980 expressions: ['a+b+c'],3981 options: ['disallow-terms-and-factors-permutation']3982 },3983 {3984 answer: 'b+a+c',3985 check_status: STATUS_BAD_FORM3986 },3987 ],3988 ]3989 test.each(specs)('%s', (s, q, check) => {3990 const generated = generateQuestion(q)3991 const item = {3992 ...generated,3993 ...check3994 }3995 assessItem(item)3996 expect(item.status).toBe(item.check_status)3997 })3998})3999describe('testing correct answer with permuted terms or factors (penalty-for-terms-and-factors-permutation)', () => {4000 const specs = [4001 ['b*a',4002 {4003 expressions: ['a*b'],4004 options: ['penalty-for-terms-and-factors-permutation']4005 },4006 {4007 answer: 'ba',4008 check_status: STATUS_UNOPTIMAL_FORM4009 },4010 ],4011 ['b*a*c',4012 {4013 expressions: ['a*b*c'],4014 options: ['penalty-for-terms-and-factors-permutation']4015 },4016 {4017 answer: 'bac',4018 check_status: STATUS_UNOPTIMAL_FORM4019 },4020 ],4021 ['b+a',4022 {4023 expressions: ['a+b'],4024 options: ['penalty-for-terms-and-factors-permutation']4025 },4026 {4027 answer: 'b+a',4028 check_status: STATUS_UNOPTIMAL_FORM4029 },4030 ],4031 ['b+a+c',4032 {4033 expressions: ['a+b+c'],4034 options: ['penalty-for-terms-and-factors-permutation']4035 },4036 {4037 answer: 'b+a+c',4038 check_status: STATUS_UNOPTIMAL_FORM4039 },4040 ],4041 ]4042 test.each(specs)('%s', (s, q, check) => {4043 const generated = generateQuestion(q)4044 const item = {4045 ...generated,4046 ...check4047 }4048 assessItem(item)4049 expect(item.status).toBe(item.check_status)4050 })4051})4052describe('testing correct answer with permuted terms or terms', () => {4053 const specs = [4054 ['b+a',4055 {4056 expressions: ['a+b'],4057 },4058 {4059 answer: 'b+a',4060 check_status: STATUS_CORRECT4061 },4062 ],4063 ['b+a+c',4064 {4065 expressions: ['a+b+c'],4066 },4067 {4068 answer: 'b+a+c',4069 check_status: STATUS_CORRECT4070 },4071 ],4072 ['b+a',4073 {4074 expressions: ['a+b'],4075 },4076 {4077 answer: 'b+a',4078 check_status: STATUS_CORRECT4079 },4080 ],4081 ['b+a+c',4082 {4083 expressions: ['a+b+c'],4084 },4085 {4086 answer: 'b+a+c',4087 check_status: STATUS_CORRECT4088 },4089 ],4090 ]4091 test.each(specs)('%s', (s, q, check) => {4092 const generated = generateQuestion(q)4093 const item = {4094 ...generated,4095 ...check4096 }4097 assessItem(item)4098 expect(item.status).toBe(item.check_status)4099 })...

Full Screen

Full Screen

res_config_settings.py

Source:res_config_settings.py Github

copy

Full Screen

1from odoo import api, fields, models2from odoo.tools import unquote3XML_ID = "base_epithelium._assets_primary_variables"4SCSS_URL = "/base_epithelium/static/src/scss/colors.scss"5class ResConfigSettingsMod(models.TransientModel):6 _inherit = 'res.config.settings'7 check_status = fields.Boolean('Localization',8 help='Company localization control')9 days_to_expiration = fields.Char('Days to Expiration', default=30)10 def set_values(self):11 res = super(ResConfigSettingsMod, self).set_values()12 parameter = self.env['ir.config_parameter'].sudo()13 parameter.set_param('res.config.settings.check_status', self.check_status)14 parameter.set_param('res.config.settings.days_to_expiration', self.days_to_expiration)15 variables = [16 'o-brand-odoo']17 colors = self.env['scss.editor.epithelium'].get_values(18 SCSS_URL, XML_ID, variables19 )20 if self.check_status:21 variables = [22 {'name': 'o-brand-odoo', 'value': "#003699"}]23 else:24 variables = [25 {'name': 'o-brand-odoo', 'value': "#7C7BAD"}]26 self.env['scss.editor.epithelium'].replace_values(27 SCSS_URL, XML_ID, variables28 )29 return res30 @api.model31 def get_values(self):32 res = super(ResConfigSettingsMod, self).get_values()33 parameter = self.env['ir.config_parameter'].sudo()34 check_status = parameter.get_param('res.config.settings.check_status')35 days_to_expiration = parameter.get_param('res.config.settings.days_to_expiration')36 res.update(37 {'check_status': check_status,38 'days_to_expiration': days_to_expiration})39 return res40 def execute(self):41 super(ResConfigSettingsMod, self).execute()42 if self.check_status:43 self._change_action_domain(True)44 else:45 self._change_action_domain(False)46 return {47 'type': 'ir.actions.client',48 'tag': 'reload',49 }50 def _change_action_domain(self, state):51 """52 Función que busca las acciones de la vista en el los menu item y cambia los dominions de las mismas,53 se pasa por parametro un state el cual funciona como un campo activo, si state es igual a true54 se modificaran los dominions de las acciones por ('check_status",'='.True), con el fin de mostrar unicamente55 los registros con el (check_status = true) en la vista.56 @author: Juanca Perdomo - Intello Idea57 """58 # Actions for Module Sale59 sale_action = self.env.ref('sale.action_quotations_with_onboarding')60 sale_orders_action = self.env.ref('sale.action_orders')61 sale_order_to_invoice_action = self.env.ref('sale.action_orders_to_invoice')62 sale_order_upsell = self.env.ref('sale.action_orders_upselling')63 sale_product = self.env.ref('sale.product_template_action')64 sale_report_action_order = self.env.ref('sale.action_order_report_all')65 # Actions for Module Accounting66 invoice_client_action = self.env.ref('account.action_move_out_invoice_type')67 credit_note_client_action = self.env.ref('account.action_move_out_refund_type')68 receipts_client_action = self.env.ref('account.action_move_out_receipt_type')69 account_product_action_client = self.env.ref('account.product_product_action_sellable')70 account_payment_action_client = self.env.ref('account.action_account_payments')71 account_journal_action = self.env.ref('account.open_account_journal_dashboard_kanban')72 bills_provider_action = self.env.ref('account.action_move_in_invoice_type')73 refund_provider_action = self.env.ref('account.action_move_in_refund_type')74 receipts_provider_action = self.env.ref('account.action_move_in_receipt_type')75 account_payment_action_provider = self.env.ref('account.action_account_payments_payable')76 account_product_action_provider = self.env.ref('account.product_product_action_purchasable')77 journal_action = self.env.ref('account.action_account_journal_form')78 # Actions for Module Purchase79 request_quotation_action = self.env.ref('purchase.purchase_rfq')80 purchase_order_action = self.env.ref('purchase.purchase_form_action')81 purchase_product = self.env.ref('purchase.product_normal_action_puchased')82 purchase_report = self.env.ref('purchase.action_purchase_order_report_all')83 # Actions for Module Inventory84 transference_action = self.env.ref('stock.action_picking_tree_all')85 inventory_adjust_action = self.env.ref('stock.action_inventory_form')86 scrap_orders_action = self.env.ref('stock.action_stock_scrap')87 product_stock = self.env.ref('stock.product_template_action_product')88#Carlos reordering_rules_action = self.env.ref('stock.action_orderpoint_form')89 product_move_line_action = self.env.ref('stock.stock_move_line_action')90 stock_move_action = self.env.ref('stock.stock_move_action')91 operation_types_action = self.env.ref('stock.action_picking_type_list')92 product_category = self.env.ref('product.product_category_action_form')93 product_code = self.env.ref('coding_products.action_coding_products')94 # Action for Module Manufacturing95 manufacturing_order_action = self.env.ref('mrp.mrp_production_action')96 unbuild_order_action = self.env.ref('mrp.mrp_unbuild')97 manufacturing_product_action = self.env.ref('mrp.product_template_action')98 production_lines_action = self.env.ref('base_epithelium.production_lines_action')99 master_production_action = self.env.ref('mrp_mps.action_mrp_mps')100 bills_materials_action = self.env.ref('mrp.mrp_bom_form_action')101 production_order = self.env.ref('mrp.mrp_production_report')102 work_order_report = self.env.ref('mrp.mrp_workorder_report')103 work_order_todo = self.env.ref('mrp.mrp_workorder_todo')104 # Action for Module Quality105 quality_point = self.env.ref('quality_control.quality_point_action')106 quality_check = self.env.ref('quality_control.quality_check_action_main')107 quality_alert = self.env.ref('quality_control.quality_alert_action_check')108 quality_team = self.env.ref('quality_control.quality_alert_action_team')109 quality_team_check = self.env.ref('quality_control.quality_check_action_team')110 quality_check_report = self.env.ref('quality_control.quality_check_action_report')111 quality_alert_report = self.env.ref('quality_control.quality_alert_action_report')112 # Stock Actions113 stock_picking_type_action = self.env.ref('stock.stock_picking_type_action')114 stock_quant_dashboard = self.env.ref('stock.dashboard_open_quants')115 stock_quantity_report = self.env.ref('stock.report_stock_quantity_action')116#Carlos stock_inventory_valuation = self.env.ref('stock_account.action_stock_inventory_valuation')117 # account accountant118 active_id = unquote("active_id")119 if state:120 # Action Module Sale121 sale_action.update({'domain': [('check_status', '=', True)]})122 sale_orders_action.update(123 {'domain': [('check_status', '=', True), ('state', 'not in', ('draft', 'sent', 'cancel'))]})124 sale_order_to_invoice_action.update(125 {'domain': [('invoice_status', '=', 'to invoice'), ('check_status', '=', True)]})126 sale_order_upsell.update({'domain': [('check_status', '=', True), ('invoice_status', '=', 'upselling')]})127 sale_product.update({'domain': [('check_status', '=', True)]})128 sale_report_action_order.update({'domain': [('order_id.check_status', '=', True)]})129 # Action Module Accounting130#Carlos invoice_client_action.update({'domain': [('check_status', '=', True), ('type', '=', 'out_invoice')]})131 invoice_client_action.update({'domain': [('check_status', '=', True), ('move_type', '=', 'out_invoice')]}) 132#Carlos credit_note_client_action.update({'domain': [('check_status', '=', True), ('type', '=', 'out_refund')]})133 credit_note_client_action.update({'domain': [('check_status', '=', True), ('move_type', '=', 'out_refund')]})134#Carlos receipts_client_action.update({'domain': [('check_status', '=', True), ('type', '=', 'out_receipt')]})135 receipts_client_action.update({'domain': [('check_status', '=', True), ('move_type', '=', 'out_receipt')]})136 account_product_action_client.update({'domain': [('check_status', '=', True)]})137 account_payment_action_client.update({'domain': [('journal_id.check_status', '=', True)]})138 account_journal_action.update({'domain': [('check_status', '=', True)]})139#Carlos bills_provider_action.update({'domain': [('check_status', '=', True), ('type', '=', 'in_invoice')]})140 bills_provider_action.update({'domain': [('check_status', '=', True), ('move_type', '=', 'in_invoice')]})141#Carlos refund_provider_action.update({'domain': [('type', '=', 'in_refund'), ('check_status', '=', True)]})142 refund_provider_action.update({'domain': [('move_type', '=', 'in_refund'), ('check_status', '=', True)]})143#Carlos receipts_provider_action.update({'domain': [('check_status', '=', True), ('type', '=', 'in_receipt')]})144 receipts_provider_action.update({'domain': [('check_status', '=', True), ('move_type', '=', 'in_receipt')]})145 account_payment_action_provider.update({'domain': [('journal_id.check_status', '=', True)]})146 account_product_action_provider.update({'domain': [('check_status', '=', True)]})147 journal_action.update({'domain': [('check_status', '=', True)]})148 # Action Module Purchase149 request_quotation_action.update({'domain': [('check_status', '=', True)]})150 purchase_order_action.update(151 {'domain': [('state', 'in', ('purchase', 'done')), ('check_status', '=', True)]})152 purchase_product.update({'domain': []}) #quite ('check_status', '=', True) requerimiento REQ-SP-000001153 purchase_report.update({'domain': [('order_id.check_status', '=', True)]})154 # Action Module Inventory155 transference_action.update({'domain': [('check_status', '=', True)]})156 inventory_adjust_action.update({'domain': [('product_ids.check_status', '=', True)]})157 scrap_orders_action.update({'domain': [('product_id.check_status', '=', True)]})158 product_stock.update({'domain': [('check_status', '=', True)]})159#Carlos reordering_rules_action.update({'domain': [('product_id.check_status', '=', True)]})160 product_move_line_action.update({'domain': [('product_id.check_status', '=', True)]})161 stock_move_action.update({'domain': [('product_id.check_status', '=', True)]})162 operation_types_action.update({'domain': [('check_status', '=', True)]})163 product_category.update({'domain': [('check_status', '=', True)]})164 product_code.update({'domain': [('check_status', '=', True)]})165 # Action Module Manufacturing166 manufacturing_order_action.update(167 {'domain': [('picking_type_id.active', '=', True), ('check_status', '=', True)]})168 unbuild_order_action.update({'domain': [('product_id.check_status', '=', True)]})169 manufacturing_product_action.update({'domain': [('check_status', '=', True)]})170 production_lines_action.update({'domain': [('check_status', '=', True)]})171 bills_materials_action.update({'domain': [('check_status', '=', True)]})172 production_order.update({'domain': [('check_status', '=', True)]})173 work_order_report.update({'domain': [('product_id.check_status', '=', True)]})174 work_order_todo.update({'domain': [('product_id.check_status', '=', True)]})175 # Action Module Quality176 quality_point.update({'domain': [('check_status', '=', True)]})177 quality_check.update({'domain': [('check_status', '=', True)]})178 quality_alert.update({'domain': [('check_status', '=', True)]})179 quality_check_report.update({'domain': [('check_status', '=', True)]})180 quality_alert_report.update({'domain': [('check_status', '=', True)]})181 quality_team.update({'domain': [('team_id', '=', active_id), ('check_status', '=', True)]})182 quality_team_check.update({'domain': [('team_id', '=', active_id), ('check_status', '=', True)]})183 # Stock184 stock_picking_type_action.update({'domain': [('check_status', '=', True)]})185# stock_inventory_valuation.update({'domain': [('product_id.type', '=', 'product'), '|',186# ('product_id.check_status', '=', True),187# ('product_tmpl_id.check_status', '=', True)]})188 stock_quantity_report.update({'domain': [('warehouse_id', '!=', False), '|',189 ('product_id.check_status', '=', True),190 ('product_tmpl_id.check_status', '=', True)]})191 stock_quant_dashboard.update(192 {'domain': ['|', ('product_id.check_status', '=', True), ('product_tmpl_id.check_status', '=', True)]})193 else:194 # Action Module Sale195 sale_action.update({'domain': []})196 sale_orders_action.update({'domain': [('state', 'not in', ('draft', 'sent', 'cancel'))]})197 sale_order_to_invoice_action.update({'domain': [('invoice_status', '=', 'to invoice')]})198 sale_order_upsell.update({'domain': [('invoice_status', '=', 'upselling')]})199 sale_product.update({'domain': []})200 sale_report_action_order.update({'domain': []})201 # Action Module Accounting202#Carlos invoice_client_action.update({'domain': [('type', '=', 'out_invoice')]})203#Carlos credit_note_client_action.update({'domain': [('type', '=', 'out_refund')]})204#Carlos receipts_client_action.update({'domain': [('type', '=', 'out_receipt')]})205 invoice_client_action.update({'domain': [('move_type', '=', 'out_invoice')]})206 credit_note_client_action.update({'domain': [('move_type', '=', 'out_refund')]})207 receipts_client_action.update({'domain': [('move_type', '=', 'out_receipt')]})208 account_product_action_client.update({'domain': []})209 account_payment_action_client.update({'domain': []})210 account_journal_action.update({'domain': []})211#Carlos bills_provider_action.update({'domain': [('type', '=', 'in_invoice')]})212#Carlos refund_provider_action.update({'domain': [('type', '=', 'in_refund')]})213#Carlos receipts_provider_action.update({'domain': [('type', '=', 'in_receipt')]})214 bills_provider_action.update({'domain': [('move_type', '=', 'in_invoice')]})215 refund_provider_action.update({'domain': [('move_type', '=', 'in_refund')]})216 receipts_provider_action.update({'domain': [('move_type', '=', 'in_receipt')]})217 account_payment_action_provider.update({'domain': []})218 account_product_action_provider.update({'domain': []})219 journal_action.update({'domain': []})220 # Action Module Purchase221 request_quotation_action.update({'domain': []})222 purchase_order_action.update({'domain': [('state', 'in', ('purchase', 'done'))]})223 purchase_product.update({'domain': []})224 purchase_report.update({'domain': []})225 # Action Module Inventory226 transference_action.update({'domain': []})227 inventory_adjust_action.update({'domain': []})228 scrap_orders_action.update({'domain': []})229 product_stock.update({'domain': []})230# reordering_rules_action.update({'domain': []})231 product_move_line_action.update({'domain': []})232 stock_move_action.update({'domain': []})233 operation_types_action.update({'domain': []})234 product_category.update({'domain': []})235 product_code.update({'domain': []})236 # Action Module Manufacturing237 manufacturing_order_action.update({'domain': [('picking_type_id.active', '=', True)]})238 unbuild_order_action.update({'domain': []})239 manufacturing_product_action.update({'domain': []})240 production_lines_action.update({'domain': []})241 bills_materials_action.update({'domain': []})242 production_order.update({'domain': []})243 work_order_report.update({'domain': []})244 work_order_todo.update({'domain': []})245 # Action Quality246 quality_point.update({'domain': []})247 quality_check.update({'domain': []})248 quality_alert.update({'domain': []})249 quality_check_report.update({'domain': []})250 quality_alert_report.update({'domain': []})251 quality_team.update({'domain': [('team_id', '=', active_id)]})252 quality_team_check.update({'domain': [('team_id', '=', active_id)]})253 # Stock254 stock_picking_type_action.update({'domain': []})255 stock_quant_dashboard.update({'domain': []})256 stock_quantity_report.update({'domain': [('warehouse_id', '!=', False)]})...

Full Screen

Full Screen

product.py

Source:product.py Github

copy

Full Screen

...58 domain = {'categ_id': [('check_status', '=', False)]}59 return {'domain': domain}60class Product(models.Model):61 _inherit = 'product.product'62 def default_check_status(self):63 parameter = self.env['ir.config_parameter'].sudo()64 check_status = parameter.get_param('res.config.settings.check_status')65 return check_status66 check_status = fields.Boolean('I.', default=default_check_status, related='product_tmpl_id.check_status')67 check_status_group = fields.Boolean('Check product group', related="product_group.check_status")68 check_status_categ = fields.Boolean('Check product categ', related="categ_id.check_status")69 affect_bill_materials = fields.Boolean('Affects bill of materials', related='product_tmpl_id.affect_bill_materials')70 @api.model71 def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):72 parameter = self.env['ir.config_parameter'].sudo()73 check_status = parameter.get_param('res.config.settings.check_status')74 res = super(Product, self).fields_view_get(view_id=view_id,75 view_type=view_type,76 toolbar=toolbar,77 submenu=submenu)78 doc = etree.XML(res['arch'])79 for node in doc.xpath("//field[@name='product_group']"):80 if check_status:81 node.set('domain', "[('check_status', '=', True)]")82 else:83 node.set('domain', "[]")84 for node in doc.xpath("//field[@name='check_status']"):85 if check_status:86 node.set("readonly", "1")87 modifiers = json.loads(node.get("modifiers"))88 modifiers['readonly'] = True89 node.set("modifiers", json.dumps(modifiers))90 else:91 node.set("readonly", "0")92 modifiers = json.loads(node.get("modifiers"))93 modifiers['readonly'] = ['|',('check_status_group', '=',False),('check_status_categ', '=',False)]94 node.set("modifiers", json.dumps(modifiers))95 res['arch'] = etree.tostring(doc)96 return res97 @api.onchange('categ_id')98 def onchange_categ_id(self):99 self.check_status = self.categ_id.check_status100 @api.onchange('product_group')101 def onchange_product_group(self):102 domain = {'categ_id': []}103 parameter = self.env['ir.config_parameter'].sudo()104 check_status = parameter.get_param('res.config.settings.check_status')105 if self.product_group.check_status != self.categ_id.check_status:106 self.categ_id = False107 if check_status:108 domain = {'categ_id': [('check_status', '=', True)]}109 else:110 if not self.product_group.check_status:111 domain = {'categ_id': [('check_status', '=', False)]}112 return {'domain': domain}113class ProductCategory(models.Model):114 _inherit = 'product.category'115 def default_check_status(self):116 parameter = self.env['ir.config_parameter'].sudo()117 check_status = parameter.get_param('res.config.settings.check_status')118 return check_status119 check_status = fields.Boolean('I.', default=default_check_status)120 @api.model121 def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):122 parameter = self.env['ir.config_parameter'].sudo()123 check_status = parameter.get_param('res.config.settings.check_status')124 res = super(ProductCategory, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar,125 submenu=submenu)126 doc = etree.XML(res['arch'])127 for node in doc.xpath("//field[@name='check_status']"):128 if check_status:129 node.set("readonly", "1")130 modifiers = json.loads(node.get("modifiers"))131 modifiers['readonly'] = True132 node.set("modifiers", json.dumps(modifiers))133 else:134 node.set("readonly", "0")135 modifiers = json.loads(node.get("modifiers"))136 modifiers['readonly'] = False137 node.set("modifiers", json.dumps(modifiers))138 res['arch'] = etree.tostring(doc)139 return res140class ProductGroup(models.Model):141 _inherit = 'product.group'142 def default_check_status(self):143 parameter = self.env['ir.config_parameter'].sudo()144 check_status = parameter.get_param('res.config.settings.check_status')145 return check_status146 check_status = fields.Boolean('I.', default=default_check_status)147 @api.model148 def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):149 parameter = self.env['ir.config_parameter'].sudo()150 check_status = parameter.get_param('res.config.settings.check_status')151 res = super(ProductGroup, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar,152 submenu=submenu)153 doc = etree.XML(res['arch'])154 for node in doc.xpath("//field[@name='check_status']"):155 if check_status:156 node.set("readonly", "1")...

Full Screen

Full Screen

quality.py

Source:quality.py Github

copy

Full Screen

2from lxml import etree3import json4class QualityPoint(models.Model):5 _inherit = "quality.point"6 def default_check_status(self):7 parameter = self.env['ir.config_parameter'].sudo()8 check_status = parameter.get_param('res.config.settings.check_status')9 return check_status10 check_status = fields.Boolean('I.', default=default_check_status)11 @api.model12 def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):13 parameter = self.env['ir.config_parameter'].sudo()14 check_status = parameter.get_param('res.config.settings.check_status')15 res = super(QualityPoint, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar,16 submenu=submenu)17 doc = etree.XML(res['arch'])18 for node in doc.xpath("//field[@name='product_tmpl_id']"):19 if check_status:20 node.set('domain',21 "[('type', 'in', ['consu', 'product']), '|', ('company_id', '=', False), ('company_id', '=', company_id),('check_status', '=', True)]")22 else:23 node.set('domain',24 "[('type', 'in', ['consu', 'product']), '|', ('company_id', '=', False), ('company_id', '=', company_id)]")25 res['arch'] = etree.tostring(doc)26 return res27 @api.onchange('product_ids')28 def check_invima_products(self):29 if self.product_ids:30 status = True31 else:32 status = False33 for product in self.product_ids:34 status = status and product.check_status35 self.check_status = status36 @api.onchange('product_tmpl_id')37 def check_invima_change(self):38 if self.product_tmpl_id:39 self.check_status = self.product_tmpl_id.check_status40class QualityCheck(models.Model):41 _inherit = "quality.check"42 def default_check_status(self):43 parameter = self.env['ir.config_parameter'].sudo()44 check_status = parameter.get_param('res.config.settings.check_status')45 return check_status46 check_status = fields.Boolean('I.', default=default_check_status)47 @api.model48 def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):49 parameter = self.env['ir.config_parameter'].sudo()50 check_status = parameter.get_param('res.config.settings.check_status')51 res = super(QualityCheck, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar,52 submenu=submenu)53 doc = etree.XML(res['arch'])54 for node in doc.xpath("//field[@name='product_id']"):55 if check_status:56 node.set('domain',57 "[('type', 'in', ['consu', 'product']), '|', ('company_id', '=', False), ('company_id', '=', company_id),('check_status', '=', True)]")58 else:59 node.set('domain',60 "[('type', 'in', ['consu', 'product']), '|', ('company_id', '=', False), ('company_id', '=', company_id)]")61 res['arch'] = etree.tostring(doc)62 return res63 @api.onchange('product_id')64 def check_invima_change(self):65 if self.product_id:66 self.check_status = self.product_id.check_status67class QualityAlert(models.Model):68 _inherit = "quality.alert"69 def default_check_status(self):70 parameter = self.env['ir.config_parameter'].sudo()71 check_status = parameter.get_param('res.config.settings.check_status')72 return check_status73 check_status = fields.Boolean('I.', default=default_check_status)74 @api.model75 def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):76 parameter = self.env['ir.config_parameter'].sudo()77 check_status = parameter.get_param('res.config.settings.check_status')78 res = super(QualityAlert, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar,79 submenu=submenu)80 doc = etree.XML(res['arch'])81 for node in doc.xpath("//field[@name='product_tmpl_id']"):82 if check_status:83 node.set('domain',...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful