"use strict";

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

var _immutable = require("immutable");

var _formatMessage = _interopRequireDefault(require("@instructure/quiz-common/lib/format-message"));

var _ItemAnalysis = _interopRequireDefault(require("../ItemAnalysis"));

var _SDKApp = require("../../components/SDKApp");

describe('Item Analysis Record', function () {
  _formatMessage.default.setup({
    formats: (0, _SDKApp.generateFormats)('America/Denver')
  });

  var itemAnalysis = new _ItemAnalysis.default((0, _immutable.fromJS)({
    itemId: '0',
    itemAnalysis: {
      scoreInfo: {
        resultCount: 5,
        resultSum: 10,
        scoreStddevPop: 2.5
      },
      correctAnswerInfo: {
        appearedCount: 5,
        resultCount: 2,
        resultSum: 10
      },
      incorrectAnswerInfo: {
        appearedCount: 5,
        resultCount: 1,
        resultSum: 0
      },
      topCorrectAnswerInfo: {
        appearedCount: 4,
        resultCount: 1,
        resultSum: 10
      },
      bottomCorrectAnswerInfo: {
        appearedCount: 1,
        resultCount: 0,
        resultSum: 0
      },
      unansweredInfo: 0,
      choiceInfo: [{
        itemBody: 'Monday',
        id: '1',
        choiceCount: 0
      }, {
        itemBody: 'Tuesday',
        id: '2',
        choiceCount: 2
      }, {
        itemBody: 'Wednesday',
        id: '3',
        choiceCount: 3
      }],
      quintile: [1, 1, 2, 3, 5]
    }
  }));
  describe('Score Information', function () {
    it('returns scoreInfo', function () {
      expect(itemAnalysis.scoreInfo().get('resultCount')).to.be.equal(5);
      expect(itemAnalysis.scoreInfo().get('resultSum')).to.be.equal(10);
    });
    it('calculates mean score', function () {
      expect(itemAnalysis.meanScore()).to.be.equal('2.00');
    });
  });
  describe('Diffculty Information', function () {
    it('returns correctAnswerInfo', function () {
      expect(itemAnalysis.correctAnswerInfo().get('appearedCount')).to.be.equal(5);
      expect(itemAnalysis.correctAnswerInfo().get('resultCount')).to.be.equal(2);
    });
    it('calculates difficulty index', function () {
      expect(itemAnalysis.difficultyIndex()).to.be.equal('0.40');
    });
  });
  describe('Unanswered Information', function () {
    var unanswerableAnalysis = new _ItemAnalysis.default((0, _immutable.fromJS)({
      itemAnalysis: {
        unansweredInfo: 4,
        choiceInfo: [{
          itemBody: 'Pizza',
          choiceCount: 1
        }, {
          itemBody: 'Tacos',
          choiceCount: 2
        }]
      }
    }));
    it('returns unansweredInfo', function () {
      expect(unanswerableAnalysis.unansweredInfo()).to.eq(4);
    });
    it('is included in choice counts', function () {
      expect(unanswerableAnalysis.choiceCountMax()).to.eq(4);
      expect(unanswerableAnalysis.choiceCountSum()).to.eq(7);
    });
  });
  describe('Discrimination Information', function () {
    it('returns difficultyInfo for top scorers', function () {
      expect(itemAnalysis.topCorrectAnswerInfo().get('appearedCount')).to.be.equal(4);
      expect(itemAnalysis.topCorrectAnswerInfo().get('resultCount')).to.be.equal(1);
    });
    it('returns difficultyInfo for bottom scorers', function () {
      expect(itemAnalysis.bottomCorrectAnswerInfo().get('appearedCount')).to.be.equal(1);
      expect(itemAnalysis.bottomCorrectAnswerInfo().get('resultCount')).to.be.equal(0);
    });
    it('calculates discrimination index', function () {
      expect(itemAnalysis.discriminationIndex()).to.be.equal('0.25');
    });
    it('returns null if discrimination index cannot be calculated', function () {
      var newItemAnalysis = new _ItemAnalysis.default((0, _immutable.fromJS)({
        itemAnalysis: {
          topCorrectAnswerInfo: {
            appearedCount: 1,
            resultCount: 1,
            resultSum: 10
          }
        }
      }));
      expect(newItemAnalysis.discriminationIndex()).to.be.equal(null);
    });
  });
  describe('Point BiSerial Correlation Coefficient', function () {
    it('calculates PBS', function () {
      expect(itemAnalysis.pointBiserial()).to.be.equal('0.57');
    });
    it('returns null if there are no incorrect answers', function () {
      var newItemAnalysis = itemAnalysis.setIn(['itemAnalysis', 'incorrectAnswerInfo', 'resultCount'], 0);
      expect(newItemAnalysis.pointBiserial()).to.be.equal(null);
    });
    it('returns null if standard deviation is 0', function () {
      var newItemAnalysis = itemAnalysis.setIn(['itemAnalysis', 'scoreInfo', 'scoreStddevPop'], 0);
      expect(newItemAnalysis.pointBiserial()).to.be.equal(null);
    });
  });
  describe('Choice Information', function () {
    it('returns choiceInfo', function () {
      expect(itemAnalysis.choiceInfo().toJS().length).to.be.equal(3);
    });
    it('calculates highest choice count', function () {
      expect(itemAnalysis.choiceCountMax()).to.be.equal(3);
    });
    it('calculates the sum of choice counts', function () {
      expect(itemAnalysis.choiceCountSum()).to.be.equal(5);
    });
  });
  describe('Calculated Metrics', function () {
    it('calculates the difficulty index', function () {
      expect(itemAnalysis.difficultyIndex()).to.be.equal('0.40');
    });
  });
  describe('Quintile Distribution', function () {
    it('returns quintile', function () {
      expect(itemAnalysis.quintile()).to.eql([1, 1, 2, 3, 5]);
    });
    it('defaults to empty quintile', function () {
      var itemAnalysis = new _ItemAnalysis.default((0, _immutable.fromJS)({
        itemId: '0',
        itemAnalysis: {}
      }));
      expect(itemAnalysis.quintile()).to.eql([0, 0, 0, 0, 0]);
    });
  });
});