<commit_before>define(["helper/Basic", "Tone/event/Sequence", "Tone/core/Tone", 
	"Tone/core/Transport", "Tone/event/Event", "helper/Offline2"], 
	function (Basic, Sequence, Tone, Transport, Event, Offline) {

	describe("Sequence", function(){

		Basic(Sequence);

		function resetTransport(done){
			Tone.Transport.cancel(0);
			Tone.Transport.off("start stop pause loop");
			Tone.Transport.stop();
			Tone.Transport.loop = false;
			Tone.Transport.PPQ = 48;
			Tone.Transport.bpm.value = 120;
			Tone.Transport.timeSignature = [4, 4];
			setTimeout(done, 200);
		}

		context("Constructor", function(){

			afterEach(resetTransport);

			it ("takes a callback and a sequence of values", function(){
				var callback = function(){};
				var seq = new Sequence(callback, [0, 1, 2]);
				expect(seq.callback).to.equal(callback);
				expect(seq.length).to.equal(3);
				seq.dispose();
			});

			it ("takes a callback and a sequence of values and a subdivision", function(){
				var callback = function(){};
				var seq = new Sequence(callback, [0, 1, 2], "2n");
				expect(seq.callback).to.equal(callback);
				expect(seq.subdivision).to.equal("2n");
				expect(seq.length).to.equal(3);
				seq.dispose();
			});

			it ("can be constructed with no arguments", function(){
				var seq = new Sequence();
				expect(seq.length).to.equal(0);
				seq.dispose();
			});

			it ("can pass in arguments in options object", function(){
				var callback = function(){};
				var seq = new Sequence({
					"callback" : callback,
					"humanize" : true,
					"events" : [0, 1, 2],
					"loop" : true,
					"loopEnd" : "4n",
					"probability" : 0.3
				});
				expect(seq.callback).to.equal(callback);
				expect(seq.length).to.equal(3);
				expect(seq.loop).to.be.true;
				expect(seq.loopEnd).to.equal("4n");
				expect(seq.probability).to.equal(0.3);
				expect(seq.humanize).to.be.true;
				seq.dispose();
			});

			it ("loops by default with the loopEnd as the duration of the loop", function(){
				var seq = new Sequence(function(){

				}, [0, 1, 2, 3], "8n");
				expect(seq.loop).to.be.true;
				expect(seq.length).to.equal(4);
				expect(seq.loopEnd).to.equal("2n");
				seq.dispose();
			});
		});

		context("Adding / Removing / Getting Events", function(){

			it("can add an event using the index", function(){
				var seq = new Sequence();
				seq.add(0, 0);
				expect(seq.length).to.equal(1);
				seq.add(1, 1);
				expect(seq.length).to.equal(2);
				seq.dispose();
			});

			it("can add a subsequence", function(){
				var seq = new Sequence();
				seq.add(0, [0, 1, 2]);
				expect(seq.length).to.equal(1);
				seq.dispose();
			});

			it ("can retrieve an event using 'at' and the index", function(){
				var seq = new Sequence(function(){}, [0, 1, 2]);
				expect(seq.length).to.equal(3);
				expect(seq.at(0)).to.be.instanceof(Event);
				expect(seq.at(0).value).to.equal(0);
				expect(seq.at(1).value).to.equal(1);
				expect(seq.at(2).value).to.equal(2);
				expect(seq.at(3)).to.be.null;
				seq.dispose();
			});

			it ("can set the value of an existing event with 'at'", function(){
				var seq = new Sequence(function(){}, [0, 1, 2]);
				expect(seq.length).to.equal(3);
				expect(seq.at(0).value).to.equal(0);
				expect(seq.at(0, 1).value).to.equal(1);
				expect(seq.at(0).value).to.equal(1);
				seq.dispose();
			});

			it ("can remove an event by index", function(){
				var seq = new Sequence(function(){}, [0, 1, 2]);
				expect(seq.length).to.equal(3);
				seq.remove(0);
				expect(seq.length).to.equal(2);
				seq.dispose();
			});


			it ("can add and retrieve a subSequence with 'at'", function(){
				var seq = new Sequence(function(){}, [0, 1, 2]);
				expect(seq.length).to.equal(3);
				expect(seq.at(1, [0, 1])).to.be.instanceof(Sequence);
				expect(seq.at(1).at(0).value).to.equal(0);
				expect(seq.at(1).at(1).value).to.equal(1);
				expect(seq.at(1).at(1, [0, 1])).to.be.instanceof(Sequence);
				expect(seq.at(1).at(1).at(1).value).to.equal(1);
				seq.dispose();
			});

			it("can add another seq", function(){
				var seq = new Sequence();
				expect(seq.length).to.equal(0);
				var subSequence = new Sequence({
					"events" : [0, 0.5]
				});
				seq.add(0, subSequence);
				expect(seq.length).to.equal(1);
				expect(seq.at(0)).to.equal(subSequence);
				seq.dispose();
			});

			it("can remove all of the events", function(){
				var seq = new Sequence(function(){}, [0, 1, 2, 3, 4, 5]);
				expect(seq.length).to.equal(6);
				seq.removeAll();
				expect(seq.length).to.equal(0);
				seq.dispose();
			});
		
		});
		context("Sequence callback", function(){

			afterEach(resetTransport);

			it ("invokes the callback after it's started", function(done){
				var seq = new Sequence(function(){
					seq.dispose();
					done();
				}, [0, 1]).start(0);
				Tone.Transport.start();
			});

			it ("passes in the scheduled time to the callback", function(done){
				var now = Tone.Transport.now();
				var seq = new Sequence(function(time){
					expect(time).to.be.a.number;
					expect(time - now).to.be.closeTo(0.3, 0.01);
					seq.dispose();
					done();
				}, [0.5]);
				seq.start(0.3);
				Tone.Transport.start();
			});

			it ("passes in the value to the callback", function(done){
				var seq = new Sequence(function(time, thing){
					expect(time).to.be.a.number;
					expect(thing).to.equal("thing");
					seq.dispose();
					done();<commit_msg>scheduling sequence test in the future<commit_after>define(["helper/Basic", "Tone/event/Sequence", "Tone/core/Tone", 
	"Tone/core/Transport", "Tone/event/Event", "helper/Offline2"], 
	function (Basic, Sequence, Tone, Transport, Event, Offline) {

	describe("Sequence", function(){

		Basic(Sequence);

		function resetTransport(done){
			Tone.Transport.cancel(0);
			Tone.Transport.off("start stop pause loop");
			Tone.Transport.stop();
			Tone.Transport.loop = false;
			Tone.Transport.PPQ = 48;
			Tone.Transport.bpm.value = 120;
			Tone.Transport.timeSignature = [4, 4];
			setTimeout(done, 200);
		}

		context("Constructor", function(){

			afterEach(resetTransport);

			it ("takes a callback and a sequence of values", function(){
				var callback = function(){};
				var seq = new Sequence(callback, [0, 1, 2]);
				expect(seq.callback).to.equal(callback);
				expect(seq.length).to.equal(3);
				seq.dispose();
			});

			it ("takes a callback and a sequence of values and a subdivision", function(){
				var callback = function(){};
				var seq = new Sequence(callback, [0, 1, 2], "2n");
				expect(seq.callback).to.equal(callback);
				expect(seq.subdivision).to.equal("2n");
				expect(seq.length).to.equal(3);
				seq.dispose();
			});

			it ("can be constructed with no arguments", function(){
				var seq = new Sequence();
				expect(seq.length).to.equal(0);
				seq.dispose();
			});

			it ("can pass in arguments in options object", function(){
				var callback = function(){};
				var seq = new Sequence({
					"callback" : callback,
					"humanize" : true,
					"events" : [0, 1, 2],
					"loop" : true,
					"loopEnd" : "4n",
					"probability" : 0.3
				});
				expect(seq.callback).to.equal(callback);
				expect(seq.length).to.equal(3);
				expect(seq.loop).to.be.true;
				expect(seq.loopEnd).to.equal("4n");
				expect(seq.probability).to.equal(0.3);
				expect(seq.humanize).to.be.true;
				seq.dispose();
			});

			it ("loops by default with the loopEnd as the duration of the loop", function(){
				var seq = new Sequence(function(){

				}, [0, 1, 2, 3], "8n");
				expect(seq.loop).to.be.true;
				expect(seq.length).to.equal(4);
				expect(seq.loopEnd).to.equal("2n");
				seq.dispose();
			});
		});

		context("Adding / Removing / Getting Events", function(){

			it("can add an event using the index", function(){
				var seq = new Sequence();
				seq.add(0, 0);
				expect(seq.length).to.equal(1);
				seq.add(1, 1);
				expect(seq.length).to.equal(2);
				seq.dispose();
			});

			it("can add a subsequence", function(){
				var seq = new Sequence();
				seq.add(0, [0, 1, 2]);
				expect(seq.length).to.equal(1);
				seq.dispose();
			});

			it ("can retrieve an event using 'at' and the index", function(){
				var seq = new Sequence(function(){}, [0, 1, 2]);
				expect(seq.length).to.equal(3);
				expect(seq.at(0)).to.be.instanceof(Event);
				expect(seq.at(0).value).to.equal(0);
				expect(seq.at(1).value).to.equal(1);
				expect(seq.at(2).value).to.equal(2);
				expect(seq.at(3)).to.be.null;
				seq.dispose();
			});

			it ("can set the value of an existing event with 'at'", function(){
				var seq = new Sequence(function(){}, [0, 1, 2]);
				expect(seq.length).to.equal(3);
				expect(seq.at(0).value).to.equal(0);
				expect(seq.at(0, 1).value).to.equal(1);
				expect(seq.at(0).value).to.equal(1);
				seq.dispose();
			});

			it ("can remove an event by index", function(){
				var seq = new Sequence(function(){}, [0, 1, 2]);
				expect(seq.length).to.equal(3);
				seq.remove(0);
				expect(seq.length).to.equal(2);
				seq.dispose();
			});


			it ("can add and retrieve a subSequence with 'at'", function(){
				var seq = new Sequence(function(){}, [0, 1, 2]);
				expect(seq.length).to.equal(3);
				expect(seq.at(1, [0, 1])).to.be.instanceof(Sequence);
				expect(seq.at(1).at(0).value).to.equal(0);
				expect(seq.at(1).at(1).value).to.equal(1);
				expect(seq.at(1).at(1, [0, 1])).to.be.instanceof(Sequence);
				expect(seq.at(1).at(1).at(1).value).to.equal(1);
				seq.dispose();
			});

			it("can add another seq", function(){
				var seq = new Sequence();
				expect(seq.length).to.equal(0);
				var subSequence = new Sequence({
					"events" : [0, 0.5]
				});
				seq.add(0, subSequence);
				expect(seq.length).to.equal(1);
				expect(seq.at(0)).to.equal(subSequence);
				seq.dispose();
			});

			it("can remove all of the events", function(){
				var seq = new Sequence(function(){}, [0, 1, 2, 3, 4, 5]);
				expect(seq.length).to.equal(6);
				seq.removeAll();
				expect(seq.length).to.equal(0);
				seq.dispose();
			});
		
		});
		context("Sequence callback", function(){

			afterEach(resetTransport);

			it ("invokes the callback after it's started", function(done){
				var seq = new Sequence(function(){
					seq.dispose();
					done();
				}, [0, 1]).start(0);
				Tone.Transport.start();
			});

			it ("passes in the scheduled time to the callback", function(done){
				var now = Tone.Transport.now() + 0.1;
				var seq = new Sequence(function(time){
					expect(time).to.be.a.number;
					expect(time - now).to.be.closeTo(0.3, 0.01);
					seq.dispose();
					done();
				}, [0.5]);
				seq.start(0.3);
				Tone.Transport.start(now);
			});

			it ("passes in the value to the callback", function(done){
				var seq = new Sequence(function(time, thing){
					expect(time).to.be.a.number;
					expect(thing).to.equal("thing");
					seq.dispose();
					done();
{'fraction_non_alphanumeric': 0.19786489968709736, 'fraction_numerical': 0.023743787962451683, 'mean_word_length': 3.1524646541841803, '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': '7184297', 'n_tokens_mistral': 4808, 'n_tokens_neox': 3767, 'n_words': 827}