{"size": 7226, "ext": "js", "max_stars_repo_path": "components/quarterback/quarterback.spec.js", "max_stars_repo_name": "DustinOgan/tsb-stats-extractor", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "components/quarterback/quarterback.spec.js", "max_issues_repo_name": "DustinOgan/tsb-stats-extractor", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "components/quarterback/quarterback.spec.js", "max_forks_repo_name": "DustinOgan/tsb-stats-extractor", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 50.5314685315, "max_line_length": 160, "alphanum_fraction": 0.6603930252}
const { expect } = require("chai");
const qb = require('./quarterback.js');


describe('the qb ', async function () {
    it('should successfully import qb stats', async function () {
        const expectedQb = {
            passAttemptsBase: 20,
            passCompleteBase: 10,
            passTdBase: 8,
            passIntBase: 12,
            passYardsBase: 38,
            rushAttempts: 3,
            rushYardsBase: 28,
            modPassRushYards: 8,
            rushTDsBase: 4
        };
        const testQb = await qb.mapStats([20, 10, 8, 12, 38, 3, 28, 8, 4])
        expect(testQb).to.eql(expectedQb);
    })


    it('should successfully calculate pass attempts for low attempts qb < 255', async function () {
        /* attempts 229 * yards 3068 * completeions 126 * touchdowns 26 * interceptions 20* rushing att 56  rushing yards 306  * rushing tds 4*/
        const testQb = await qb.mapStats([229, 126, 104, 80, 252, 56, 50, 89, 16])
        const passAttempts = await qb.calculatePassAttempts(testQb.passAttemptsBase, testQb.passTdBase)
        expect(passAttempts).to.equal(229);
    })

    it('should successfully calculate passing tds for high attempts qb', async function () {
        /* attempts: 272 * Yards 3778 * completions 155 * touchdowns 31 * interceptions 27 */
        const testQb = await qb.mapStats([16, 155, 125, 108, 194, 0, 0, 112, 0])
        const testPassTd = await qb.calculatePassTds(testQb.passTdBase)
        expect(testPassTd).to.equal(31);
    })

    it('should successfully calculate passing tds for low attempts qb', async function () {
        const testQb = await qb.mapStats([20, 10, 8, 12, 38, 3, 28, 8, 4])
        const testPassTd = await qb.calculatePassTds(testQb.passTdBase)
        expect(testPassTd).to.equal(2);
    })

    it('should successfully calculate passing ints for high attempts qb', async function () {
        /* attempts: 272 * Yards 3778 * completions 155 * touchdowns 31 * interceptions 27 */
        const testQb = await qb.mapStats([16, 155, 125, 108, 194, 0, 0, 112, 0])
        const testPassInt = await qb.calculatePassTds(testQb.passIntBase)
        expect(testPassInt).to.equal(27);
    })

    it('should successfully calculate passing ints for low attempts qb', async function () {
        const testQb = await qb.mapStats([20, 10, 8, 12, 38, 3, 28, 8, 4])
        const testPassInt = await qb.calculatePassTds(testQb.passIntBase)
        expect(testPassInt).to.equal(3);
    })

    it('should successfully calculate pass attempts for high attempts qb > 255', async function () {
        /* attempts: 272 * Yards 3778 * completions 155 * touchdowns 31 * interceptions 27 */
        const testQb = await qb.mapStats([16, 155, 125, 108, 194, 0, 0, 112, 0])
        const testPassAttempts = await qb.calculatePassAttempts(testQb.passAttemptsBase, testQb.passTdBase)
        expect(testPassAttempts).to.equal(272);
    })

    it('should calculate passing yards over 255', async function () {
        /* attempts: 272 * Yards 3778 * completions 155 * touchdowns 31 * interceptions 27 */
        const testQb = await qb.mapStats([16, 155, 125, 108, 194, 0, 0, 112, 0])
        const testPassYards = await qb.calculatePassYards(testQb.passYardsBase, testQb.modPassRushYards)
        expect(testPassYards).to.equal(3778);
    })

    it('should successfully calculate pass completions', async function () {
        /* attempts: 272 * Yards 3778 * completions 155 * touchdowns 31 * interceptions 27 */
        const testQb = await qb.mapStats([16, 155, 125, 108, 194, 0, 0, 112, 0])
        const testCompletions = await qb.calculatePassCompletions(testQb.passCompleteBase, testQb.passIntBase)
        expect(testCompletions).to.equal(155);
    })

    it('should correclty calculate the avg passing yardage to match tsb on screen', async function () {
        /* attempts: 272 * Yards 3778 * completions 155 *  avg 13.8 */
        const testYardsActual = 3778;
        const testAttemptsActual = 272
        const avgPassingYards = await qb.calculateAvgYards(testYardsActual, testAttemptsActual);
        expect(avgPassingYards).to.equal(13.8)
    })

    it('should return a rating that matches the rating displayed on tsb player info', async function () {
        /* attempts: 272 * Yards 3778 * completions 155 * touchdowns 31 * interceptions 27 */
        const testYardsActual = 3778;
        const testAttemptsActual = 272;
        const testCompletionsActual = 155;
        const testTouchdownsActual = 31;
        const testInterceptionsActual = 27;
        const testQbRating = await qb.calculateRating(testYardsActual, testAttemptsActual, testCompletionsActual, testTouchdownsActual, testInterceptionsActual)
        expect(testQbRating).to.equal(104.0)
    })

    it('should return a completion percentage that matches the rating displayed for a player in tsb', async function () {
        /* attempts: 272 * completions 155 * completion percentage 56.9*/
        const testAttemptsActual = 272;
        const testCompletionsActual = 155;
        const testCompletionPercentage = await qb.calculateCompletionPercentage(testAttemptsActual, testCompletionsActual)
        expect(testCompletionPercentage).to.equal(56.9)
    })

    
    it('should successfully handle the 0 case', async function () {
        /* based on full season of backup qb with 0 for all statistics */
        const testQb = await qb.mapStats([0, 0, 0, 0, 0, 0, 0, 0, 0])
        const testPassAttempts = await qb.calculatePassAttempts(testQb.passAttemptsBase, testQb.passTdBase)
        expect(testPassAttempts).to.equal(0);
        const testPassYards = await qb.calculatePassYards(testQb.passYardsBase, testQb.modPassRushYards)
        expect(testPassYards).to.equal(0);

    })

    it('should successfully calculate the qbs rush attempts', async function(){
        /* rushAttempts: 56 * rush yds : 306 * rush td 4 */
        const testQb = await qb.mapStats([ 229, 126, 104, 80, 252, 56, 50, 89, 16 ])
        const testQbRushAttempts = await qb.calculateRushAttempts(testQb.rushAttempts)
        expect(testQbRushAttempts).to.equal(56);
    })

    it('should successfully calcuate the qbs rushing yards', async function(){
        /* rushAttempts: 56 * rush yds : 306 * rush td 4 */
        const testQb = await qb.mapStats([ 229, 126, 104, 80, 252, 56, 50, 89, 16 ])
        const testQbRushYards = await qb.calculateRushYards(testQb.rushYardsBase, testQb.modPassRushYards)
        expect(testQbRushYards).to.equal(306);
    })

    it('should successfully calculate the qbs rushing tds', async function(){
         /* rushAttempts: 56 * rush yds : 306 * rush td 4 */
         const testQb = await qb.mapStats([ 229, 126, 104, 80, 252, 56, 50, 89, 16 ])
         const testQbRushTds = await qb.calculateRushTds(testQb.rushTDsBase)
        expect(testQbRushTds).to.equal(4);
    })

    it('should successfully caculate the qbs rushing average', async function(){
         /* rushAttempts: 56 * rush yds : 306 * rush td 4 , rush avg 5.4*/
        const testQb = await qb.mapStats([ 229, 126, 104, 80, 252, 56, 50, 89, 16 ])
        const testAvgRushYards = await qb.calculateAvgYards(306, 56)
        expect(testAvgRushYards).to.equal(5.4);

    })
})