"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _immutable = require("immutable");

var _QuizAnalysis = _interopRequireDefault(require("../QuizAnalysis"));

describe('Quiz Analysis Record', function () {
  var analysis = {
    quizId: '0',
    quizAnalysis: {
      centile: Array.from({
        length: 100
      }, function () {
        return Math.floor(Math.random() * 5);
      }),
      decile: Array.from({
        length: 10
      }, function () {
        return Math.floor(Math.random() * 5);
      }),
      cronbachsAlpha: 0.75,
      scoreInfo: {
        scoreCount: 20,
        scoreSum: 100,
        scoreMax: 9,
        scoreMin: 2,
        elapsedTimeSum: 61,
        pointsPossible: 10,
        scoreStddevPop: 2.5
      }
    }
  };
  var quizAnalysis = new _QuizAnalysis.default((0, _immutable.fromJS)(analysis));
  describe('Score Information', function () {
    it('returns scoreInfo', function () {
      expect(quizAnalysis.scoreInfo().get('scoreCount')).to.be.equal(20);
      expect(quizAnalysis.scoreInfo().get('scoreSum')).to.be.equal(100);
    });
    it('calculates mean score percentage', function () {
      expect(quizAnalysis.meanScore()).to.be.equal('50%');
    });
    it('calculates high score percentage', function () {
      expect(quizAnalysis.highScore()).to.be.equal('90%');
    });
    it('calculates low score percentage', function () {
      expect(quizAnalysis.lowScore()).to.be.equal('20%');
    });
    it('calculates standard deviation', function () {
      expect(quizAnalysis.standardDeviation()).to.be.equal('2.5');
    });
    it('calculates mean elapsed time', function () {
      expect(quizAnalysis.meanElapsedTime()).to.be.equal(3);
    });
    it('returns cronbachs alpha', function () {
      expect(quizAnalysis.cronbachsAlpha()).to.be.equal('0.75');
    });
    it('calculates centile distribution', function () {
      expect(quizAnalysis.centileDistribution().length).to.be.equal(100);
    });
    it('calculates decile distribution', function () {
      expect(quizAnalysis.decileDistribution().length).to.be.equal(10);
    });
  });
  describe('Mean elapsed time', function () {
    it('rounds mean time', function () {
      expect(quizAnalysis.meanElapsedTime()).to.be.equal(3);
    });
  });
  context('with no submissions', function () {
    var emptyAnalysis = new _QuizAnalysis.default((0, _immutable.fromJS)(Object.assign({}, analysis, {
      quizAnalysis: {
        centile: Array.from({
          length: 100
        }, function () {
          return 0;
        }),
        decile: Array.from({
          length: 10
        }, function () {
          return 0;
        }),
        scoreInfo: {
          scoreCount: 0,
          scoreSum: 0,
          elapsedTimeSum: 0
        }
      }
    })));
    it('returns mean elapsed time', function () {
      expect(emptyAnalysis.meanElapsedTime()).to.be.equal(0);
    });
  });
});