CoffeeScript tests migration: Decaffeinate files
This is running decaffeinate, with no additional cleanup.
This commit is contained in:
committed by
Calen Pennington
parent
5c64da2f63
commit
0880502f26
@@ -1,21 +1,55 @@
|
||||
class MinimaxProblemDisplay extends XProblemDisplay
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS001: Remove Babel/TypeScript constructor workaround
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS205: Consider reworking code to avoid use of IIFEs
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* DS208: Avoid top-level this
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
class MinimaxProblemDisplay extends XProblemDisplay {
|
||||
|
||||
constructor: (@state, @submission, @evaluation, @container, @submissionField, @parameters={}) ->
|
||||
constructor(state, submission, evaluation, container, submissionField, parameters) {
|
||||
|
||||
super(@state, @submission, @evaluation, @container, @submissionField, @parameters)
|
||||
{
|
||||
// Hack: trick Babel/TypeScript into allowing this before super.
|
||||
if (false) { super(); }
|
||||
let thisFn = (() => { this; }).toString();
|
||||
let thisName = thisFn.slice(thisFn.indexOf('{') + 1, thisFn.indexOf(';')).trim();
|
||||
eval(`${thisName} = this;`);
|
||||
}
|
||||
this.state = state;
|
||||
this.submission = submission;
|
||||
this.evaluation = evaluation;
|
||||
this.container = container;
|
||||
this.submissionField = submissionField;
|
||||
if (parameters == null) { parameters = {}; }
|
||||
this.parameters = parameters;
|
||||
super(this.state, this.submission, this.evaluation, this.container, this.submissionField, this.parameters);
|
||||
}
|
||||
|
||||
render: () ->
|
||||
render() {}
|
||||
|
||||
createSubmission: () ->
|
||||
createSubmission() {
|
||||
|
||||
@newSubmission = {}
|
||||
this.newSubmission = {};
|
||||
|
||||
if @submission?
|
||||
for id, value of @submission
|
||||
@newSubmission[id] = value
|
||||
if (this.submission != null) {
|
||||
return (() => {
|
||||
const result = [];
|
||||
for (let id in this.submission) {
|
||||
const value = this.submission[id];
|
||||
result.push(this.newSubmission[id] = value);
|
||||
}
|
||||
return result;
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
getCurrentSubmission: () ->
|
||||
return @newSubmission
|
||||
getCurrentSubmission() {
|
||||
return this.newSubmission;
|
||||
}
|
||||
}
|
||||
|
||||
root = exports ? this
|
||||
root.TestProblemDisplay = TestProblemDisplay
|
||||
const root = typeof exports !== 'undefined' && exports !== null ? exports : this;
|
||||
root.TestProblemDisplay = TestProblemDisplay;
|
||||
|
||||
@@ -1,14 +1,33 @@
|
||||
class TestProblemGenerator extends XProblemGenerator
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS001: Remove Babel/TypeScript constructor workaround
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* DS208: Avoid top-level this
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
class TestProblemGenerator extends XProblemGenerator {
|
||||
|
||||
constructor: (seed, @parameters = {}) ->
|
||||
constructor(seed, parameters) {
|
||||
|
||||
super(seed, @parameters)
|
||||
{
|
||||
// Hack: trick Babel/TypeScript into allowing this before super.
|
||||
if (false) { super(); }
|
||||
let thisFn = (() => { this; }).toString();
|
||||
let thisName = thisFn.slice(thisFn.indexOf('{') + 1, thisFn.indexOf(';')).trim();
|
||||
eval(`${thisName} = this;`);
|
||||
}
|
||||
if (parameters == null) { parameters = {}; }
|
||||
this.parameters = parameters;
|
||||
super(seed, this.parameters);
|
||||
}
|
||||
|
||||
generate: () ->
|
||||
generate() {
|
||||
|
||||
@problemState.value = @parameters.value
|
||||
this.problemState.value = this.parameters.value;
|
||||
|
||||
return @problemState
|
||||
return this.problemState;
|
||||
}
|
||||
}
|
||||
|
||||
root = exports ? this
|
||||
root.generatorClass = TestProblemGenerator
|
||||
const root = typeof exports !== 'undefined' && exports !== null ? exports : this;
|
||||
root.generatorClass = TestProblemGenerator;
|
||||
|
||||
@@ -1,27 +1,54 @@
|
||||
class TestProblemGrader extends XProblemGrader
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS001: Remove Babel/TypeScript constructor workaround
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* DS208: Avoid top-level this
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
class TestProblemGrader extends XProblemGrader {
|
||||
|
||||
constructor: (@submission, @problemState, @parameters={}) ->
|
||||
constructor(submission, problemState, parameters) {
|
||||
|
||||
super(@submission, @problemState, @parameters)
|
||||
{
|
||||
// Hack: trick Babel/TypeScript into allowing this before super.
|
||||
if (false) { super(); }
|
||||
let thisFn = (() => { this; }).toString();
|
||||
let thisName = thisFn.slice(thisFn.indexOf('{') + 1, thisFn.indexOf(';')).trim();
|
||||
eval(`${thisName} = this;`);
|
||||
}
|
||||
this.submission = submission;
|
||||
this.problemState = problemState;
|
||||
if (parameters == null) { parameters = {}; }
|
||||
this.parameters = parameters;
|
||||
super(this.submission, this.problemState, this.parameters);
|
||||
}
|
||||
|
||||
solve: () ->
|
||||
solve() {
|
||||
|
||||
@solution = {0: @problemState.value}
|
||||
return this.solution = {0: this.problemState.value};
|
||||
}
|
||||
|
||||
grade: () ->
|
||||
grade() {
|
||||
|
||||
if not @solution?
|
||||
@solve()
|
||||
if ((this.solution == null)) {
|
||||
this.solve();
|
||||
}
|
||||
|
||||
allCorrect = true
|
||||
let allCorrect = true;
|
||||
|
||||
for id, value of @solution
|
||||
valueCorrect = if @submission? then (value == @submission[id]) else false
|
||||
@evaluation[id] = valueCorrect
|
||||
if not valueCorrect
|
||||
allCorrect = false
|
||||
for (let id in this.solution) {
|
||||
const value = this.solution[id];
|
||||
const valueCorrect = (this.submission != null) ? (value === this.submission[id]) : false;
|
||||
this.evaluation[id] = valueCorrect;
|
||||
if (!valueCorrect) {
|
||||
allCorrect = false;
|
||||
}
|
||||
}
|
||||
|
||||
return allCorrect
|
||||
return allCorrect;
|
||||
}
|
||||
}
|
||||
|
||||
root = exports ? this
|
||||
root.graderClass = TestProblemGrader
|
||||
const root = typeof exports !== 'undefined' && exports !== null ? exports : this;
|
||||
root.graderClass = TestProblemGrader;
|
||||
|
||||
@@ -1,47 +1,79 @@
|
||||
class XProblemGenerator
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* DS208: Avoid top-level this
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
class XProblemGenerator {
|
||||
|
||||
constructor: (seed, @parameters={}) ->
|
||||
constructor(seed, parameters) {
|
||||
|
||||
@random = new MersenneTwister(seed)
|
||||
if (parameters == null) { parameters = {}; }
|
||||
this.parameters = parameters;
|
||||
this.random = new MersenneTwister(seed);
|
||||
|
||||
@problemState = {}
|
||||
this.problemState = {};
|
||||
}
|
||||
|
||||
generate: () ->
|
||||
generate() {
|
||||
|
||||
console.error("Abstract method called: XProblemGenerator.generate")
|
||||
return console.error("Abstract method called: XProblemGenerator.generate");
|
||||
}
|
||||
}
|
||||
|
||||
class XProblemDisplay
|
||||
class XProblemDisplay {
|
||||
|
||||
constructor: (@state, @submission, @evaluation, @container, @submissionField, @parameters={}) ->
|
||||
constructor(state, submission, evaluation, container, submissionField, parameters) {
|
||||
this.state = state;
|
||||
this.submission = submission;
|
||||
this.evaluation = evaluation;
|
||||
this.container = container;
|
||||
this.submissionField = submissionField;
|
||||
if (parameters == null) { parameters = {}; }
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
render: () ->
|
||||
render() {
|
||||
|
||||
console.error("Abstract method called: XProblemDisplay.render")
|
||||
return console.error("Abstract method called: XProblemDisplay.render");
|
||||
}
|
||||
|
||||
updateSubmission: () ->
|
||||
updateSubmission() {
|
||||
|
||||
@submissionField.val(JSON.stringify(@getCurrentSubmission()))
|
||||
return this.submissionField.val(JSON.stringify(this.getCurrentSubmission()));
|
||||
}
|
||||
|
||||
getCurrentSubmission: () ->
|
||||
console.error("Abstract method called: XProblemDisplay.getCurrentSubmission")
|
||||
getCurrentSubmission() {
|
||||
return console.error("Abstract method called: XProblemDisplay.getCurrentSubmission");
|
||||
}
|
||||
}
|
||||
|
||||
class XProblemGrader
|
||||
class XProblemGrader {
|
||||
|
||||
constructor: (@submission, @problemState, @parameters={}) ->
|
||||
constructor(submission, problemState, parameters) {
|
||||
|
||||
@solution = null
|
||||
@evaluation = {}
|
||||
this.submission = submission;
|
||||
this.problemState = problemState;
|
||||
if (parameters == null) { parameters = {}; }
|
||||
this.parameters = parameters;
|
||||
this.solution = null;
|
||||
this.evaluation = {};
|
||||
}
|
||||
|
||||
solve: () ->
|
||||
solve() {
|
||||
|
||||
console.error("Abstract method called: XProblemGrader.solve")
|
||||
return console.error("Abstract method called: XProblemGrader.solve");
|
||||
}
|
||||
|
||||
grade: () ->
|
||||
grade() {
|
||||
|
||||
console.error("Abstract method called: XProblemGrader.grade")
|
||||
return console.error("Abstract method called: XProblemGrader.grade");
|
||||
}
|
||||
}
|
||||
|
||||
root = exports ? this
|
||||
const root = typeof exports !== 'undefined' && exports !== null ? exports : this;
|
||||
|
||||
root.XProblemGenerator = XProblemGenerator
|
||||
root.XProblemDisplay = XProblemDisplay
|
||||
root.XProblemGrader = XProblemGrader
|
||||
root.XProblemGenerator = XProblemGenerator;
|
||||
root.XProblemDisplay = XProblemDisplay;
|
||||
root.XProblemGrader = XProblemGrader;
|
||||
|
||||
Reference in New Issue
Block a user