Commit f669df31 authored by Christoph Häfner's avatar Christoph Häfner

Add estimatedAmountOfSteps

parent 4f28e536
Pipeline #461 passed with stages
in 12 minutes and 55 seconds
export default (personalMovieListLength=0) => {
let steps = comparisons(personalMovieListLength);
steps++; // add one step for choosing the movie
if(userNeedsToChooseMovieForPersonalMovieList(personalMovieListLength)) {
steps++;
}
return steps;
}
function comparisons(number) {
return atLeastOne(Math.ceil(Math.log2(number)))
}
function atLeastOne(number) {
return Math.max(1, number)
}
function userNeedsToChooseMovieForPersonalMovieList(personalMovieListLength) {
return personalMovieListLength <= 0
}
\ No newline at end of file
import { expect } from 'chai'
import estimatedAmountOfSteps from '../../../../src/rate/process/lib/estimatedAmountOfSteps'
describe("estimatedAmountOfSteps", () => {
it("should be a function", () => {
expect(estimatedAmountOfSteps).to.be.a('function')
})
it("should return a number", () => {
expect(estimatedAmountOfSteps()).to.be.a('number')
})
it("should return three if given nothing (two choose + one comparsion)", () => {
expect(estimatedAmountOfSteps()).to.equal(3)
})
it("one movie takes two steps", () => {
expect(estimatedAmountOfSteps(1)).to.equal(2)
})
it("three movies take three steps", () => {
expect(estimatedAmountOfSteps(3)).to.equal(3)
})
it("four movies take three steps", () => {
expect(estimatedAmountOfSteps(4)).to.equal(3)
})
it("eight movies take four steps", () => {
expect(estimatedAmountOfSteps(8)).to.equal(4)
})
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment