Skip to content

Commit

Permalink
added functionality for creating and deleting buggy implementations; …
Browse files Browse the repository at this point in the history
…to-do: allow editing of implementation hints as they default to "no hint available"
  • Loading branch information
russell-rozenbaum committed Jun 27, 2024
1 parent 6ffc5cf commit a1e82bf
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 10 deletions.
41 changes: 41 additions & 0 deletions src/haz3lschool/Exercise.re
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,47 @@ module F = (ExerciseEnv: ExerciseEnv) => {
},
};

let add_buggy_impl = (state: state) => {
let new_buggy_impl = {
impl: Editor.init(Zipper.init()),
hint: "no hint available",
};
let new_state = {
pos: HiddenBugs(List.length(state.eds.hidden_bugs)),
eds: {
...state.eds,
hidden_bugs: state.eds.hidden_bugs @ [new_buggy_impl],
},
};
put_editor(new_state, new_buggy_impl.impl);
};

let delete_buggy_impl = (state: state, index: int) => {
let length = List.length(state.eds.hidden_bugs);
let flag = length > 1;
let editor_on =
flag
? List.nth(
state.eds.hidden_bugs,
index < length - 1 ? index + 1 : index - 1,
).
impl
: state.eds.your_tests.tests;
let position =
flag
? HiddenBugs(index < length - 1 ? index : index - 1)
: YourTestsValidation;
let new_state = {
pos: position,
eds: {
...state.eds,
hidden_bugs:
List.filteri((i, _) => i != index, state.eds.hidden_bugs),
},
};
put_editor(new_state, editor_on);
};

let visible_in = (pos, ~instructor_mode) => {
switch (pos) {
| Prelude => instructor_mode
Expand Down
37 changes: 37 additions & 0 deletions src/haz3lweb/Editors.re
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,43 @@ let update_exercise_title = (editors: t, new_title: string): t =>
)
};

let add_buggy_impl = (editors: t) => {
switch (editors) {
| Scratch(_)
| Documentation(_) => editors
| Exercises(n, specs, exercise) =>
let new_buggy_impl = {
Exercise.impl: Zipper.init(),
hint: "no hint available",
};
Exercises(
n,
ListUtil.update_nth(n, specs, spec => {
{...spec, hidden_bugs: spec.hidden_bugs @ [new_buggy_impl]}
}),
Exercise.add_buggy_impl(exercise),
);
};
};

let delete_buggy_impl = (editors: t, index: int) => {
switch (editors) {
| Scratch(_)
| Documentation(_) => editors
| Exercises(n, specs, exercise) =>
Exercises(
n,
ListUtil.update_nth(n, specs, spec => {
{
...spec,
hidden_bugs: List.filteri((i, _) => i != index, spec.hidden_bugs),
}
}),
Exercise.delete_buggy_impl(exercise, index),
)
};
};

let reset_nth_slide = (n, slides) => {
let (_, init_editors, _) = Init.startup.scratch;
let data = List.nth(init_editors, n);
Expand Down
2 changes: 2 additions & 0 deletions src/haz3lweb/Log.re
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ let is_action_logged: UpdateAction.t => bool =
| MoveToNextHole(_)
| UpdateResult(_)
| UpdateTitle(_)
| AddBuggyImplementation
| DeleteBuggyImplementation(_)
| ToggleStepper(_)
| StepperAction(_, StepForward(_) | StepBackward)
| UpdateExplainThisModel(_) => true;
Expand Down
10 changes: 10 additions & 0 deletions src/haz3lweb/Update.re
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,16 @@ let rec apply =
...model,
editors: Editors.update_exercise_title(model.editors, new_title),
})
| AddBuggyImplementation =>
Model.save_and_return({
...model,
editors: Editors.add_buggy_impl(model.editors),
})
| DeleteBuggyImplementation(index) =>
Model.save_and_return({
...model,
editors: Editors.delete_buggy_impl(model.editors, index),
})
};
m |> Result.map(~f=update_cached_data(~schedule_action, update));
};
10 changes: 9 additions & 1 deletion src/haz3lweb/UpdateAction.re
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ type t =
| ToggleStepper(ModelResults.Key.t)
| StepperAction(ModelResults.Key.t, stepper_action)
| UpdateResult(ModelResults.t)
| UpdateTitle(string);
| UpdateTitle(string)
| AddBuggyImplementation
| DeleteBuggyImplementation(int);

