Skip to content

Commit

Permalink
Add CLI flags to output well-formatted optional question attributes. (#…
Browse files Browse the repository at this point in the history
…123)

* Add CLI flags to output well-formatted optional question attributes.

This change is backward compatible with the current learn interface.

This commit adds three new flags to the `learn md` command:

- `--with-explanation/-e` (bool)  which creates explanation attributes
  for correct and incorrect responses
- `--with-rubric/-r` (bool) which creates rubric attributes
- `--with-hints/-n` (int) which creates the indicated number of hint
  attributes

Without the minimal flag, the comments are preserved in the question
as it previously worked. If a user specifies one of the above flags,
then the corresponding comment is removed from the final output.

* Simplify difference between minimal and maximal output

---------

Co-authored-by: Curtis Schlak <[email protected]>
  • Loading branch information
realistschuckle and Curtis Schlak authored Mar 1, 2024
1 parent b1f669d commit ef65ac2
Show file tree
Hide file tree
Showing 3 changed files with 373 additions and 94 deletions.
195 changes: 195 additions & 0 deletions app/cmd/challenge_attributes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
package cmd

import (
"strings"
"testing"
)

var questionTypes = []string{
"mc",
"cb",
"tl",
"sa",
"nb",
"pg",
"or",
"js",
"ja",
"py",
"sq",
"rb",
"up",
"cs",
"pr",
"tpr",
}

func Test_AttributesCommentsOccurInMaximalWithNoAttributes(t *testing.T) {
PrintTemplate = false
Minimal = false
WithExplanation = false
WithRubric = false
WithHints = 0

for _, command := range questionTypes {
t.Run(command, func(t2 *testing.T) {
template, _ := getTemp(command)
rendered := template.renderTemplate()

if !strings.Contains(rendered, blockHeader) {
t2.Errorf("%s did not have block header", command)
}
if !strings.Contains(rendered, hintTemplateSilent) {
t2.Errorf("%s did not have hint comment", command)
}
if !strings.Contains(rendered, rubricTemplateSilent) {
t2.Errorf("%s did not have rubric comment", command)
}
if !strings.Contains(rendered, explanationTemplateSilent) {
t2.Errorf("%s did not have explanation comment", command)
}
})
}
}

func Test_ExplanationBlockAppearsWhenTrueInMaximal(t *testing.T) {
PrintTemplate = false
Minimal = false
WithExplanation = true
WithRubric = false
WithHints = 0

for _, command := range questionTypes {
t.Run(command, func(t2 *testing.T) {
template, _ := getTemp(command)
rendered := template.renderTemplate()

if !strings.Contains(rendered, explanationTemplate) {
t2.Errorf("%s did not have explanation block", command)
}
})
}
}

func Test_RubricBlockAppearsWhenTrueInMaximal(t *testing.T) {
PrintTemplate = false
Minimal = false
WithExplanation = false
WithRubric = true
WithHints = 0

for _, command := range questionTypes {
t.Run(command, func(t2 *testing.T) {
template, _ := getTemp(command)
rendered := template.renderTemplate()

if !strings.Contains(rendered, rubricTemplate) {
t2.Errorf("%s did not have rubric block", command)
}
})
}
}

func Test_HintBlockAppearsWhenTrueInMaximal(t *testing.T) {
PrintTemplate = false
Minimal = false
WithExplanation = false
WithRubric = true
WithHints = 1

for _, command := range questionTypes {
t.Run(command, func(t2 *testing.T) {
template, _ := getTemp(command)
rendered := template.renderTemplate()

if !strings.Contains(rendered, hintTemplate) {
t2.Errorf("%s did not have hint block", command)
}
})
}
}

func Test_AttributesCommentsAbsentInMinimalWithNoAttributes(t *testing.T) {
PrintTemplate = false
Minimal = true
WithExplanation = false
WithRubric = false
WithHints = 0

for _, command := range questionTypes {
t.Run(command, func(t2 *testing.T) {
template, _ := getTemp(command)
rendered := template.renderTemplate()

if strings.Contains(rendered, blockHeader) {
t2.Errorf("%s did have block header", command)
}
if strings.Contains(rendered, hintTemplateSilent) {
t2.Errorf("%s did have hint comment", command)
}
if strings.Contains(rendered, rubricTemplateSilent) {
t2.Errorf("%s did have rubric comment", command)
}
if strings.Contains(rendered, explanationTemplateSilent) {
t2.Errorf("%s did have explanation comment", command)
}
})
}
}

func Test_ExplanationBlockAppearsWhenTrueInMinimal(t *testing.T) {
PrintTemplate = false
Minimal = true
WithExplanation = true
WithRubric = false
WithHints = 0

for _, command := range questionTypes {
t.Run(command, func(t2 *testing.T) {
template, _ := getTemp(command)
rendered := template.renderTemplate()

if !strings.Contains(rendered, explanationTemplateMin) {
t2.Errorf("%s did not have explanation block", command)
}
})
}
}

func Test_RubricBlockAppearsWhenTrueInMinimal(t *testing.T) {
PrintTemplate = false
Minimal = true
WithExplanation = false
WithRubric = true
WithHints = 0

for _, command := range questionTypes {
t.Run(command, func(t2 *testing.T) {
template, _ := getTemp(command)
rendered := template.renderTemplate()

if !strings.Contains(rendered, rubricTemplateMin) {
t2.Errorf("%s did not have rubric block", command)
}
})
}
}

func Test_HintBlockAppearsWhenTrueInMinimal(t *testing.T) {
PrintTemplate = false
Minimal = true
WithExplanation = false
WithRubric = true
WithHints = 1

for _, command := range questionTypes {
t.Run(command, func(t2 *testing.T) {
template, _ := getTemp(command)
rendered := template.renderTemplate()

if !strings.Contains(rendered, hintTemplateMin) {
t2.Errorf("%s did not have hint block", command)
}
})
}
}
Loading

0 comments on commit ef65ac2

Please sign in to comment.