I'm practicing TDD doing Codewars, and unfortunately they prefer to not use constructor function structures. Anyways, some of my jasmine tests seem to effect each other, and its also replicating in their test suite. Am I writing these wrong?
The test;
describe("#deductLowestToAll", function() {
it("deducts the lowest element of the array to all elements, and removes it", function() {
deductLowestToAll([8, 5, 3, 9]);
expect(currentTillers).toEqual([5, 2, 6]);
});
it("removed element added to runningTime variable", function() {
runningTime = 0;
//Need this reset or runningTime gets carried over!
deductLowestToAll([10, 5, 7, 2, 3]);
expect(runningTime).toEqual(2);
});
it("adds array to currentTillers", function() {
deductLowestToAll([3, 5, 2, 1, 3]);
expect(currentTillers).toEqual([2, 4, 1, 2]);
});
The code;
var runningTime = 0
var deductLowestToAll = function(array) {
var newArray = [];
var lowest = lowestNumberInArray(array);
runningTime += lowest;
array.forEach(element => {
newArray.push(element - lowest);
if (element === lowest) {
newArray.pop(element);
}
});
currentTillers = newArray;
};
var lowestNumberInArray = function(array) {
return Math.min.apply(null, array);
};
The error;
supermarket queue kata #deductLowestToAll removed element added to runningTime variable
Expected 5 to equal 2.
It isn't resetting runningTime with the next test, seems to get 3 and then add 2 to it for 5.
Aucun commentaire:
Enregistrer un commentaire