<commit_before>import { TestBed, inject, fakeAsync, tick } from "@angular/core/testing";
import { TapeService } from "./tape.service";
import { TAPES } from "./mock-tapes";
import { Tape } from "./tape";

describe('Tape Service Test', () => {
    let tapes: Tape[];
    let tape: Tape;
    let rentedTapes: Tape[];
    let sortedTapes: Tape[];
    let service: TapeService;
    beforeEach(async () => {
        TestBed.configureTestingModule({
            providers: [TapeService]
        }).compileComponents();
    });

    it('can instantiate service when inject service',
        inject([TapeService], (service: TapeService) => {
            expect(service instanceof TapeService).toBe(true);
        }));
    it('it can getTapes', inject([TapeService],
        fakeAsync((service: TapeService) => {
            service.getTapes().then(tapesFromService => tapes = tapesFromService);
            tick();
            expect(tapes.length).toEqual(TAPES.length);
        })));
    it('it can getTape by id', inject([TapeService],
        fakeAsync((service: TapeService) => {
            let tapeId: number = 1;
            service.getTape(tapeId).then(tapeFromService => tape = tapeFromService);
            tick();
            expect(tape.id).toEqual(tapeId);
        })));
    it('it can get rentedtapes', inject([TapeService],
        fakeAsync((service: TapeService) => {
            let numberOfRentedTapes: number=6;
            service.getRentedTapes().then(tapesFromService => rentedTapes = tapesFromService);
            tick();
            expect(rentedTapes.length).toEqual(numberOfRentedTapes);
        })));
            it('it can get tapes sorted by title', inject([TapeService],
        fakeAsync((service: TapeService) => {
            let sortTerm: string='title';
            let expectedTitle: string='Alien';
            let ascending: boolean=true;
            service.getSortedTapes(sortTerm,true).then(tapesFromService => sortedTapes = tapesFromService);
            tick();
            expect(sortedTapes[0].title).toEqual(expectedTitle);
        })));
});<commit_msg>with test for sorting by rating<commit_after>import { TestBed, inject, fakeAsync, tick } from "@angular/core/testing";
import { TapeService } from "./tape.service";
import { TAPES } from "./mock-tapes";
import { Tape } from "./tape";

describe('Tape Service Test', () => {
    let tapes: Tape[];
    let tape: Tape;
    let rentedTapes: Tape[];
    let sortedTapes: Tape[];
    beforeEach(async () => {
        TestBed.configureTestingModule({
            providers: [TapeService]
        }).compileComponents();
    });

    it('can instantiate service when inject service',
        inject([TapeService], (service: TapeService) => {
            expect(service instanceof TapeService).toBe(true);
        }));
    it('it can getTapes', inject([TapeService],
        fakeAsync((service: TapeService) => {
            service.getTapes().then(tapesFromService => tapes = tapesFromService);
            tick();
            expect(tapes.length).toEqual(TAPES.length);
        })));
    it('it can getTape by id', inject([TapeService],
        fakeAsync((service: TapeService) => {
            let tapeId: number = 1;
            service.getTape(tapeId).then(tapeFromService => tape = tapeFromService);
            tick();
            expect(tape.id).toEqual(tapeId);
        })));
    it('it can get rentedtapes', inject([TapeService],
        fakeAsync((service: TapeService) => {
            let numberOfRentedTapes: number=6;
            service.getRentedTapes().then(tapesFromService => rentedTapes = tapesFromService);
            tick();
            expect(rentedTapes.length).toEqual(numberOfRentedTapes);
        })));
            it('it can get tapes sorted by title ascending', inject([TapeService],
        fakeAsync((service: TapeService) => {
            let sortTerm: string='title';
            let expectedTitle: string='Alien';
            let ascending: boolean=true;
            service.getSortedTapes(sortTerm,ascending).then(tapesFromService => sortedTapes = tapesFromService);
            tick();
            expect(sortedTapes[0].title).toEqual(expectedTitle);
        })));
                    it('it can get tapes sorted by title descending', inject([TapeService],
        fakeAsync((service: TapeService) => {
            let sortTerm: string='title';
            let expectedTitle: string='The Sting';
            let ascending: boolean=false;
            service.getSortedTapes(sortTerm,ascending).then(tapesFromService => sortedTapes = tapesFromService);
            tick();
            expect(sortedTapes[0].title).toEqual(expectedTitle);
        })));
        //getRentedTapesSortedByParameter(parameter: string,asc: boolean)
         it('it can get rented tapes sorted by rating ascending', inject([TapeService],
        fakeAsync((service: TapeService) => {
            let sortTerm: string='rating';
            let expectedTitle: string='Rocky';
            let ascending: boolean=true;
            service.getRentedTapesSortedByParameter(sortTerm,ascending).then(tapesFromService => sortedTapes = tapesFromService);
            tick();
            expect(sortedTapes[0].title).toEqual(expectedTitle);
        })));
                 it('it can get rented tapes sorted by rating descending', inject([TapeService],
        fakeAsync((service: TapeService) => {
            let sortTerm: string='rating';
            let expectedTitle: string='Star Wars: Episode VI - Return of the Jedi';
            let ascending: boolean=false;
            service.getRentedTapesSortedByParameter(sortTerm,ascending).then(tapesFromService => sortedTapes = tapesFromService);
            tick();
            expect(sortedTapes[0].title).toEqual(expectedTitle);
        })));
});
{'fraction_non_alphanumeric': 0.13159259899706036, 'fraction_numerical': 0.0015562856648798202, 'mean_word_length': 2.6584440227703983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '789357', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1588, 'n_words': 333}