<commit_before>eval(require('fs').readFileSync('sourcematrix.js', 'utf8'));

describe('SourceMatrix', function () {
    it('can store one VisualCmd', function () {
        var sourceMatrix = Object.create(SourceMatrix).init();
        sourceMatrix.addCommand(Object.create(VisualCmdRight));
        expect(sourceMatrix.toArray().length).toEqual(1);
        expect(VisualCmdRight.isPrototypeOf(sourceMatrix.toArray()[0])).toEqual(true);
    });

    it('can store several VisualCmds', function () {
        var sourceMatrix = Object.create(SourceMatrix).init();
        sourceMatrix.addCommand(Object.create(VisualCmdLeft));
        sourceMatrix.addCommand(Object.create(VisualCmdLeft));
        sourceMatrix.addCommand(Object.create(VisualCmdLeft));
        sourceMatrix.addCommand(Object.create(VisualCmdLeft));
        sourceMatrix.addCommand(Object.create(VisualCmdLeft));
        sourceMatrix.addCommand(Object.create(VisualCmdRight));
        expect(sourceMatrix.toArray().length).toEqual(6);
        expect(VisualCmdLeft.isPrototypeOf(sourceMatrix.toArray()[0])).toEqual(true);
        expect(VisualCmdRight.isPrototypeOf(sourceMatrix.toArray()[5])).toEqual(true);
    });

    it('can store loops', function () {
        var visualCmdLoop = Object.create(VisualCmdLoop).init();
        visualCmdLoop.addChild(Object.create(VisualCmdLeft));
        visualCmdLoop.addChild(Object.create(VisualCmdRight));
        visualCmdLoop.addChild(Object.create(VisualCmdLeft));

        var sourceMatrix = Object.create(SourceMatrix).init();
        sourceMatrix.addCommand(Object.create(VisualCmdLeft));
        sourceMatrix.addCommand(Object.create(visualCmdLoop));
        sourceMatrix.addCommand(Object.create(VisualCmdLeft));

        var sourceMatrixArray = sourceMatrix.toArray();
        expect(sourceMatrixArray.length).toEqual(7);
        expect(VisualCmdLeft.isPrototypeOf(sourceMatrixArray[0])).toEqual(true);
        expect(VisualCmdLoop.isPrototypeOf(sourceMatrixArray[1])).toEqual(true);
        expect(VisualCmdRight.isPrototypeOf(sourceMatrixArray[3])).toEqual(true);
        expect(VisualCmdBodyEnd.isPrototypeOf(sourceMatrixArray[5])).toEqual(true);
        expect(VisualCmdLeft.isPrototypeOf(sourceMatrixArray[6])).toEqual(true);
    });
});

