UNPKG

@sunzhongmou/math

Version:
93 lines 4.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MathematicsBuilder = void 0; const mathematics_1 = require("./mathematics"); const AddResultLessOrEqualTo10Rule_1 = require("./rule/AddResultLessOrEqualTo10Rule"); const and_1 = require("@sunzhongmou/design-pattern/lib/and"); const AddResultGreaterOrEqualTo10Rule_1 = require("./rule/AddResultGreaterOrEqualTo10Rule"); const AddResultLessOrEqualTo20Rule_1 = require("./rule/AddResultLessOrEqualTo20Rule"); const SubResultGreaterOrEqualTo0Rule_1 = require("./rule/SubResultGreaterOrEqualTo0Rule"); const DestOperandGreaterOrEqualTo10Rule_1 = require("./rule/DestOperandGreaterOrEqualTo10Rule"); const permutation_1 = require("./permutation"); const DestOperandLessOrEqualTo10Rule_1 = require("./rule/DestOperandLessOrEqualTo10Rule"); const OperandLessOrEqualTo10Rule_1 = require("./rule/OperandLessOrEqualTo10Rule"); class MathematicsBuilder { constructor() { this.maximum = 10; this.addCapacity = 0; this.subCapacity = 0; this.fillCapacity = 0; this.operandsInTen = false; this.loopAdd = false; } withMaximum(maximum) { this.maximum = maximum; return this; } withOperandsInTen() { this.operandsInTen = true; return this; } withLoopAdd() { this.loopAdd = true; return this; } withAdd(capacity) { this.addCapacity = capacity; return this; } withSub(capacity) { this.subCapacity = capacity; return this; } withFill(capacity) { this.fillCapacity = capacity; return this; } build() { if (this.maximum === 10) { return this.buildTen(); } else { return this.buildTwenty(); } } buildTen() { const mathematics = new mathematics_1.Mathematics(permutation_1.getSequence(10)); const rules = new and_1.And([]).addRule(new AddResultLessOrEqualTo10Rule_1.AddResultLessOrEqualTo10Rule()); mathematics.generateAddQuestions(this.addCapacity, rules); const subRules = new and_1.And([]).addRule(new SubResultGreaterOrEqualTo0Rule_1.SubResultGreaterOrEqualTo0Rule()); mathematics.generateSubQuestions(this.subCapacity, subRules); mathematics.generateQuestions(this.addCapacity + this.subCapacity - this.fillCapacity, this.fillCapacity); return mathematics; } buildTwenty() { const mathematics = new mathematics_1.Mathematics(permutation_1.getSequence(20)); const rules = new and_1.And([]) .addRule(new AddResultGreaterOrEqualTo10Rule_1.AddResultGreaterOrEqualTo10Rule()) .addRule(new AddResultLessOrEqualTo20Rule_1.AddResultLessOrEqualTo20Rule()); if (this.operandsInTen) { rules .addRule(new DestOperandLessOrEqualTo10Rule_1.DestOperandLessOrEqualTo10Rule()) .addRule(new OperandLessOrEqualTo10Rule_1.OperandLessOrEqualTo10Rule()); } if (this.loopAdd) { const secRules = new and_1.And([]) .addRule(new AddResultGreaterOrEqualTo10Rule_1.AddResultGreaterOrEqualTo10Rule()) .addRule(new AddResultLessOrEqualTo20Rule_1.AddResultLessOrEqualTo20Rule()) .addRule(new OperandLessOrEqualTo10Rule_1.OperandLessOrEqualTo10Rule()); mathematics.generateLoopAddQuestions(this.addCapacity, rules, secRules); } else { mathematics.generateAddQuestions(this.addCapacity, rules); } const subRules = new and_1.And([]) .addRule(new SubResultGreaterOrEqualTo0Rule_1.SubResultGreaterOrEqualTo0Rule()) .addRule(new DestOperandGreaterOrEqualTo10Rule_1.DestOperandGreaterOrEqualTo10Rule()); mathematics.generateSubQuestions(this.subCapacity, subRules); mathematics.generateQuestions(this.addCapacity + this.subCapacity - this.fillCapacity, this.fillCapacity); return mathematics; } } exports.MathematicsBuilder = MathematicsBuilder; //# sourceMappingURL=mathematics.builder.js.map