<commit_before>import {TestBed} from '@angular/core/testing';

import {CandidateService} from './candidate';
import {Candidate} from '../models/Candidate';
import {Polygon} from '../models/Polygon';
import {Point} from '../models/Point';

describe('CandidateService', () => {
  let service: CandidateService;

  beforeEach(() => {
    TestBed.configureTestingModule({});
    service = TestBed.inject(CandidateService);
  });

  // TODO(#171): Add tests for polygonHovered/Unhovered.

  it('should be created', () => {
    expect(service).toBeTruthy();
  });

  describe('#addPolygons', () => {
    it('candidate is already present in map', () => {
      service = new CandidateService();
      service.addCandidate(3, '1');
      const inputPolygons: Polygon[] = [
        new Polygon([new Point(0, 10), new Point(1, 0)], '1', 3),
      ];
      service.addPolygons(inputPolygons);
      expect(service.cands.get('1').polygons).toEqual(inputPolygons);
    });

    it('candidate is not already present in map', () => {
      service = new CandidateService();
      service.addCandidate(5, '1');
      const inputPolygons: Polygon[] = [
        new Polygon([new Point(0, 10), new Point(1, 0)], '2', 3),
      ];
      service.addPolygons(inputPolygons);
      expect(service.cands.get('1').candName).toBe('1');
      expect(service.cands.get('2').polygons).toEqual(inputPolygons);
    });
  });
});<commit_msg>Add test for polygonHovered of CandidateService.<commit_after>import {TestBed} from '@angular/core/testing';

import {CandidateService} from './candidate';
import {Candidate} from '../models/Candidate';
import {Polygon} from '../models/Polygon';
import {Point} from '../models/Point';

describe('CandidateService', () => {
  let service: CandidateService;

  beforeEach(() => {
    TestBed.configureTestingModule({});
    service = TestBed.inject(CandidateService);
  });

  // TODO(#171): Add tests for polygonHovered/Unhovered.

  it('should be created', () => {
    expect(service).toBeTruthy();
  });

  describe('#addPolygons', () => {
    it('candidate is already present in map', () => {
      service = new CandidateService();
      service.addCandidate(3, '1');
      const inputPolygons: Polygon[] = [
        new Polygon([new Point(0, 10), new Point(1, 0)], '1', 3),
      ];
      service.addPolygons(inputPolygons);
      expect(service.cands.get('1').polygons).toEqual(inputPolygons);
    });

    it('candidate is not already present in map', () => {
      service = new CandidateService();
      service.addCandidate(5, '1');
      const inputPolygons: Polygon[] = [
        new Polygon([new Point(0, 10), new Point(1, 0)], '2', 3),
      ];
      service.addPolygons(inputPolygons);
      expect(service.cands.get('1').candName).toBe('1');
      expect(service.cands.get('2').polygons).toEqual(inputPolygons);
    });
  });

  describe('#polygonHovered', () => {
    it('test', () => {
      service = new CandidateService();
      service.addCandidate(5, '1');
      const polygonToBeHoveredOver: Polygon = new Polygon(
        [new Point(0, 10), new Point(1, 0)],
        '1'
      );
      const polygonsOfCandidate: Polygon[] = [
        polygonToBeHoveredOver,
        new Polygon([new Point(0, 20), new Point(1, 0)], '1'),
      ];
      service.addPolygons(polygonsOfCandidate);
      service.polygonHovered(polygonToBeHoveredOver);

      // all the polygons of candidate named '1' should have the highlight property true
      expect(
        service.cands.get('1').polygons.filter(polygon => polygon.highlight)
          .length
      ).toEqual(2);
    });
  });
});
{'fraction_non_alphanumeric': 0.17406996113270407, 'fraction_numerical': 0.018600777345918935, 'mean_word_length': 3.351449275362319, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '930276', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1134, 'n_words': 236}