Skip to content

Commit

Permalink
fixed bug with exercise indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
russell-rozenbaum committed Dec 21, 2024
1 parent 976f67e commit dec734e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 27 deletions.
53 changes: 31 additions & 22 deletions src/haz3lweb/app/editors/mode/ExercisesMode.re
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ module Model = {
};

let persist = (~instructor_mode, model): persistent => {
cur_exercise: List.nth(model.exercises, model.current).editors.id,
exercise_data:
List.map(
(exercise: ExerciseMode.Model.t) =>
(
exercise.editors.id,
ExerciseMode.Model.persist(~instructor_mode, exercise),
),
model.exercises,
),
{
cur_exercise: List.nth(model.exercises, model.current).editors.id,
exercise_data:
List.map(
(exercise: ExerciseMode.Model.t) =>
(
exercise.editors.id,
ExerciseMode.Model.persist(~instructor_mode, exercise),
),
model.exercises,
),
};
};

let unpersist = (~instructor_mode, persistent: persistent) => {
Expand Down Expand Up @@ -464,18 +466,25 @@ module View = {
@ EditorModeView.view(
~signal=
fun
| Previous =>
inject(
Update.SwitchExercise(
abs((model.current - 1) mod List.length(model.exercises)),
),
)
| Next =>
inject(
Update.SwitchExercise(
(model.current + 1) mod List.length(model.exercises),
),
),
| Previous => {
let next = model.current - 1;
let len = List.length(model.exercises);
print_endline("Length is: ");
print_endline(string_of_int((next mod len + len) mod len));
inject(
Update.SwitchExercise(
// Ensures positive index
(next mod len + len) mod len,
),
);
}
| Next => {
inject(
Update.SwitchExercise(
(model.current + 1) mod List.length(model.exercises),
),
);
},
~indicator=
EditorModeView.indicator_n(
model.current,
Expand Down
10 changes: 8 additions & 2 deletions src/haz3lweb/exercises/Exercise.re
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ type persistent_state = {
point_distribution,
required: int,
module_name: string,
syntax_tests: list(syntax_test),
hidden_test_hints: list(string),
// NOTE: Add new fields to record here as new instructor editable features are
// implemented (eg. prelude: PersistentZipper.t when adding the feature
// to edit the prelude). After adding these field(s), we will need to
Expand Down Expand Up @@ -784,6 +786,8 @@ let persist = (state: state, ~instructor_mode: bool) => {
point_distribution: state.eds.point_distribution,
required: state.eds.your_tests.required,
module_name: state.eds.module_name,
syntax_tests: state.eds.syntax_tests,
hidden_test_hints: state.eds.hidden_tests.hints,
};
};

Expand All @@ -797,6 +801,8 @@ let unpersist =
point_distribution,
required,
module_name,
syntax_tests,
hidden_test_hints,
}: persistent_state,
~spec: spec,
~instructor_mode: bool,
Expand Down Expand Up @@ -839,9 +845,9 @@ let unpersist =
hidden_bugs,
hidden_tests: {
tests: hidden_tests_tests,
hints: spec.hidden_tests.hints,
hints: hidden_test_hints,
},
syntax_tests: spec.syntax_tests,
syntax_tests,
},
};
};
7 changes: 4 additions & 3 deletions src/haz3lweb/exercises/examples/Ex_RecursiveFibonacci.ml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dec734e

Please sign in to comment.