<commit_before>module('tl.enchant.js', {
    setup: function() {
        enchant();
        var game = new Core();
        var sprite = new Sprite(32, 32);
        sprite.moveTo(0, 0);
        game.rootScene.addChild(sprite);
    },
    teardown: function() {

    }
});

test('tl.frameBased', function() {
    var sprite = enchant.Core.instance.rootScene.childNodes[0];

    equal(sprite.tl.isFrameBased, true);
    sprite.tl.setFrameBased();
    equal(sprite.tl.isFrameBased, true);
    sprite.tl.setTimeBased();
    equal(sprite.tl.isFrameBased, false);
    sprite.tl.setFrameBased();
    equal(sprite.tl.isFrameBased, true);
});

test('tl.delay.then', function() {
    var sprite = enchant.Core.instance.rootScene.childNodes[0];
    var then = false;
    sprite.tl.delay(30).then(function() {
        then = true;
    });
    ok(!then);

    var enterframe = new enchant.Event('enterframe');
    for (var i = 0; i < 30 - 1; i++) {
        sprite.dispatchEvent(enterframe);
    }

    ok(!then);
    sprite.dispatchEvent(enterframe);
    ok(then);

    sprite.tl.clear();
});

test('tl.tween', function() {
    var sprite = enchant.Core.instance.rootScene.childNodes[0];
    sprite.tl.moveTo(320, 320, 30);
    equal(sprite.x, 0);
    equal(sprite.y, 0);
    for (var i = 0; i < 30 - 1; i++) {
        var enterframe = new enchant.Event('enterframe');
        sprite.dispatchEvent(enterframe);
    }
    notEqual(Math.round(sprite.x, 5), 320);
    notEqual(Math.round(sprite.y, 5), 320);

    sprite.dispatchEvent(enterframe);
    equal(Math.round(sprite.x, 5), 320);
    equal(Math.round(sprite.y, 5), 320);
});


test('tl.tween', function() {
    var sprite = enchant.Core.instance.rootScene.childNodes[0];
    sprite.tl.moveTo(320, 320, 30);
    equal(sprite.x, 0);
    equal(sprite.y, 0);
    for (var i = 0; i < 30 - 1; i++) {
        var enterframe = new enchant.Event('enterframe');
        sprite.dispatchEvent(enterframe);
    }
    notEqual(Math.round(sprite.x, 5), 320);
    notEqual(Math.round(sprite.y, 5), 320);

    sprite.dispatchEvent(enterframe);
    equal(Math.round(sprite.x, 5), 320);
    equal(Math.round(sprite.y, 5), 320);
});


test('tl.tween (minus)', function() {
    var sprite = enchant.Core.instance.rootScene.childNodes[0];

    sprite.moveTo(200, 0);
    sprite.tl.moveBy(-200, 0, 8);
    equal(sprite.x, 200);

    for (var i = 0; i < 8; i++) {
        var enterframe = new enchant.Event('enterframe');
        sprite.dispatchEvent(enterframe);
    }
    equal(sprite.x, 0);
});


test('tl.fadeOut', function() {
    var sprite = enchant.Core.instance.rootScene.childNodes[0];
    sprite.tl.fadeOut(10);
    equal(sprite.opacity, 1);
    for (var i = 0; i < 10 - 1; i++) {
        var enterframe = new enchant.Event('enterframe');
        sprite.dispatchEvent(enterframe);
    }
    notEqual(sprite.opacity, 0);

    sprite.dispatchEvent(enterframe);
    equal(sprite.opacity, 0);
});

/* time based testing */

