All files App.js

100% Statements 28/28
100% Branches 4/4
100% Functions 8/8
100% Lines 27/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58        10x 10x 10x 10x       10x 10x 10x 10x       24x 24x 24x 24x       2x 11x 2x   9x         14x 14x 14x 14x       36x 36x     36x 6x 6x     36x 6x            
import BusdriverService from "./BusdriverService.js";
 
class App {
  constructor(properties) {
    this.maxSteps = properties.maxSteps;
    this.allRoutes = properties.allRoutes;
    this.steps = 1;
    this.initialize();
  }
 
  initialize() {
    this.service = new BusdriverService({ allRoutes: this.allRoutes });
    this.service.busdriverFactory();
    this.handleGossipExchange();
    this.reportIfSuccessful();
  }
 
  handleGossipExchange() {
    this.service.calculateNumberOfDriversAtStation();
    this.service.exchangeGossipIsPossibleAtStations();
    this.service.createStationsForGossipExhange();
    this.service.getDriversHaveFullGossipKnowledge();
  }
 
  run() {
    for (let i = 1; i < this.maxSteps; i++) {
      if (this.reportIfSuccessful()) {
        break;
      }
      this.nextStep();
    }
  }
 
  nextStep() {
    this.steps++;
    this.service.allDriveToNextStation();
    this.handleGossipExchange();
    this.reportIfSuccessful();
  }
 
  reportIfSuccessful() {
    const isFinished = () => {
      return this.service.isGossipKnowledgeComplete();
    };
 
    const reportResult = () => {
      console.log("Finished in " + this.steps + " steps");
      return (this.resultInSteps = this.steps);
    };
 
    if (isFinished()) {
      return !!reportResult();
    }
  }
}
 
export default App;