Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Remove isOptional checks preventing optional questions from treated as always being correct (Fixes #54) #55

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ The attributes listed below are properly formatted as JSON in [*example.json*](h

>**\_containerId** (string): To add a block to a alternative branching set, add the branching id here. Leave this blank to use the current parent.

>**\_correct** (string): When the mandatory questions contained are all correct and complete, this is the id of the next content block.
>**\_correct** (string): When the questions contained are all correct and complete, this is the id of the next content block.

>**\_partlyCorrect** (string): When the mandatory questions contained are partly correct and complete, this is the id of the next content block.
>**\_partlyCorrect** (string): When the questions contained are partly correct and complete, this is the id of the next content block.

>**\_incorrect** (string): When the mandatory questions contained are all incorrect and complete, this is the id of the next content block.
>**\_incorrect** (string): When the questions contained are all incorrect and complete, this is the id of the next content block.

>**\_hasAttemptBands** (boolean): If set to `true`, turns on the **\_attemptBands** behaviour, allowing branching to happen across both attempts and correctness.

Expand All @@ -49,11 +49,11 @@ The attributes listed below are properly formatted as JSON in [*example.json*](h

>>**\_attempts** (number): This numeric value represents the start of the range. The range continues to the next highest **\_attempts** of another band.

>>**\_correct** (string): When the mandatory questions contained are all correct and complete, this is the id of the next content block.
>>**\_correct** (string): When the questions contained are all correct and complete, this is the id of the next content block.

>>**\_partlyCorrect** (string): When the mandatory questions contained are partly correct and complete, this is the id of the next content block.
>>**\_partlyCorrect** (string): When the questions contained are partly correct and complete, this is the id of the next content block.

>>**\_incorrect** (string): When the mandatory questions contained are all incorrect and complete, this is the id of the next content block.
>>**\_incorrect** (string): When the questions contained are all incorrect and complete, this is the id of the next content block.

## Notes

Expand Down
6 changes: 3 additions & 3 deletions js/BranchingSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default class BranchingSet {
}

const lastChildModel = branchedModels[branchedModels.length - 1];
const isLastIncomplete = !lastChildModel.get('_isComplete') && !lastChildModel.get('_isOptional');
const isLastIncomplete = !lastChildModel.get('_isComplete');
if (isLastIncomplete && !isTheoretical) {
return false;
}
Expand Down Expand Up @@ -224,7 +224,7 @@ export default class BranchingSet {
if (isAnyPartRestored) {
// Make sure to explicitly set the block to complete if complete
// This helps trickle setup locking correctly
const areAllDescendantsComplete = cloned.getAllDescendantModels(true).every(model => model.get('_isComplete') || model.get('_isOptional'));
const areAllDescendantsComplete = cloned.getAllDescendantModels(true).every(model => model.get('_isComplete'));
if (areAllDescendantsComplete) {
cloned.setCompletionStatus();
}
Expand Down Expand Up @@ -282,7 +282,7 @@ export default class BranchingSet {
// Excludes non-trackable extension components, like trickle buttons
const areAllAvailableTrackableChildrenComplete = childModel.getChildren()
.filter(model => model.get('_isAvailable') && model.get('_isTrackable') !== false)
.every(model => model.get('_isComplete') || model.get('_isOptional'));
.every(model => model.get('_isComplete'));
return areAllAvailableTrackableChildrenComplete;
});
return isEffectivelyComplete && this.isAtEnd;
Expand Down
6 changes: 3 additions & 3 deletions js/branchingAlgorithm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import data from 'core/js/data';

export function getCorrectness(model) {
const questionModels = model.getAllDescendantModels().concat([model]).filter(model => model instanceof QuestionModel);
const numberOfCorrect = (questionModels.filter(child => (child.isCorrect()) && !child.get('_isOptional'))).length;
const numberOfPartlyCorrect = (questionModels.filter(child => (child.isPartlyCorrect()) && !child.get('_isOptional'))).length;
const isCorrect = questionModels.every(child => child.isCorrect() || child.get('_isOptional'));
const numberOfCorrect = (questionModels.filter(child => (child.isCorrect()))).length;
const numberOfPartlyCorrect = (questionModels.filter(child => (child.isPartlyCorrect()))).length;
const isCorrect = questionModels.every(child => child.isCorrect());
const isPartlyCorrect = (numberOfCorrect > 0) || (numberOfPartlyCorrect > 0);
const correctnessState = isCorrect ?
'correct' :
Expand Down