{"size": 4131, "ext": "js", "max_stars_repo_path": "test/scene_gameScene.test.js", "max_stars_repo_name": "hl778/SameGame-Phaser3", "max_stars_repo_stars_event_min_datetime": "2022-03-10T11:52:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-10T11:52:33.000Z", "max_issues_repo_path": "test/scene_gameScene.test.js", "max_issues_repo_name": "hl778/SameGame-Phaser3", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/scene_gameScene.test.js", "max_forks_repo_name": "hl778/SameGame-Phaser3", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.5275590551, "max_line_length": 91, "alphanum_fraction": 0.5611232147}
/**
 * test ../src/SceneGame
 */
const expect = require('chai').expect;

import Phaser from 'phaser';
import SceneGame from '../src/SceneGame';

// initialise with dumb data
let scene = new SceneGame('gameScene');
scene.init({});
scene.colli_tileGroup = [];
scene.colli_tileGroup.children = [];
scene.colli_tileGroup.children.entries = [];

scene.tileGroup_decreasing = {
    getChildren:()=>{
        return [];
    }};
scene.platform = {y:0};
scene.displayHeight = 0;
scene.initial_x_pos = [1.50000002,20.50000002];
scene.blueprint = [[1,1],[1,1]];

scene.scene = {};
scene.scene.switch = (s)=>{};

describe('#SceneGame - scores', function() {
    context('getStepScore', function() {
        it('should be int', function() {
            let res = Number.isInteger(scene.getStepScore(5));
            expect(res).to.equal(true);
        })
    })
    context('calculatePenalty', function() {
        it('should be int', function() {
            let res = Number.isInteger(scene.getStepScore(5));
            expect(res).to.equal(true);
        })
    })
})

describe('#SceneGame - logic', function() {
    this.timeout(10000);
    context('clickPause', function() {
        it('should store level info', function() {
            scene.clickPause();
            expect("restart_bluePrint" in localStorage).to.equal(true);
            expect("restart_level" in localStorage).to.equal(true);
            expect("restart_startScore" in localStorage).to.equal(true);
        })
    })
    context('clickPause', function() {
        it('should store level info', function() {
            scene.clickPause();
            expect("restart_bluePrint" in localStorage).to.equal(true);
            expect("restart_level" in localStorage).to.equal(true);
            expect("restart_startScore" in localStorage).to.equal(true);
        })
    })
    context('findXposKey', function() {
        it('should return the most similar key', function() {
            let res = SceneGame.getXposKey(1.50000001999,
                [1.50000002,20.50000002]);
            expect(res).to.eql([0,1.50000002]);
        })
    })

    context('extractOneCol', function() {
        it('should get one column', function() {
            let allTiles = [{x:1.50000002},{x:20.50000002},{x:1.50000002},{x:20.50000002}];
            let xpos = 1.50000002;
            scene.initial_x_pos = [1.50000002,20.50000002];
            let res = scene.getOneCol(allTiles, xpos);
            expect(res).to.eql([{x:1.50000002},{x:1.50000002}]);
        })
    })

    context('extractOneCol', function() {
        it('should get another column', function() {
            let allTiles = [{x:1.50000002},{x:20.50000002},{x:1.50000002},{x:20.50000002}];
            let xpos = 20.50000002;
            scene.initial_x_pos = [1.50000002,20.50000002];
            let res = scene.getOneCol(allTiles, xpos);
            expect(res).to.eql([{x:20.50000002},{x:20.50000002}]);
        })
    })

    context('checkAllStopped', function() {
        it('should return true', function() {
            let res = SceneGame.isAllStopped(scene.tileGroup_decreasing);
            expect(res).to.equal(true);
        })
    })

    context('checkAllStopped', function() {
        it('should return false', function() {
            let group = {
                getChildren:()=>{
                    return [{body:{velocity:{x:15}}}];
                }};
            let res = SceneGame.isAllStopped(group);
            expect(res).to.equal(false);
        })
    })

    context('arrangeDeleteOrder', function() {
        it('should return array with position sorted', function() {
            let toInsert = 7;
            let position = 2;
            let arr = [3,5,8,40];
            let res = SceneGame.getDeleteOrder(toInsert, position, arr);
            expect(res).to.eql([7,5,3,8,40]);
        })
    })

    context('findInsertIndex', function() {
        it('should return insertion index', function() {
            let arr = [3,5,8,40];
            let val = 6
            let res = SceneGame.getInsertIndex(arr, val);
            expect(res).to.equal(2);
        })
    })

})
