From 02f21d45d9bc63cd8898aacff0e03a6d091a8247 Mon Sep 17 00:00:00 2001 From: facundoy Date: Sun, 24 Nov 2024 15:50:49 -0500 Subject: [PATCH] Provided number of tests for test validation changes based on the number of tests in the editor box during instructor mode --- src/haz3lschool/Exercise.re | 51 ++++++++++++++++++------------ src/haz3lweb/Editors.re | 60 +++++++++++++++++++++++++++++------- src/haz3lweb/Grading.re | 6 ---- src/haz3lweb/Update.re | 17 +++++----- src/haz3lweb/UpdateAction.re | 2 +- 5 files changed, 91 insertions(+), 45 deletions(-) diff --git a/src/haz3lschool/Exercise.re b/src/haz3lschool/Exercise.re index eff5b3b69..8b00d84d1 100644 --- a/src/haz3lschool/Exercise.re +++ b/src/haz3lschool/Exercise.re @@ -177,7 +177,13 @@ module F = (ExerciseEnv: ExerciseEnv) => { | HiddenTests => eds.hidden_tests.tests }; - let put_editor = ({pos, eds, _} as state: state, editor: Editor.t) => + let put_editor = + ( + {pos, eds, _} as state: state, + editor: Editor.t, + new_prov_test: int, + instructor_mode: bool, + ) => switch (pos) { | Prelude => { ...state, @@ -194,16 +200,29 @@ module F = (ExerciseEnv: ExerciseEnv) => { }, } | YourTestsValidation - | YourTestsTesting => { - ...state, - eds: { - ...eds, - your_tests: { - ...eds.your_tests, - tests: editor, + | YourTestsTesting => + instructor_mode + ? { + ...state, + eds: { + ...eds, + your_tests: { + ...eds.your_tests, + tests: editor, + provided: new_prov_test, + }, + } /* Set 'provided' to 1 if editing_test_val_rep is true */ + } + : { + ...state, + eds: { + ...eds, + your_tests: { + ...eds.your_tests, + tests: editor, + }, }, - }, - } + } | YourImpl => { ...state, eds: { @@ -542,7 +561,7 @@ module F = (ExerciseEnv: ExerciseEnv) => { }, }; let new_state = set_editing_title(new_state, editing_title); - put_editor(new_state, new_buggy_impl.impl); + put_editor(new_state, new_buggy_impl.impl, 0, false); }; let delete_buggy_impl = (state: state, index: int) => { @@ -567,7 +586,7 @@ module F = (ExerciseEnv: ExerciseEnv) => { List.filteri((i, _) => i != index, state.eds.hidden_bugs), }, }; - put_editor(new_state, editor_on); + put_editor(new_state, editor_on, 0, false); }; let set_editing_prompt = ({eds, _} as state: state, editing: bool) => { @@ -635,19 +654,13 @@ module F = (ExerciseEnv: ExerciseEnv) => { }; let update_test_val_rep = - ( - {eds, _} as state: state, - new_test_num: int, - new_dist: int, - new_prov: int, - ) => { + ({eds, _} as state: state, new_test_num: int, new_dist: int) => { ...state, eds: { ...eds, your_tests: { ...eds.your_tests, required: new_test_num, - provided: new_prov, }, point_distribution: { ...eds.point_distribution, diff --git a/src/haz3lweb/Editors.re b/src/haz3lweb/Editors.re index 229e411f1..8acf06698 100644 --- a/src/haz3lweb/Editors.re +++ b/src/haz3lweb/Editors.re @@ -37,7 +37,44 @@ let put_editor = (ed: Editor.t, eds: t): t => assert(List.mem_assoc(name, slides)); Documentation(name, slides |> ListUtil.update_assoc((name, ed))); | Exercises(n, specs, exercise) => - Exercises(n, specs, Exercise.put_editor(exercise, ed)) + Exercises(n, specs, Exercise.put_editor(exercise, ed, 0, false)) + }; + +let put_editor_action = + ( + ed: Editor.t, + eds: t, + results: ModelResults.t, + ~settings: CoreSettings.t, + instructor_mode: bool, + ) + : t => + switch (eds) { + | Scratch(n, slides) => + assert(n < List.length(slides)); + Scratch(n, Util.ListUtil.put_nth(n, ed, slides)); + | Documentation(name, slides) => + assert(List.mem_assoc(name, slides)); + Documentation(name, slides |> ListUtil.update_assoc((name, ed))); + | Exercises(n, specs, exercise) => + let stitched_dynamics = + Exercise.stitch_dynamic( + settings, + exercise, + settings.dynamics ? Some(results) : None, + ); + let test_results = + ModelResult.test_results(stitched_dynamics.test_validation.result); + let new_prov_test = + switch (test_results) { + | Some(test_results) => test_results.total + | None => 0 + }; + Exercises( + n, + specs, + Exercise.put_editor(exercise, ed, new_prov_test, instructor_mode), + ); }; let update = (f: Editor.t => Editor.t, editors: t): t => @@ -47,7 +84,13 @@ let update_opt = (editors: t, f: Editor.t => option(Editor.t)): option(t) => editors |> get_editor |> f |> Option.map(put_editor(_, editors)); let perform_action = - (~settings: CoreSettings.t, editors: t, a: Action.t) + ( + ~settings: CoreSettings.t, + editors: t, + a: Action.t, + results: ModelResults.t, + instructor_mode: bool, + ) : UpdateAction.Result.t(t) => { let settings = switch (editors) { @@ -59,7 +102,8 @@ let perform_action = }; switch (Perform.go(~settings, a, get_editor(editors))) { | Error(err) => Error(FailedToPerform(err)) - | Ok(ed) => Ok(put_editor(ed, editors)) + | Ok(ed) => + Ok(put_editor_action(ed, editors, results, ~settings, instructor_mode)) }; }; @@ -182,8 +226,7 @@ let set_editing_test_val_rep = (editors: t, editing: bool): t => Exercises(n, specs, Exercise.set_editing_test_val_rep(exercise, editing)) }; -let update_test_val_rep = - (editors: t, new_test_num: int, new_dist: int, new_prov: int): t => +let update_test_val_rep = (editors: t, new_test_num: int, new_dist: int): t => switch (editors) { | Scratch(_) | Documentation(_) => editors @@ -191,12 +234,7 @@ let update_test_val_rep = Exercises( n, specs, - Exercise.update_test_val_rep( - exercise, - new_test_num, - new_dist, - new_prov, - ), + Exercise.update_test_val_rep(exercise, new_test_num, new_dist), ) }; diff --git a/src/haz3lweb/Grading.re b/src/haz3lweb/Grading.re index 7e774b870..1661748c9 100644 --- a/src/haz3lweb/Grading.re +++ b/src/haz3lweb/Grading.re @@ -122,11 +122,6 @@ module TestValidationReport = { ), ), )##.value; - let new_prov_test = - switch (report.test_results) { - | Some(test_results) => test_results.total - | None => 0 - }; let update_events = [ inject(Set(EditingTestValRep)), @@ -134,7 +129,6 @@ module TestValidationReport = { UpdateTestValRep( int_of_string(new_test_num), int_of_string(new_dist), - new_prov_test, ), ), ]; diff --git a/src/haz3lweb/Update.re b/src/haz3lweb/Update.re index aeb083124..6d6e13ef3 100644 --- a/src/haz3lweb/Update.re +++ b/src/haz3lweb/Update.re @@ -488,7 +488,13 @@ let ui_state_update = let apply = (model: Model.t, update: t, ~schedule_action): Result.t(Model.t) => { let perform_action = (model: Model.t, a: Action.t): Result.t(Model.t) => { switch ( - Editors.perform_action(~settings=model.settings.core, model.editors, a) + Editors.perform_action( + ~settings=model.settings.core, + model.editors, + a, + model.results, + model.settings.instructor_mode, + ) ) { | Error(err) => Error(err) | Ok(editors) => Ok({...model, editors}) @@ -702,16 +708,11 @@ let apply = (model: Model.t, update: t, ~schedule_action): Result.t(Model.t) => ...model, editors: Editors.update_exercise_prompt(model.editors, new_prompt), }) - | UpdateTestValRep(new_test_num, new_dist, new_prov) => + | UpdateTestValRep(new_test_num, new_dist) => Model.save_and_return({ ...model, editors: - Editors.update_test_val_rep( - model.editors, - new_test_num, - new_dist, - new_prov, - ), + Editors.update_test_val_rep(model.editors, new_test_num, new_dist), }) | UpdateMutTestRep(new_dist) => Model.save_and_return({ diff --git a/src/haz3lweb/UpdateAction.re b/src/haz3lweb/UpdateAction.re index b60452aa3..30cd8a7f9 100644 --- a/src/haz3lweb/UpdateAction.re +++ b/src/haz3lweb/UpdateAction.re @@ -100,7 +100,7 @@ type t = | AddBuggyImplementation | DeleteBuggyImplementation(int) | UpdatePrompt(string) - | UpdateTestValRep(int, int, int) + | UpdateTestValRep(int, int) | UpdateMutTestRep(int) | UpdateImplGrdRep(int) | UpdateModuleName(string);