Skip to content

Commit

Permalink
Provided number of tests for test validation changes based on the num…
Browse files Browse the repository at this point in the history
…ber of tests in the editor box during instructor mode
  • Loading branch information
facundoy committed Nov 24, 2024
1 parent a09ceb2 commit 02f21d4
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 45 deletions.
51 changes: 32 additions & 19 deletions src/haz3lschool/Exercise.re
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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: {
Expand Down Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand Down Expand Up @@ -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,
Expand Down
60 changes: 49 additions & 11 deletions src/haz3lweb/Editors.re
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand All @@ -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) {
Expand All @@ -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))
};
};

Expand Down Expand Up @@ -182,21 +226,15 @@ 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
| Exercises(n, specs, exercise) =>
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),
)
};

Expand Down
6 changes: 0 additions & 6 deletions src/haz3lweb/Grading.re
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,13 @@ 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)),
inject(
UpdateTestValRep(
int_of_string(new_test_num),
int_of_string(new_dist),
new_prov_test,
),
),
];
Expand Down
17 changes: 9 additions & 8 deletions src/haz3lweb/Update.re
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lweb/UpdateAction.re
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type t =
| AddBuggyImplementation
| DeleteBuggyImplementation(int)
| UpdatePrompt(string)
| UpdateTestValRep(int, int, int)
| UpdateTestValRep(int, int)
| UpdateMutTestRep(int)
| UpdateImplGrdRep(int)
| UpdateModuleName(string);
Expand Down

0 comments on commit 02f21d4

Please sign in to comment.