test('tl.timebased.delay.then', function() {
    var sprite = enchant.Core.instance.rootScene.childNodes[0];
    sprite.tl.setTimeBased();
    var then = false;
    sprite.tl.delay(1000).then(function() {
        then = true;
    });
    ok(!then);

    var enterframe = new enchant.Event('enterframe');
    enterframe.elapsed = 33;<commit_msg>added a new test case for multiple timelines<commit_after>module('tl.enchant.js', {
    setup: function() {
        enchant();
        var game = new Core();
        var sprite = new Sprite(32, 32);
        sprite.moveTo(0, 0);
        game.rootScene.addChild(sprite);
    },
    teardown: function() {

    }
});

test('tl.frameBased', function() {
    var sprite = enchant.Core.instance.rootScene.childNodes[0];

    equal(sprite.tl.isFrameBased, true);
    sprite.tl.setFrameBased();
    equal(sprite.tl.isFrameBased, true);
    sprite.tl.setTimeBased();
    equal(sprite.tl.isFrameBased, false);
    sprite.tl.setFrameBased();
    equal(sprite.tl.isFrameBased, true);
});

test('tl.delay.then', function() {
    var sprite = enchant.Core.instance.rootScene.childNodes[0];
    var then = false;
    sprite.tl.delay(30).then(function() {
        then = true;
    });
    ok(!then);

    var enterframe = new enchant.Event('enterframe');
    for (var i = 0; i < 30 - 1; i++) {
        sprite.dispatchEvent(enterframe);
    }

    ok(!then);
    sprite.dispatchEvent(enterframe);
    ok(then);

    sprite.tl.clear();
});

test('tl.tween', function() {
    var sprite = enchant.Core.instance.rootScene.childNodes[0];
    sprite.tl.moveTo(320, 320, 30);
    equal(sprite.x, 0);
    equal(sprite.y, 0);
    for (var i = 0; i < 30 - 1; i++) {
        var enterframe = new enchant.Event('enterframe');
        sprite.dispatchEvent(enterframe);
    }
    notEqual(Math.round(sprite.x, 5), 320);
    notEqual(Math.round(sprite.y, 5), 320);

    sprite.dispatchEvent(enterframe);
    equal(Math.round(sprite.x, 5), 320);
    equal(Math.round(sprite.y, 5), 320);
});


test('tl.tween', function() {
    var sprite = enchant.Core.instance.rootScene.childNodes[0];
    sprite.tl.moveTo(320, 320, 30);
    equal(sprite.x, 0);
    equal(sprite.y, 0);
    for (var i = 0; i < 30 - 1; i++) {
        var enterframe = new enchant.Event('enterframe');
        sprite.dispatchEvent(enterframe);
    }
    notEqual(Math.round(sprite.x, 5), 320);
    notEqual(Math.round(sprite.y, 5), 320);

    sprite.dispatchEvent(enterframe);
    equal(Math.round(sprite.x, 5), 320);
    equal(Math.round(sprite.y, 5), 320);
});


test('tl.tween (minus)', function() {
    var sprite = enchant.Core.instance.rootScene.childNodes[0];

    sprite.moveTo(200, 0);
    sprite.tl.moveBy(-200, 0, 8);
    equal(sprite.x, 200);

    for (var i = 0; i < 8; i++) {
        var enterframe = new enchant.Event('enterframe');
        sprite.dispatchEvent(enterframe);
    }
    equal(sprite.x, 0);
});


test('tl.fadeOut', function() {
    var sprite = enchant.Core.instance.rootScene.childNodes[0];
    sprite.tl.fadeOut(10);
    equal(sprite.opacity, 1);
    for (var i = 0; i < 10 - 1; i++) {
        var enterframe = new enchant.Event('enterframe');
        sprite.dispatchEvent(enterframe);
    }
    notEqual(sprite.opacity, 0);

    sprite.dispatchEvent(enterframe);
    equal(sprite.opacity, 0);
});

var periodTestingFunction = function(time, checkArray,period,sprite,property) {
    for(var j = 0; j < checkArray.length; j++) {
        if(checkArray[j][0] === time%period) {
            equal(sprite[property] === checkArray[j][1],checkArray[j][2],' ' + property + ' for time ' + time + ' testing: ' + checkArray[j][1] + ' === ' + sprite[property] + ', expecting ' + checkArray[j][2]);
        }
    }
}

test('tl.multipleTl', function() {
    var sprite = enchant.Core.instance.rootScene.childNodes[0];
    var tl = new Timeline(sprite,true);
    tl.rotateTo(360,10).delay(2).rotateTo(0,10).delay(2).loop();
    var rotateCheck = [[0,0,true],[9,0,false],[10,360,true],
                   [11,360,false],[19,360,false],
                   [19,0,false]
                   ];
    var rotationPeriod = 20;
    
    tl = new Timeline(sprite,true);
    tl.delay(Math.round(Math.random()*10+5)).delay(Math.round(Math.random()*10+5))
    .delay(Math.round(Math.random()*10+5)).delay(Math.round(Math.random()*10+5));
    
    tl = new Timeline(sprite,true);
    tl.fadeOut(20).delay(2).fadeIn(20).delay(2).loop();
    var fadeCheck = [[0,1,true],[9,1,false],[19,1,false],[20,0,true],
                   [21,0,false],[29,0,false],[39,0,false],
                   [39,1,false]
                   ];
    var fadePeriod = 40;
    
    sprite.tl.moveTo(300,sprite.y,10).scaleTo(-1,1,1).delay(2).moveTo(0,sprite.y,10).scaleTo(1,1,1).delay(2).loop();
    
    var spriteTlMoveCheckX = [[0,0,true],[9,300,false],[10,300,true],
                              [11,300,false],[19,300,false],
                              [19,0,false]
                              ];
    var spriteTlMoveCheckPeriodX = 20;
    
    var spriteTlScaleCheckX = [[0,1,true],[9,-1,false],[10,-1,true],
                              [11,-1,true],[19,-1,true]];
    var spriteTlScaleCheckPeriodX = 20;
    
    var enterframe = new enchant.Event('enterframe');
    
    for (var i = 0; i < 200 - 1; i++) {
        equal(sprite.y,0,' testing sprite.y === 0');
        equal(sprite.scaleY,1,' testing sprite.scaleY === 1');
        periodTestingFunction(i, rotateCheck,rotationPeriod,sprite,'rotation');
        periodTestingFunction(i, fadeCheck,fadePeriod,sprite,'opacity');
        periodTestingFunction(i, spriteTlMoveCheckX,spriteTlMoveCheckPeriodX,sprite,'x');
        periodTestingFunction(i, spriteTlScaleCheckX,spriteTlScaleCheckPeriodX,sprite,'scaleX');
        
        enterframe.elapsed = Math.round((Math.random()*50+10));
        sprite.dispatchEvent(enterframe);
    }
});


/* time based testing */

test('tl.timebased.delay.then', function() {
    var sprite = enchant.Core.instance.rootScene.childNodes[0];
    sprite.tl.setTimeBased();
    var then = false;
    sprite.tl.delay(1000).then(function() {
        then = true;
    });
    ok(!then);

    var enterframe = new enchant.Event('enterframe');
    enterframe.elapsed = 33;
{'fraction_non_alphanumeric': 0.17518009168303864, 'fraction_numerical': 0.0404933420650513, 'mean_word_length': 2.904132935662548, 'pattern_counts': {'":': 0, '<': 15, '<?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': '103225', 'n_tokens_mistral': 3534, 'n_tokens_neox': 3193, 'n_words': 539}