diff --git a/swad_changelog.h b/swad_changelog.h index 964b5304..c3081177 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -548,10 +548,11 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.228 (2020-05-13)" +#define Log_PLATFORM_VERSION "SWAD 19.228.1 (2020-05-13)" #define CSS_FILE "swad19.217.css" #define JS_FILE "swad19.223.js" /* + Version 19.228.1: May 13, 2020 Code refactoring in exam prints. (303828 lines) Version 19.228: May 13, 2020 Code refactoring and bug fixing in exam prints. (303837 lines) Version 19.227.1: May 13, 2020 Cache of linked GIFs and videos. (303612 lines) Version 19.227: May 13, 2020 Cache of linked images. (303586 lines) diff --git a/swad_exam_print.c b/swad_exam_print.c index 1b3a48c2..82add70f 100644 --- a/swad_exam_print.c +++ b/swad_exam_print.c @@ -1095,23 +1095,19 @@ static void ExaPrn_ComputeScoreAndStoreQuestionOfPrint (struct ExaPrn_Print *Pri void ExaPrn_ComputeAnswerScore (struct TstPrn_PrintedQuestion *PrintedQuestion, struct Tst_Question *Question) { - /***** Write answer depending on type *****/ - switch (Question->Answer.Type) - { - case Tst_ANS_INT: - ExaPrn_GetCorrectAndComputeIntAnsScore (PrintedQuestion,Question); break; - case Tst_ANS_FLOAT: - ExaPrn_GetCorrectAndComputeFltAnsScore (PrintedQuestion,Question); break; - case Tst_ANS_TRUE_FALSE: - ExaPrn_GetCorrectAndComputeTF_AnsScore (PrintedQuestion,Question); break; - case Tst_ANS_UNIQUE_CHOICE: - case Tst_ANS_MULTIPLE_CHOICE: - ExaPrn_GetCorrectAndComputeChoAnsScore (PrintedQuestion,Question); break; - case Tst_ANS_TEXT: - ExaPrn_GetCorrectAndComputeTxtAnsScore (PrintedQuestion,Question); break; - default: - break; - } + void (*ExaPrn_GetCorrectAndComputeAnsScore[Tst_NUM_ANS_TYPES]) (struct TstPrn_PrintedQuestion *PrintedQuestion, + struct Tst_Question *Question) = + { + [Tst_ANS_INT ] = ExaPrn_GetCorrectAndComputeIntAnsScore, + [Tst_ANS_FLOAT ] = ExaPrn_GetCorrectAndComputeFltAnsScore, + [Tst_ANS_TRUE_FALSE ] = ExaPrn_GetCorrectAndComputeTF_AnsScore, + [Tst_ANS_UNIQUE_CHOICE ] = ExaPrn_GetCorrectAndComputeChoAnsScore, + [Tst_ANS_MULTIPLE_CHOICE] = ExaPrn_GetCorrectAndComputeChoAnsScore, + [Tst_ANS_TEXT ] = ExaPrn_GetCorrectAndComputeTxtAnsScore, + }; + + /***** Get correct answer and compute answer score depending on type *****/ + ExaPrn_GetCorrectAndComputeAnsScore[Question->Answer.Type] (PrintedQuestion,Question); } /*****************************************************************************/ diff --git a/swad_test_print.c b/swad_test_print.c index efc9c9d7..b8df9f00 100644 --- a/swad_test_print.c +++ b/swad_test_print.c @@ -403,23 +403,19 @@ void TstPrn_ComputeScoresAndStoreQuestionsOfPrint (struct TstPrn_Print *Print, void TstPrn_ComputeAnswerScore (struct TstPrn_PrintedQuestion *PrintedQuestion, struct Tst_Question *Question) { - /***** Write answer depending on type *****/ - switch (Question->Answer.Type) - { - case Tst_ANS_INT: - TstPrn_GetCorrectAndComputeIntAnsScore (PrintedQuestion,Question); break; - case Tst_ANS_FLOAT: - TstPrn_GetCorrectAndComputeFltAnsScore (PrintedQuestion,Question); break; - case Tst_ANS_TRUE_FALSE: - TstPrn_GetCorrectAndComputeTF_AnsScore (PrintedQuestion,Question); break; - case Tst_ANS_UNIQUE_CHOICE: - case Tst_ANS_MULTIPLE_CHOICE: - TstPrn_GetCorrectAndComputeChoAnsScore (PrintedQuestion,Question); break; - case Tst_ANS_TEXT: - TstPrn_GetCorrectAndComputeTxtAnsScore (PrintedQuestion,Question); break; - default: - break; - } + void (*TstPrn_GetCorrectAndComputeAnsScore[Tst_NUM_ANS_TYPES]) (struct TstPrn_PrintedQuestion *PrintedQuestion, + struct Tst_Question *Question) = + { + [Tst_ANS_INT ] = TstPrn_GetCorrectAndComputeIntAnsScore, + [Tst_ANS_FLOAT ] = TstPrn_GetCorrectAndComputeFltAnsScore, + [Tst_ANS_TRUE_FALSE ] = TstPrn_GetCorrectAndComputeTF_AnsScore, + [Tst_ANS_UNIQUE_CHOICE ] = TstPrn_GetCorrectAndComputeChoAnsScore, + [Tst_ANS_MULTIPLE_CHOICE] = TstPrn_GetCorrectAndComputeChoAnsScore, + [Tst_ANS_TEXT ] = TstPrn_GetCorrectAndComputeTxtAnsScore, + }; + + /***** Get correct answer and compute answer score depending on type *****/ + TstPrn_GetCorrectAndComputeAnsScore[Question->Answer.Type] (PrintedQuestion,Question); } /*****************************************************************************/ diff --git a/swad_test_print.h b/swad_test_print.h index 86ed5e4d..a1e4a0af 100644 --- a/swad_test_print.h +++ b/swad_test_print.h @@ -78,6 +78,7 @@ void TstPrn_ComputeAnswerScore (struct TstPrn_PrintedQuestion *PrintedQuestion, struct Tst_Question *Question); //----------------------------------------------------------------------------- + void TstPrn_ComputeIntAnsScore (struct TstPrn_PrintedQuestion *PrintedQuestion, const struct Tst_Question *Question); void TstPrn_ComputeFltAnsScore (struct TstPrn_PrintedQuestion *PrintedQuestion,