<commit_before>'use strict';

describe('Sprint controller', function() {

  beforeEach(function() {
    module('words');
    module(['$provide', function($provide) {
        $provide.service('mockWordsLoader', function() {
        this.getWords = jasmine.createSpy('getWords').and.returnValue({
          'word': 'car',
          'category': 'common',
          'translation': {
            'ua': ['автомобіль'],
            'ru': ['автомобиль']
          }
        });
      });
    }]);
  });

  it('get words from loader service', inject(['$controller', '$rootScope', 'mockWordsLoader',
  function($controller, $rootScope, mockWordsLoader) {
    var mockScope = $rootScope.$new();
    var sprintCtrl = $controller('SprintCtrl', {
      '$scope': mockScope,
      'wordsLoaderService': mockWordsLoader
    });

    expect(sprintCtrl).toBeDefined();
    expect(mockWordsLoader.getWords).toHaveBeenCalled();
    expect(mockScope.data).toEqual({
      'word': 'car',
      'category': 'common',
      'translation': {
        'ua': ['автомобіль'],
        'ru': ['автомобиль']
      }
    });
  }]));

  it('should create anwer array', inject(['$controller', '$rootScope', 'mockWordsLoader',
  function($controller, $rootScope, mockWordsLoader) {
    var mockScope = $rootScope.$new();
    var sprintCtrl = $controller('SprintCtrl', {
      '$scope': mockScope,
      'wordsLoaderService': mockWordsLoader
    });

    expect(sprintCtrl).toBeDefined();
    expect(mockScope.data.translation.ua).toBeDefined();
    expect(mockScope.answer).toBeDefined();
    expect(mockScope.answer.length).toEqual(mockScope.data.translation.ua[0].length);
  }]));
});
<commit_msg>Added test for checking user answer<commit_after>'use strict';

describe('Sprint controller', function() {
  var scope, wordsLoader, sprintCtrl;

  beforeEach(function() {
    module('words');
    module(['$provide', function($provide) {
        $provide.service('mockWordsLoader', function() {
        this.getWords = jasmine.createSpy('getWords').and.returnValue({
          'word': 'car',
          'category': 'common',
          'translation': {
            'ua': ['автомобіль'],
            'ru': ['автомобиль']
          }
        });
      });
    }]);
  });

  beforeEach(inject(['$rootScope', '$controller', 'mockWordsLoader',
  function($rootScope, $controller, mockWordsLoader) {
    scope = $rootScope.$new();
    wordsLoader = mockWordsLoader;
    sprintCtrl = $controller('SprintCtrl', {
      '$scope': scope,
      'wordsLoaderService': wordsLoader
    });
  }]));

  it('get words from loader service', function() {
    expect(wordsLoader.getWords).toHaveBeenCalled();
    expect(scope.data).toEqual({
      'word': 'car',
      'category': 'common',
      'translation': {
        'ua': ['автомобіль'],
        'ru': ['автомобиль']
      }
    });
  });

  it('create answer array', function() {
    expect(scope.data.translation.ua).toBeDefined();
    expect(scope.answer).toBeDefined();
    expect(scope.answer.length).toEqual(scope.data.translation.ua[0].length);
  });

  it('checkAnswer change answerState to NA if answer is not full', function() {
    scope.checkAnswer();
    expect(scope.answerState).toEqual('NA');
  });

  it('checkAnswer change answerState to INCORRECT if answer is full, but not correct', function() {
    var position = 0;

    for(var elem of scope.data.translation.ua[0]) {
      scope.answer[position++] = {char: 'a'};
    }

    scope.checkAnswer();
    expect(scope.answerState).toEqual('INCORRECT');
  });

  it('checkAnswer change answerState to CORRECT if answer is full and correct', function() {
    var position = 0;

    for(var elem of scope.data.translation.ua[0]) {
      scope.answer[position++] = {char: elem};
    }

    scope.checkAnswer();
    expect(scope.answerState).toEqual('CORRECT');
  });
});

{'fraction_non_alphanumeric': 0.17379958246346555, 'fraction_numerical': 0.0015657620041753654, 'mean_word_length': 3.2779017857142856, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4875719', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1148, 'n_words': 212}