Skip to content

Commit 1a1d1bb

Browse files
committed
fix #113; wordsWithStepValue
1 parent 72851b0 commit 1a1d1bb

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

spec/learnwords2/LWBoxOfQuestionsSpec.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,15 @@ describe("BoxOfQuestions", function() {
8787
// setup a particular set of step value
8888

8989
var allWords = LW.db.allWords();
90-
// FIXME why do I need to indicate 0 as a string value?
91-
allWords[0].step = 0; // has not been answered yet
90+
allWords[0].step = 0; // question for word has not been answered yet
9291
allWords[1].step = 0;
9392
allWords[2].step = 0;
94-
allWords[3].step = 0;
9593

96-
allWords[4].step = 1; // word has been answered once
94+
allWords[3].step = 1; // question for word has been answered once
95+
allWords[4].step = 1;
9796
allWords[5].step = 1;
9897
allWords[6].step = 2; // word has been answered two times
99-
allWords[7].step = 2;
98+
allWords[7].step = 3; // word has been answered three times
10099

101100
LW.db.putWord(allWords[0]);
102101
LW.db.putWord(allWords[1]);
@@ -132,6 +131,8 @@ describe("BoxOfQuestions", function() {
132131
expect(LW).toHaveMethod("importFrom");
133132
expect(LW).toHaveMethod("wordsToRepeat");
134133

134+
135+
expect(LW).toHaveMethod("wordsWithStepValue");
135136
expect(LW).toHaveMethod("chooseRandomObject");
136137
expect(LW).toHaveMethod("config");
137138
expect(LW).toHaveMethod("status");
@@ -237,6 +238,29 @@ describe("BoxOfQuestions", function() {
237238

238239

239240

241+
it("should give an array of words having particular step values", function() {
242+
243+
expect(LW).not.toBe(null);
244+
expect(LW).toHaveMethod("wordsWithStepValue");
245+
246+
var wordWithStepEqualMinus1 = LW.wordsWithStepValue(-1);
247+
expect(wordWithStepEqualMinus1.length).toBe(4);
248+
249+
var wordsWithStep0 = LW.wordsWithStepValue(0);
250+
expect(wordsWithStep0.length).toBe(3);
251+
252+
var wordsWithStepMinus1ToZero = LW.wordsWithStepValue(-1,0);
253+
expect(wordsWithStepMinus1ToZero.length).toBe(7);
254+
255+
var wordsWithStepMinus1ToPlus1 = LW.wordsWithStepValue(-1,1);
256+
expect(wordsWithStepMinus1ToPlus1.length).toBe(10);
257+
258+
259+
});
260+
261+
262+
263+
240264
it("should be able to give a question", function() {
241265

242266
expect(LW).not.toBe(null);
@@ -457,7 +481,6 @@ describe("BoxOfQuestions", function() {
457481
sum = sum + _id;
458482
}
459483

460-
console.log();
461484

462485
expect(sum/2000 >=6.3).toBe(true);
463486
expect(sum/2000 <=6.7).toBe(true);

src/BoxOfQuestions.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,34 @@ function BoxOfQuestions(db) {
301301
};
302302

303303
return _wordsToRepeat;
304+
},
305+
306+
307+
308+
309+
310+
311+
312+
313+
wordsWithStepValue : function(from, to){
314+
var toValue;
315+
316+
if ( typeof(to) == "undefined" || to == null ) {toValue = from}
317+
else {toValue = to}
318+
319+
function stepValueInRange(aWord) {
320+
return (aWord.step >= from) && (aWord.step <= toValue);
321+
}
322+
323+
324+
return (this.db.allWords()).filter(stepValueInRange);
304325
}
305326

306327

307328

329+
330+
331+
308332
}
309333

310334
}

0 commit comments

Comments
 (0)