describe('VisualCmd', function () {
    describe('subclass VisualCmdLeft', function () {
        it('can print the correct source representation', function () {
            expect(Object.create(VisualCmdLeft).toSourceString())
                .toEqual('robot.moveLeft();\n');
        });
    });

    describe('subclass VisualCmdRight', function () {
        it('can print the correct source representation', function () {
            expect(Object.create(VisualCmdRight).toSourceString())
                .toEqual('robot.moveRight();\n');
        });
    });
<commit_msg>Test for nested loops in SourceMatrix<commit_after>eval(require('fs').readFileSync('sourcematrix.js', 'utf8'));

describe('SourceMatrix', function () {
    it('can store one VisualCmd', function () {
        var sourceMatrix = Object.create(SourceMatrix).init();
        sourceMatrix.addCommand(Object.create(VisualCmdRight));
        expect(sourceMatrix.toArray().length).toEqual(1);
        expect(VisualCmdRight.isPrototypeOf(sourceMatrix.toArray()[0])).toEqual(true);
    });

    it('can store several VisualCmds', function () {
        var sourceMatrix = Object.create(SourceMatrix).init();
        sourceMatrix.addCommand(Object.create(VisualCmdLeft));
        sourceMatrix.addCommand(Object.create(VisualCmdLeft));
        sourceMatrix.addCommand(Object.create(VisualCmdLeft));
        sourceMatrix.addCommand(Object.create(VisualCmdLeft));
        sourceMatrix.addCommand(Object.create(VisualCmdLeft));
        sourceMatrix.addCommand(Object.create(VisualCmdRight));
        expect(sourceMatrix.toArray().length).toEqual(6);
        expect(VisualCmdLeft.isPrototypeOf(sourceMatrix.toArray()[0])).toEqual(true);
        expect(VisualCmdRight.isPrototypeOf(sourceMatrix.toArray()[5])).toEqual(true);
    });

    it('can store loops', function () {
        var visualCmdLoop = Object.create(VisualCmdLoop).init();
        visualCmdLoop.addChild(Object.create(VisualCmdLeft));
        visualCmdLoop.addChild(Object.create(VisualCmdRight));
        visualCmdLoop.addChild(Object.create(VisualCmdLeft));

        var sourceMatrix = Object.create(SourceMatrix).init();
        sourceMatrix.addCommand(Object.create(VisualCmdLeft));
        sourceMatrix.addCommand(Object.create(visualCmdLoop));
        sourceMatrix.addCommand(Object.create(VisualCmdLeft));

        var sourceMatrixArray = sourceMatrix.toArray();
        expect(sourceMatrixArray.length).toEqual(7);
        expect(VisualCmdLeft.isPrototypeOf(sourceMatrixArray[0])).toEqual(true);
        expect(VisualCmdLoop.isPrototypeOf(sourceMatrixArray[1])).toEqual(true);
        expect(VisualCmdRight.isPrototypeOf(sourceMatrixArray[3])).toEqual(true);
        expect(VisualCmdBodyEnd.isPrototypeOf(sourceMatrixArray[5])).toEqual(true);
        expect(VisualCmdLeft.isPrototypeOf(sourceMatrixArray[6])).toEqual(true);
    });

    it('can store nested loops', function () {
        var visualCmdLoopInner = Object.create(VisualCmdLoop).init();
        visualCmdLoopInner.addChild(Object.create(VisualCmdRight));

        var visualCmdLoop = Object.create(VisualCmdLoop).init();
        visualCmdLoop.addChild(Object.create(VisualCmdLeft));
        visualCmdLoop.addChild(visualCmdLoopInner);

        var sourceMatrix = Object.create(SourceMatrix).init();
        sourceMatrix.addCommand(Object.create(visualCmdLoop));
        sourceMatrix.addCommand(Object.create(VisualCmdLeft));

        var sourceMatrixArray = sourceMatrix.toArray();
        expect(sourceMatrixArray.length).toEqual(7);
        expect(VisualCmdLoop.isPrototypeOf(sourceMatrixArray[0])).toEqual(true);
        expect(VisualCmdLeft.isPrototypeOf(sourceMatrixArray[1])).toEqual(true);
        expect(VisualCmdLoop.isPrototypeOf(sourceMatrixArray[2])).toEqual(true);
        expect(VisualCmdRight.isPrototypeOf(sourceMatrixArray[3])).toEqual(true);
        expect(VisualCmdBodyEnd.isPrototypeOf(sourceMatrixArray[4])).toEqual(true);
        expect(VisualCmdBodyEnd.isPrototypeOf(sourceMatrixArray[5])).toEqual(true);
        expect(VisualCmdLeft.isPrototypeOf(sourceMatrixArray[6])).toEqual(true);
    });
});

describe('VisualCmd', function () {
    describe('subclass VisualCmdLeft', function () {
        it('can print the correct source representation', function () {
            expect(Object.create(VisualCmdLeft).toSourceString())
                .toEqual('robot.moveLeft();\n');
        });
    });

    describe('subclass VisualCmdRight', function () {
        it('can print the correct source representation', function () {
            expect(Object.create(VisualCmdRight).toSourceString())
                .toEqual('robot.moveRight();\n');
        });
    });

{'fraction_non_alphanumeric': 0.13665223665223666, 'fraction_numerical': 0.004617604617604618, 'mean_word_length': 4.199549887471868, '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': '2318018', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1893, 'n_words': 201}