import { GraderSpecificationFor } from "../graders/QuestionGrader"; import { ResponseHandler, SubmissionType } from "./responses"; /** * One of the "lines" of code that may be toggled on/off in a select lines response. * If `forced` is specified as true, the item will appear as selected and can not * be toggled off (it will always be included in the solution). */ export type SLItem = { kind: "item"; text: string; forced?: boolean; }; export type SLGroup = { kind: "group"; title?: string; items: SLItem[]; }; /** * ## Select Lines Response Element Specification * * A select lines response gives students a sequence of lines of code and asks them to choose the ones * that are correct and should become part of a final solution. The relative ordering of the lines * is fixed, but each may be turned on/off. Lines may be "forced", meaning they cannot be turned off * and are always included in the final solution. A "line" may in fact contain several lines if its * specified content contains newline characters. * * The response is rendered as a sequence of lines with checkboxes. Clicking a line toggles whether * it is selected or not. Students may also preview their final solution, composed of only the * selected lines. * * Here's an example of a question with a select lines response. * * ![image](media://response-sample-select-lines.png) * * ![image](media://response-sample-select-lines-selected-only.png) * * ```typescript * export const Question_Sample_Select_Lines : QuestionSpecification = { * question_id: "sample_select_lines", * tags: [], * points: 9, * mk_description: * ` * Compose a poem by selecting from the lines below. * Click all lines that should be included. You are not able to change the * relative ordering of the lines. You may use the buttons to toggle between * viewing all choices or just the ones you have selected to preview your * chosen code. When finished, the **selected lines should form a working * function** that performs a **deep copy** where appropriate and **avoids * undefined behavior or memory leaks**. Some lines contain **mistakes** * or are **unnecessary** for the function - these lines should not be selected. * `, * response: { * kind: "select_lines", * code_language: "cpp", * header: "A profound poem:", * choices: [ * { * kind: "item", * text: "Roses are red", * forced: false * }, * { * kind: "item", * text: "Roses are pink", * forced: true * }, * { * kind: "item", * text: "Violets are blue", * forced: false * }, * { * kind: "item", * text: "Violets are purple", * forced: false * }, * { * kind: "item", * text: "This question is easy", * forced: false * }, * { * kind: "item", * text: "This question is tough", * forced: false * }, * { * kind: "item", * text: "But you already knew", * forced: false * }, * { * kind: "item", * text: "Nothing rhymes with purple", * forced: false * }, * ], * footer: "The end", * sample_solution: [1, 2, 4, 6] * } * } * ``` * * ### Select Lines Submissions * * A submission for a select lines response is an array of numbers corresponding to the indices * of selected lines. See [[`SLSubmission`]] for details. * */ export type SLSpecification = { /** * The discriminant "select_lines" is used to distinguish select lines specifications. */ kind: "select_lines"; /** * The language to use for syntax highlighting. Specify the alias for any * [highlightjs supported language](https://highlightjs.readthedocs.io/en/latest/supported-languages.html). */ code_language: string; /** * The "lines" of code to present as choices for the student. */ choices: (SLGroup | SLItem)[]; /** * Code shown above the set of lines students select from. */ header?: string; /** * Code shown below the set of lines students select from */ footer?: string; /** * A sample solution for this response. */ sample_solution?: SubmissionType<"select_lines">; /** * A default grader for this response. */ default_grader?: GraderSpecificationFor<"select_lines">; }; /** * A submission for a select lines response is an array of numbers corresponding to the indices * of selected lines. Note that any "forced" items will always be included in a submission. * * The subset of [[`FITBSubmissions`]] that are valid (see [[`validate_submission`]]) for a * particular FITB response are those that do not contain duplicate or out-of-range indices. */ export type SLSubmission = readonly number[]; export declare const SL_HANDLER: ResponseHandler<"select_lines">;