-
Notifications
You must be signed in to change notification settings - Fork 350
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
Move scoring out of general Util into scoring util file #1962
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9d1a6c4
Move scoring out of general Util into scoring util file
jeremywiebe f366700
Changeset
jeremywiebe 63120a9
Revert tiny change
jeremywiebe 11f9483
Remove unused import
jeremywiebe a3a5230
Export helper keScoreFromPerseusScore as its used externally
jeremywiebe f44e07e
Changeset
jeremywiebe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus": minor | ||
--- | ||
|
||
Move scoring utility functions out of `Util` object into their own file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,4 @@ | ||
import Util, {isCorrect} from "../util"; | ||
|
||
describe("isCorrect", () => { | ||
it("is true given a score with all points earned", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All deleted tests here just moved to |
||
const score = {type: "points", earned: 3, total: 3} as const; | ||
expect(isCorrect(score)).toBe(true); | ||
}); | ||
|
||
it("is false given a score with some points unearned", () => { | ||
const score = {type: "points", earned: 2, total: 3} as const; | ||
expect(isCorrect(score)).toBe(false); | ||
}); | ||
|
||
it("is false given an unanswered / invalid score", () => { | ||
const score = {type: "invalid"} as const; | ||
expect(isCorrect(score)).toBe(false); | ||
}); | ||
}); | ||
import Util from "../util"; | ||
|
||
describe("#constrainedTickStepsFromTickSteps", () => { | ||
it("should not changes the tick steps if there are fewer than (or exactly) 10 steps", () => { | ||
|
@@ -79,118 +62,3 @@ describe("deepClone", () => { | |
expect(result[0]).not.toBe(input[0]); | ||
}); | ||
}); | ||
|
||
describe("flattenScores", () => { | ||
it("defaults to an empty score", () => { | ||
const result = Util.flattenScores({}); | ||
|
||
expect(result).toHaveBeenAnsweredCorrectly({shouldHavePoints: false}); | ||
expect(result).toEqual({ | ||
type: "points", | ||
total: 0, | ||
earned: 0, | ||
message: null, | ||
}); | ||
}); | ||
|
||
it("defaults to single score if there is only one", () => { | ||
const result = Util.flattenScores({ | ||
"radio 1": { | ||
type: "points", | ||
total: 1, | ||
earned: 1, | ||
message: null, | ||
}, | ||
}); | ||
|
||
expect(result).toHaveBeenAnsweredCorrectly(); | ||
expect(result).toEqual({ | ||
type: "points", | ||
total: 1, | ||
earned: 1, | ||
message: null, | ||
}); | ||
}); | ||
|
||
it("returns an invalid score if any are invalid", () => { | ||
const result = Util.flattenScores({ | ||
"radio 1": { | ||
type: "points", | ||
total: 1, | ||
earned: 1, | ||
message: null, | ||
}, | ||
"radio 2": { | ||
type: "invalid", | ||
message: null, | ||
}, | ||
}); | ||
|
||
expect(result).toHaveInvalidInput(); | ||
expect(result).toEqual({ | ||
type: "invalid", | ||
message: null, | ||
}); | ||
}); | ||
|
||
it("tallies scores if multiple widgets have points", () => { | ||
const result = Util.flattenScores({ | ||
"radio 1": { | ||
type: "points", | ||
total: 1, | ||
earned: 1, | ||
message: null, | ||
}, | ||
"radio 2": { | ||
type: "points", | ||
total: 1, | ||
earned: 1, | ||
message: null, | ||
}, | ||
"radio 3": { | ||
type: "points", | ||
total: 1, | ||
earned: 1, | ||
message: null, | ||
}, | ||
}); | ||
|
||
expect(result).toHaveBeenAnsweredCorrectly(); | ||
expect(result).toEqual({ | ||
type: "points", | ||
total: 3, | ||
earned: 3, | ||
message: null, | ||
}); | ||
}); | ||
|
||
it("doesn't count incorrect widgets", () => { | ||
const result = Util.flattenScores({ | ||
"radio 1": { | ||
type: "points", | ||
total: 1, | ||
earned: 1, | ||
message: null, | ||
}, | ||
"radio 2": { | ||
type: "points", | ||
total: 1, | ||
earned: 1, | ||
message: null, | ||
}, | ||
"radio 3": { | ||
type: "points", | ||
total: 1, | ||
earned: 0, | ||
message: null, | ||
}, | ||
}); | ||
|
||
expect(result).toEqual({ | ||
type: "points", | ||
total: 3, | ||
earned: 2, | ||
message: null, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,7 @@ import {DependenciesContext} from "../dependencies"; | |
import HintsRenderer from "../hints-renderer"; | ||
import {Log} from "../logging/log"; | ||
import Renderer from "../renderer"; | ||
import Util from "../util"; | ||
import {combineScores, keScoreFromPerseusScore} from "../util/scoring"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also switched to ES6 exports in the new file. |
||
|
||
import {itemToTree} from "./items"; | ||
import {buildMapper} from "./trees"; | ||
|
@@ -404,7 +404,7 @@ class MultiRenderer extends React.Component<Props, State> { | |
if (ref.getSerializedState) { | ||
state = ref.getSerializedState(); | ||
} | ||
return Util.keScoreFromPerseusScore(score, guess, state); | ||
return keScoreFromPerseusScore(score, guess, state); | ||
} | ||
|
||
/** | ||
|
@@ -441,9 +441,9 @@ class MultiRenderer extends React.Component<Props, State> { | |
return data.ref?.getUserInput(); | ||
}); | ||
|
||
const combinedScore = scores.reduce(Util.combineScores); | ||
const combinedScore = scores.reduce(combineScores); | ||
|
||
return Util.keScoreFromPerseusScore(combinedScore, guess, state); | ||
return keScoreFromPerseusScore(combinedScore, guess, state); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd argue this is a major change.
Util
is exported fromindex.ts
:You'll see that this breaks Webapp because I used
Util.keScoreFromPerseusScore
in my recent change. So:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I didn't catch the one usage of
keScoreFromPerseusScore
outside of Perseus. Fixing.