module Failure = {
[@deriving (show({with_path: false}), sexp, yojson)]
Expand Down Expand Up @@ -158,6 +160,8 @@ let is_edit: t => bool =
| ResetCurrentEditor
| Assistant(AcceptSuggestion)
| UpdateTitle(_)
| AddBuggyImplementation
| DeleteBuggyImplementation(_)
| Reset => true
| UpdateResult(_)
| SwitchEditor(_)
Expand Down Expand Up @@ -208,6 +212,8 @@ let reevaluate_post_update: t => bool =
}
| Assistant(AcceptSuggestion) => true
| UpdateTitle(_)
| AddBuggyImplementation
| DeleteBuggyImplementation(_)
| Assistant(Prompt(_)) => false
| MoveToNextHole(_)
| Save
Expand Down Expand Up @@ -264,6 +270,8 @@ let should_scroll_to_caret =
| UpdateResult(_)
| ToggleStepper(_)
| UpdateTitle(_)
| AddBuggyImplementation
| DeleteBuggyImplementation(_)
| StepperAction(_, StepBackward | StepForward(_)) => false
| Assistant(AcceptSuggestion) => true
| FinishImportScratchpad(_)
Expand Down
7 changes: 4 additions & 3 deletions src/haz3lweb/view/Cell.re
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,14 @@ let editor_view =
locked ? "locked" : "unlocked",
]),
[
div(~attr=Attr.class_("cell-item"), Option.to_list(caption)),
div(
~attr=
Attr.many([
Attr.class_("cell-item"),
Attr.on_mousedown(on_mousedown),
]),
Option.to_list(caption) @ mousedown_overlay @ [code_view],
mousedown_overlay @ [code_view],
),
]
@ (footer |> Option.to_list |> List.concat),
Expand Down Expand Up @@ -402,7 +403,7 @@ let instructor_title_cell = (~inject, ~title) => {
);
};

let wrong_impl_caption = (~inject, sub: string) => {
let wrong_impl_caption = (~inject, sub: string, n: int) => {
div(
~attr=Attr.class_("wrong-impl-cell-caption"),
[
Expand All @@ -412,7 +413,7 @@ let wrong_impl_caption = (~inject, sub: string) => {
[
Widgets.button(
Icons.delete,
_ => inject(UpdateAction.Set(EditingTitle)),
_ => inject(UpdateAction.DeleteBuggyImplementation(n)),
~tooltip="Delete Buggy Implementation",
),
],
Expand Down
4 changes: 2 additions & 2 deletions src/haz3lweb/view/ExerciseMode.re
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ let view =
~highlights,
~caption=
switch (this_pos) {
| HiddenBugs(_) => Cell.wrong_impl_caption(~inject, caption)
| HiddenBugs(n) => Cell.wrong_impl_caption(~inject, caption, n)
| _ => Cell.caption(caption, ~rest=?subcaption)
},
~target_id=Exercise.show_pos(this_pos),
Expand Down Expand Up @@ -210,7 +210,7 @@ let view =
[
Widgets.button(
Icons.add,
_ => inject(UpdateAction.Set(EditingTitle)),
_ => inject(UpdateAction.AddBuggyImplementation),
~tooltip="Add Buggy Implementation",
),
],
Expand Down
9 changes: 5 additions & 4 deletions src/haz3lweb/view/Icons.re
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,10 @@ let delete =
simple_icon(
~view="0 0 24 24",
[
"M10.3094 2.25002H13.6908C13.9072 2.24988 14.0957 2.24976 14.2737 2.27819C14.977 2.39049 15.5856 2.82915 15.9146 3.46084C15.9978 3.62073 16.0573 3.79961 16.1256 4.00494L16.2373 4.33984C16.2562 4.39653 16.2616 4.41258 16.2661 4.42522C16.4413 4.90933 16.8953 5.23659 17.4099 5.24964C17.4235 5.24998 17.44 5.25004 17.5001 5.25004H20.5001C20.9143 5.25004 21.2501 5.58582 21.2501 6.00004C21.2501 6.41425 20.9143 6.75004 20.5001 6.75004H3.5C3.08579 6.75004 2.75 6.41425 2.75 6.00004C2.75 5.58582 3.08579 5.25004 3.5 5.25004H6.50008C6.56013 5.25004 6.5767 5.24998 6.59023 5.24964C7.10488 5.23659 7.55891 4.90936 7.73402 4.42524C7.73863 4.41251 7.74392 4.39681 7.76291 4.33984L7.87452 4.00496C7.94281 3.79964 8.00233 3.62073 8.08559 3.46084C8.41453 2.82915 9.02313 2.39049 9.72643 2.27819C9.90445 2.24976 10.093 2.24988 10.3094 2.25002ZM9.00815 5.25004C9.05966 5.14902 9.10531 5.04404 9.14458 4.93548C9.1565 4.90251 9.1682 4.86742 9.18322 4.82234L9.28302 4.52292C9.37419 4.24941 9.39519 4.19363 9.41601 4.15364C9.52566 3.94307 9.72853 3.79686 9.96296 3.75942C10.0075 3.75231 10.067 3.75004 10.3553 3.75004H13.6448C13.9331 3.75004 13.9927 3.75231 14.0372 3.75942C14.2716 3.79686 14.4745 3.94307 14.5842 4.15364C14.605 4.19363 14.626 4.2494 14.7171 4.52292L14.8169 4.82216L14.8556 4.9355C14.8949 5.04405 14.9405 5.14902 14.992 5.25004H9.00815Z",
"M5.91509 8.45015C5.88754 8.03685 5.53016 7.72415 5.11686 7.7517C4.70357 7.77925 4.39086 8.13663 4.41841 8.54993L4.88186 15.5017C4.96736 16.7844 5.03642 17.8205 5.19839 18.6336C5.36679 19.4789 5.65321 20.185 6.2448 20.7385C6.8364 21.2919 7.55995 21.5308 8.4146 21.6425C9.23662 21.7501 10.275 21.7501 11.5606 21.75H12.4395C13.7251 21.7501 14.7635 21.7501 15.5856 21.6425C16.4402 21.5308 17.1638 21.2919 17.7554 20.7385C18.347 20.185 18.6334 19.4789 18.8018 18.6336C18.9638 17.8206 19.0328 16.7844 19.1183 15.5017L19.5818 8.54993C19.6093 8.13663 19.2966 7.77925 18.8833 7.7517C18.47 7.72415 18.1126 8.03685 18.0851 8.45015L17.6251 15.3493C17.5353 16.6971 17.4713 17.6349 17.3307 18.3406C17.1943 19.025 17.004 19.3873 16.7306 19.6431C16.4572 19.8989 16.083 20.0647 15.391 20.1552C14.6776 20.2485 13.7376 20.25 12.3868 20.25H11.6134C10.2626 20.25 9.32255 20.2485 8.60915 20.1552C7.91715 20.0647 7.54299 19.8989 7.26958 19.6431C6.99617 19.3873 6.80583 19.025 6.66948 18.3406C6.52892 17.6349 6.46489 16.6971 6.37503 15.3493L5.91509 8.45015Z",
"M9.42546 10.2538C9.83762 10.2125 10.2052 10.5133 10.2464 10.9254L10.7464 15.9254C10.7876 16.3376 10.4869 16.7051 10.0747 16.7463C9.66256 16.7875 9.29503 16.4868 9.25381 16.0747L8.75381 11.0747C8.7126 10.6625 9.01331 10.295 9.42546 10.2538Z",
"M14.5747 10.2538C14.9869 10.295 15.2876 10.6625 15.2464 11.0747L14.7464 16.0747C14.7052 16.4868 14.3376 16.7875 13.9255 16.7463C13.5133 16.7051 13.2126 16.3376 13.2538 15.9254L13.7538 10.9254C13.795 10.5133 14.1626 10.2125 14.5747 10.2538Z",
"M12 2.75C11.0215 2.75 10.1871 3.37503 9.87787 4.24993C9.73983 4.64047 9.31134 4.84517 8.9208 4.70713C8.53026 4.56909 8.32557 4.1406 8.46361 3.75007C8.97804 2.29459 10.3661 1.25 12 1.25C13.634 1.25 15.022 2.29459 15.5365 3.75007C15.6745 4.1406 15.4698 4.56909 15.0793 4.70713C14.6887 4.84517 14.2602 4.64047 14.1222 4.24993C13.813 3.37503 12.9785 2.75 12 2.75Z",
"M2.75 6C2.75 5.58579 3.08579 5.25 3.5 5.25H20.5001C20.9143 5.25 21.2501 5.58579 21.2501 6C21.2501 6.41421 20.9143 6.75 20.5001 6.75H3.5C3.08579 6.75 2.75 6.41421 2.75 6Z",
"M5.91508 8.45011C5.88753 8.03681 5.53015 7.72411 5.11686 7.75166C4.70356 7.77921 4.39085 8.13659 4.41841 8.54989L4.88186 15.5016C4.96735 16.7844 5.03641 17.8205 5.19838 18.6336C5.36678 19.4789 5.6532 20.185 6.2448 20.7384C6.83639 21.2919 7.55994 21.5307 8.41459 21.6425C9.23663 21.75 10.2751 21.75 11.5607 21.75H12.4395C13.7251 21.75 14.7635 21.75 15.5856 21.6425C16.4402 21.5307 17.1638 21.2919 17.7554 20.7384C18.347 20.185 18.6334 19.4789 18.8018 18.6336C18.9637 17.8205 19.0328 16.7844 19.1183 15.5016L19.5818 8.54989C19.6093 8.13659 19.2966 7.77921 18.8833 7.75166C18.47 7.72411 18.1126 8.03681 18.0851 8.45011L17.6251 15.3492C17.5353 16.6971 17.4712 17.6349 17.3307 18.3405C17.1943 19.025 17.004 19.3873 16.7306 19.6431C16.4572 19.8988 16.083 20.0647 15.391 20.1552C14.6776 20.2485 13.7376 20.25 12.3868 20.25H11.6134C10.2626 20.25 9.32255 20.2485 8.60915 20.1552C7.91715 20.0647 7.54299 19.8988 7.26957 19.6431C6.99616 19.3873 6.80583 19.025 6.66948 18.3405C6.52891 17.6349 6.46488 16.6971 6.37503 15.3492L5.91508 8.45011Z",
"M9.42546 10.2537C9.83762 10.2125 10.2051 10.5132 10.2464 10.9254L10.7464 15.9254C10.7876 16.3375 10.4869 16.7051 10.0747 16.7463C9.66256 16.7875 9.29502 16.4868 9.25381 16.0746L8.75381 11.0746C8.71259 10.6625 9.0133 10.2949 9.42546 10.2537Z",
"M15.2464 11.0746C15.2876 10.6625 14.9869 10.2949 14.5747 10.2537C14.1626 10.2125 13.795 10.5132 13.7538 10.9254L13.2538 15.9254C13.2126 16.3375 13.5133 16.7051 13.9255 16.7463C14.3376 16.7875 14.7051 16.4868 14.7464 16.0746L15.2464 11.0746Z",
],
);

0 comments on commit a1e82bf

Please sign in to comment.