Merge pull request from thisandagain/testing

Test Suite Adjustments
This commit is contained in:
Shane M. Clements 2014-04-10 14:46:21 -06:00
commit fa42953d58
25 changed files with 1195 additions and 1133 deletions

26
.jscsrc Normal file
View file

@ -0,0 +1,26 @@
{
"requireCurlyBraces": [
"for",
"while",
"do",
"try",
"catch"
],
"requireSpaceAfterKeywords": [
"default"
],
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowEmptyBlocks": true,
"disallowSpaceAfterObjectKeys": true,
"requireCommaBeforeLineBreak": true,
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
"validateIndentation": 4,
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"safeContextKeyword": "self"
}

View file

@ -28,41 +28,18 @@ The tests are written using Karma and there should be a 100% passing rate in ord
The expectation is to add a unit test for any code that you contribute to the project. The expectation is to add a unit test for any code that you contribute to the project.
Install Node (NPM) (https://npmjs.org/) Install Node
--------------------------------------- ---------------------------------------
Brew:
```
$ brew install npm
```
Mac Ports:
```
$ port install npm
```
In your local scratch directory To install [Node.js](http://nodejs.org) and [NPM](http://npmjs.org) simply go to [http://nodejs.org](http://nodejs.org/), download the package for your operating system and install. Once installed, navigate to your local scratch directory and run:
``` ```bash
$ npm install npm install
```
Local copy of jQuery
--------------------
```
$ cd test/lib
$ curl http://code.jquery.com/jquery-1.11.0.min.js > jquery-1.11.0.min.js
``` ```
To Run the tests To Run the tests
---------------- ----------------
``` ```bash
$ ./scripts/test.sh npm test
``` ```
To configure the unit tests
---------------------------
The karam.conf.js file is location in the config directory

View file

@ -37,12 +37,12 @@ var IO = function() {
}; };
IO.prototype.loadProject = function(project_id) { IO.prototype.loadProject = function(project_id) {
var runningIO = this; var self = this;
$.getJSON(this.project_base + project_id + this.project_suffix, function(data) { $.getJSON(this.project_base + project_id + this.project_suffix, function(data) {
runningIO.data = data; self.data = data;
runningIO.makeObjects(); self.makeObjects();
runningIO.loadThreads(); self.loadThreads();
runningIO.loadNotesDrums(); self.loadNotesDrums();
runtime.loadStart(); // Try to run the project. runtime.loadStart(); // Try to run the project.
}); });
}; };
@ -126,8 +126,8 @@ IO.prototype.makeObjects = function() {
$.each(this.data.children, function(index, obj) { $.each(this.data.children, function(index, obj) {
createObj(obj, runtime.stage); // create children of stage - sprites, watchers, and stage's lists createObj(obj, runtime.stage); // create children of stage - sprites, watchers, and stage's lists
}); });
$.each(runtime.sprites.filter(function(sprite){return sprite instanceof Sprite}), function(index, sprite) { // list of sprites $.each(runtime.sprites.filter(function(sprite) {return sprite instanceof Sprite}), function(index, sprite) { // list of sprites
$.each(sprite.lists, function(index, list){ $.each(sprite.lists, function(index, list) {
createObj(list, sprite); // create local lists createObj(list, sprite); // create local lists
}); });
}); });

View file

@ -136,7 +136,7 @@ Interpreter.prototype.stepActiveThread = function() {
if (b == null) return; if (b == null) return;
this.yield = false; this.yield = false;
while (true) { while (true) {
if (this.activeThread.paused) return; if (this.activeThread.paused) return;
++this.opCount; ++this.opCount;
// Advance the "program counter" to the next block before running the primitive. // Advance the "program counter" to the next block before running the primitive.
@ -319,8 +319,11 @@ Interpreter.prototype.lookupPrim = function(op) {
Interpreter.prototype.primNoop = function(b) { console.log(b.op); }; Interpreter.prototype.primNoop = function(b) { console.log(b.op); };
Interpreter.prototype.primWait = function(b) { Interpreter.prototype.primWait = function(b) {
if (interp.activeThread.firstTime) interp.startTimer(interp.numarg(b, 0)); if (interp.activeThread.firstTime) {
else interp.checkTimer(); interp.startTimer(interp.numarg(b, 0));
} else {
interp.checkTimer();
}
}; };
Interpreter.prototype.primRepeat = function(b) { Interpreter.prototype.primRepeat = function(b) {
@ -348,7 +351,9 @@ Interpreter.prototype.broadcast = function(b, waitFlag) {
} }
} }
runtime.allStacksDo(findReceivers); runtime.allStacksDo(findReceivers);
for (pair in receivers) interp.restartThread(receivers[pair][0], receivers[pair][1]); for (pair in receivers) {
interp.restartThread(receivers[pair][0], receivers[pair][1]);
}
if (!waitFlag) return; if (!waitFlag) return;
interp.activeThread.tmpObj = receivers; interp.activeThread.tmpObj = receivers;
interp.activeThread.firstTime = false; interp.activeThread.firstTime = false;

View file

@ -38,13 +38,9 @@ var Reporter = function(data) {
}; };
Reporter.prototype.determineReporterLabel = function() { Reporter.prototype.determineReporterLabel = function() {
if (this.target === 'Stage' && this.cmd === "getVar:") { if (this.target === 'Stage' && this.cmd === "getVar:") return this.param;
return this.param; if (this.target === 'Stage' && this.param === null) return this.cmd;
} else if (this.target === 'Stage' && this.param === null) {
return this.cmd;
} else {
return this.target + ': ' + this.param; return this.target + ': ' + this.param;
}
} }
Reporter.prototype.attach = function(scene) { Reporter.prototype.attach = function(scene) {
@ -164,10 +160,10 @@ List.prototype.attach = function(scene) {
var c = this.containerEl = $('<div style="overflow:hidden;float:left;position:relative">').appendTo(this.el).width(this.width-13).height(this.height-34); var c = this.containerEl = $('<div style="overflow:hidden;float:left;position:relative">').appendTo(this.el).width(this.width-13).height(this.height-34);
var s = this.scrollbar = $('<div class="list-scrollbar-container"><div class="list-scrollbar">').appendTo(this.el); var s = this.scrollbar = $('<div class="list-scrollbar-container"><div class="list-scrollbar">').appendTo(this.el);
var sb = s.children('.list-scrollbar'); var sb = s.children('.list-scrollbar');
sb.mousedown(function(e){ sb.mousedown(function(e) {
if (e.which===1) $(this).data({scrolling:true,startY:e.pageY}); // left button if (e.which===1) $(this).data({scrolling:true,startY:e.pageY}); // left button
}); });
$('body').mousemove(function(e){ $('body').mousemove(function(e) {
if (sb.data('scrolling')) { if (sb.data('scrolling')) {
var offset = parseInt(sb.css('top'))+e.pageY-sb.data('startY'); var offset = parseInt(sb.css('top'))+e.pageY-sb.data('startY');
if (offset < 0) { if (offset < 0) {
@ -179,7 +175,7 @@ List.prototype.attach = function(scene) {
sb.css('top',offset); sb.css('top',offset);
c.scrollTop(c.height()/sb.height()*offset); c.scrollTop(c.height()/sb.height()*offset);
} }
}).mouseup(function(){ }).mouseup(function() {
if ($.hasData(sb[0],'scrolling')) sb.removeData(['scrolling','startY']); if ($.hasData(sb[0],'scrolling')) sb.removeData(['scrolling','startY']);
}); });
// this.el.append('<div class="list-add">+'); // disabled because it doesn't do anything even in the original // this.el.append('<div class="list-add">+'); // disabled because it doesn't do anything even in the original
@ -194,14 +190,14 @@ List.prototype.attach = function(scene) {
this.el.css('display', this.visible ? 'inline-block' : 'none'); this.el.css('display', this.visible ? 'inline-block' : 'none');
}; };
List.prototype.update = function(){ List.prototype.update = function() {
this.contents = findList(runtime.spriteNamed(this.target),this.listName); this.contents = findList(runtime.spriteNamed(this.target),this.listName);
this.el.css('display', this.visible ? 'inline-block' : 'none'); this.el.css('display', this.visible ? 'inline-block' : 'none');
if (!this.visible) return; if (!this.visible) return;
var c = this.containerEl.html(''); // so that it can be used inside the forEach var c = this.containerEl.html(''); // so that it can be used inside the forEach
this.contents.forEach(function(val,i){ this.contents.forEach(function(val,i) {
$('<div style="clear:both">').appendTo(c).append('<div class="list-index">'+(i+1),'<div class="list-item">'+val); $('<div style="clear:both">').appendTo(c).append('<div class="list-index">'+(i+1),'<div class="list-item">'+val);
}); });
c.find('.list-index').width(c.find('.list-index').last().width()); c.find('.list-index').width(c.find('.list-index').last().width());

View file

@ -42,11 +42,11 @@ Runtime.prototype.init = function() {
this.scene = $('#container'); this.scene = $('#container');
window.AudioContext = window.AudioContext || window.webkitAudioContext; window.AudioContext = window.AudioContext || window.webkitAudioContext;
this.audioContext = new AudioContext(); this.audioContext = new AudioContext();
try{ try {
this.audioGain = this.audioContext.createGain(); this.audioGain = this.audioContext.createGain();
}catch(err){ } catch(err) {
this.audioGain = this.audioContext.createGainNode(); this.audioGain = this.audioContext.createGainNode();
} }
this.audioGain.connect(runtime.audioContext.destination); this.audioGain.connect(runtime.audioContext.destination);
}; };
@ -120,7 +120,7 @@ Runtime.prototype.allStacksDo = function(f) {
} }
} }
$.each(stage.stacks, function(index, stack) { $.each(stage.stacks, function(index, stack) {
f(stack, stage); f(stack, stage);
}); });
}; };

View file

@ -129,14 +129,14 @@ Sprite.prototype.attach = function(scene) {
$(sprite.textures[c]).css('display', sprite.currentCostumeIndex == c ? 'inline' : 'none'); $(sprite.textures[c]).css('display', sprite.currentCostumeIndex == c ? 'inline' : 'none');
$(sprite.textures[c]).css('position', 'absolute').css('left', '0px').css('top', '0px'); $(sprite.textures[c]).css('position', 'absolute').css('left', '0px').css('top', '0px');
$(sprite.textures[c]).bind('dragstart', function(evt) { evt.preventDefault(); }) $(sprite.textures[c]).bind('dragstart', function(evt) { evt.preventDefault(); })
.bind('selectstart', function(evt) { evt.preventDefault(); }) .bind('selectstart', function(evt) { evt.preventDefault(); })
.bind('touchend', function(evt) { sprite.onClick(evt); $(this).addClass('touched'); }) .bind('touchend', function(evt) { sprite.onClick(evt); $(this).addClass('touched'); })
.click(function(evt) { .click(function(evt) {
if (!$(this).hasClass('touched')) { if (!$(this).hasClass('touched')) {
sprite.onClick(evt); sprite.onClick(evt);
} else { } else {
$(this).removeClass('touched'); $(this).removeClass('touched');
} }
}); });
scene.append($(sprite.textures[c])); scene.append($(sprite.textures[c]));
}) })
@ -149,12 +149,12 @@ Sprite.prototype.attach = function(scene) {
this.updateTransform(); this.updateTransform();
if (! this.isStage) { if (! this.isStage) {
this.talkBubble = $('<div class="bubble-container"></div>'); this.talkBubble = $('<div class="bubble-container"></div>');
this.talkBubble.css('display', 'none'); this.talkBubble.css('display', 'none');
this.talkBubbleBox = $('<div class="bubble"></div>'); this.talkBubbleBox = $('<div class="bubble"></div>');
this.talkBubbleStyler = $('<div class="bubble-say"></div>'); this.talkBubbleStyler = $('<div class="bubble-say"></div>');
this.talkBubble.append(this.talkBubbleBox); this.talkBubble.append(this.talkBubbleBox);
this.talkBubble.append(this.talkBubbleStyler); this.talkBubble.append(this.talkBubbleStyler);
} }
this.askInput = $('<div class="ask-container"></div>'); this.askInput = $('<div class="ask-container"></div>');
@ -173,9 +173,9 @@ Sprite.prototype.attach = function(scene) {
// Load sounds from the server and buffer them // Load sounds from the server and buffer them
Sprite.prototype.loadSounds = function() { Sprite.prototype.loadSounds = function() {
var spr = this; var self = this;
$.each(this.sounds, function(index, sound) { $.each(this.sounds, function(index, sound) {
io.soundRequest(sound, spr); io.soundRequest(sound, self);
}); });
}; };
@ -273,8 +273,8 @@ Sprite.prototype.onClick = function(evt) {
}; };
Sprite.prototype.setVisible = function(v) { Sprite.prototype.setVisible = function(v) {
this.visible = v; this.visible = v;
this.updateVisible(); this.updateVisible();
}; };
Sprite.prototype.updateLayer = function() { Sprite.prototype.updateLayer = function() {
@ -308,21 +308,27 @@ Sprite.prototype.updateTransform = function() {
// sign to the X scale. // sign to the X scale.
} }
$(this.mesh).css('transform', $(this.mesh).css(
'translatex(' + drawX + 'px) \ 'transform',
translatey(' + drawY + 'px) \ 'translatex(' + drawX + 'px) ' +
rotate(' + this.rotation + 'deg) \ 'translatey(' + drawY + 'px) ' +
scaleX(' + scaleXprepend + (this.scale / resolution) + ') scaleY(' + (this.scale / resolution) + ')'); 'rotate(' + this.rotation + 'deg) ' +
$(this.mesh).css('-moz-transform', 'scaleX(' + scaleXprepend + (this.scale / resolution) + ') scaleY(' + (this.scale / resolution) + ')'
'translatex(' + drawX + 'px) \ );
translatey(' + drawY + 'px) \ $(this.mesh).css(
rotate(' + this.rotation + 'deg) \ '-moz-transform',
scaleX(' + scaleXprepend + this.scale + ') scaleY(' + this.scale / resolution + ')'); 'translatex(' + drawX + 'px) ' +
$(this.mesh).css('-webkit-transform', 'translatey(' + drawY + 'px) ' +
'translatex(' + drawX + 'px) \ 'rotate(' + this.rotation + 'deg) ' +
translatey(' + drawY + 'px) \ 'scaleX(' + scaleXprepend + this.scale + ') scaleY(' + this.scale / resolution + ')'
rotate(' + this.rotation + 'deg) \ );
scaleX(' + scaleXprepend + (this.scale / resolution) + ') scaleY(' + (this.scale / resolution) + ')'); $(this.mesh).css(
'-webkit-transform',
'translatex(' + drawX + 'px) ' +
'translatey(' + drawY + 'px) ' +
'rotate(' + this.rotation + 'deg) ' +
'scaleX(' + scaleXprepend + (this.scale / resolution) + ') scaleY(' + (this.scale / resolution) + ')'
);
$(this.mesh).css('-webkit-transform-origin', rotationCenterX + 'px ' + rotationCenterY + 'px'); $(this.mesh).css('-webkit-transform-origin', rotationCenterX + 'px ' + rotationCenterY + 'px');
$(this.mesh).css('-moz-transform-origin', rotationCenterX + 'px ' + rotationCenterY + 'px'); $(this.mesh).css('-moz-transform-origin', rotationCenterX + 'px ' + rotationCenterY + 'px');
@ -342,9 +348,11 @@ Sprite.prototype.updateTransform = function() {
Sprite.prototype.updateFilters = function() { Sprite.prototype.updateFilters = function() {
$(this.mesh).css('opacity', 1 - this.filters.ghost / 100); $(this.mesh).css('opacity', 1 - this.filters.ghost / 100);
$(this.mesh).css('-webkit-filter', $(this.mesh).css(
'hue-rotate(' + (this.filters.color * 1.8) + 'deg) \ '-webkit-filter',
brightness(' + (this.filters.brightness < 0 ? this.filters.brightness / 100 + 1 : Math.min(2.5, this.filters.brightness * .015 + 1)) + ')'); 'hue-rotate(' + (this.filters.color * 1.8) + 'deg) ' +
'brightness(' + (this.filters.brightness < 0 ? this.filters.brightness / 100 + 1 : Math.min(2.5, this.filters.brightness * .015 + 1)) + ')'
);
}; };
Sprite.prototype.getTalkBubbleXY = function() { Sprite.prototype.getTalkBubbleXY = function() {
@ -368,7 +376,7 @@ Sprite.prototype.showBubble = function(text, type) {
this.talkBubbleBox.removeClass('say-think-border'); this.talkBubbleBox.removeClass('say-think-border');
this.talkBubbleBox.removeClass('ask-border'); this.talkBubbleBox.removeClass('ask-border');
this.talkBubbleStyler.removeClass('bubble-say'); this.talkBubbleStyler.removeClass('bubble-say');
this.talkBubbleStyler.removeClass('bubble-think'); this.talkBubbleStyler.removeClass('bubble-think');
this.talkBubbleStyler.removeClass('bubble-ask'); this.talkBubbleStyler.removeClass('bubble-ask');
@ -415,17 +423,17 @@ Sprite.prototype.hideAsk = function() {
}; };
Sprite.prototype.bindDoAskButton = function() { Sprite.prototype.bindDoAskButton = function() {
var self = this; var self = this;
this.askInputButton.on("keypress click", function(e){ this.askInputButton.on("keypress click", function(e) {
var eType = e.type; var eType = e.type;
if (eType === 'click' || (eType === 'keypress' && e.which === 13)) { if (eType === 'click' || (eType === 'keypress' && e.which === 13)) {
var stage = interp.targetStage(); var stage = interp.targetStage();
stage.askAnswer = $(self.askInputTextField).val(); stage.askAnswer = $(self.askInputTextField).val();
self.hideBubble(); self.hideBubble();
self.hideAsk(); self.hideAsk();
interp.activeThread.paused = false; interp.activeThread.paused = false;
} }
}); });
}; };
Sprite.prototype.setXY = function(x, y) { Sprite.prototype.setXY = function(x, y) {

View file

@ -33,7 +33,7 @@ SensingPrims.prototype.addPrimsTo = function(primTable) {
primTable['getAttribute:of:'] = this.primGetAttribute; primTable['getAttribute:of:'] = this.primGetAttribute;
primTable['timeAndDate'] = function(b){ return runtime.getTimeString(interp.arg(b, 0)); }; primTable['timeAndDate'] = function(b) { return runtime.getTimeString(interp.arg(b, 0)); };
primTable['timestamp'] = this.primTimestamp; primTable['timestamp'] = this.primTimestamp;
}; };
@ -181,8 +181,8 @@ SensingPrims.prototype.primDoAsk= function(b) {
showBubble(b, "doAsk"); showBubble(b, "doAsk");
var s = interp.targetSprite(); var s = interp.targetSprite();
if (s !== null) { if (s !== null) {
interp.activeThread.paused = true; interp.activeThread.paused = true;
s.showAsk(); s.showAsk();
} }
}; };

View file

@ -109,8 +109,8 @@ function findList(targetSprite, listName) {
VarListPrims.prototype.primReadList = function(b) { VarListPrims.prototype.primReadList = function(b) {
var list = findList(interp.targetSprite(), interp.arg(b, 0)); var list = findList(interp.targetSprite(), interp.arg(b, 0));
if (list) { if (list) {
var allOne = list.map(function(val) { return val.length; }).reduce(function(old,val) { return old + val; }, 0) === list.length; var allOne = list.map(function(val) { return val.length; }).reduce(function(old,val) { return old + val; }, 0) === list.length;
return list.join(allOne ? '' : ' '); return list.join(allOne ? '' : ' ');
} }
}; };
@ -123,9 +123,13 @@ VarListPrims.prototype.primListDeleteLine = function(b) {
var list = findList(interp.targetSprite(), interp.arg(b, 1)); var list = findList(interp.targetSprite(), interp.arg(b, 1));
if (!list) return; if (!list) return;
var line = interp.arg(b, 0); var line = interp.arg(b, 0);
if (line == 'all' || list.length == 0) list.length = 0; if (line == 'all' || list.length == 0) {
else if (line == 'last') list.splice(list.length - 1, 1); list.length = 0;
else if (parseInt(line, 10) - 1 in list) list.splice(parseInt(line, 10) - 1, 1); } else if (line == 'last') {
list.splice(list.length - 1, 1);
} else if (parseInt(line, 10) - 1 in list) {
list.splice(parseInt(line, 10) - 1, 1);
}
}; };
VarListPrims.prototype.primListInsertAt = function(b) { VarListPrims.prototype.primListInsertAt = function(b) {
@ -134,9 +138,13 @@ VarListPrims.prototype.primListInsertAt = function(b) {
var newItem = interp.arg(b, 0); var newItem = interp.arg(b, 0);
var position = interp.arg(b, 1); var position = interp.arg(b, 1);
if (position == 'last') position = list.length; if (position == 'last') {
else if (position == 'random') position = Math.round(Math.random() * list.length); position = list.length;
else position = parseInt(position, 10) - 1; } else if (position == 'random') {
position = Math.round(Math.random() * list.length);
} else {
position = parseInt(position, 10) - 1;
}
if (position > list.length) return; if (position > list.length) return;
list.splice(position, 0, newItem); list.splice(position, 0, newItem);
@ -148,12 +156,15 @@ VarListPrims.prototype.primListSetLine = function(b) {
var newItem = interp.arg(b, 2); var newItem = interp.arg(b, 2);
var position = interp.arg(b, 0); var position = interp.arg(b, 0);
if (position == 'last') position = list.length - 1; if (position == 'last') {
else if (position == 'random') position = Math.floor(Math.random() * list.length); position = list.length - 1;
else position = parseInt(position, 10) - 1; } else if (position == 'random') {
position = Math.floor(Math.random() * list.length);
} else {
position = parseInt(position, 10) - 1;
}
if (position > list.length - 1) return; if (position > list.length - 1) return;
list[position] = newItem; list[position] = newItem;
}; };

View file

@ -27,21 +27,21 @@
var NotePlayer = function(wavFileData, originalPitch, loopStart, loopEnd, env) { var NotePlayer = function(wavFileData, originalPitch, loopStart, loopEnd, env) {
this.originalPitch = originalPitch || null; this.originalPitch = originalPitch || null;
this.index = 0; this.index = 0;
this.samplesRemaining = 0; // determines note duration this.samplesRemaining = 0; // determines note duration
// Looping // Looping
this.isLooped = false; this.isLooped = false;
this.loopPoint = 0; // final sample in loop this.loopPoint = 0; // final sample in loop
this.loopLength = 0; this.loopLength = 0;
// Volume Envelope // Volume Envelope
this.envelopeValue = 1; this.envelopeValue = 1;
this.samplesSinceStart = 0; this.samplesSinceStart = 0;
this.attackEnd = 0; this.attackEnd = 0;
this.attackRate = 0; this.attackRate = 0;
this.holdEnd = 0; this.holdEnd = 0;
this.decayRate = 1; this.decayRate = 1;
if (wavFileData == null) wavFileData = new ArrayBuffer(); if (wavFileData == null) wavFileData = new ArrayBuffer();
@ -107,8 +107,8 @@ NotePlayer.prototype.interpolatedSample = function() {
NotePlayer.prototype.rawSample = function(sampleIndex) { NotePlayer.prototype.rawSample = function(sampleIndex) {
if (sampleIndex >= this.endOffset) { if (sampleIndex >= this.endOffset) {
if (this.isLooped) sampleIndex = this.loopPoint; if (!this.isLooped) return 0;
else return 0; sampleIndex = this.loopPoint;
} }
var byteIndex = 2 * sampleIndex; var byteIndex = 2 * sampleIndex;
var result = (this.soundData[byteIndex + 1] << 8) + this.soundData[byteIndex]; var result = (this.soundData[byteIndex + 1] << 8) + this.soundData[byteIndex];

View file

@ -32,114 +32,136 @@ var SoundBank = function() {};
// The loop points are -1 if the sound is unlooped (e.g. Marimba). // The loop points are -1 if the sound is unlooped (e.g. Marimba).
// The three-element envelop array may be omitted if the instrument has no envelope. // The three-element envelop array may be omitted if the instrument has no envelope.
SoundBank.instruments = [ SoundBank.instruments = [
[[38, 'AcousticPiano_As3', 58, 10266, 17053, [0, 100, 22]], [
[44, 'AcousticPiano_C4', 60, 13968, 18975, [0, 100, 20]], [38, 'AcousticPiano_As3', 58, 10266, 17053, [0, 100, 22]],
[51, 'AcousticPiano_G4', 67, 12200, 12370, [0, 80, 18]], [44, 'AcousticPiano_C4', 60, 13968, 18975, [0, 100, 20]],
[62, 'AcousticPiano_C6', 84, 13042, 13276, [0, 80, 16]], [51, 'AcousticPiano_G4', 67, 12200, 12370, [0, 80, 18]],
[70, 'AcousticPiano_F5', 77, 12425, 12965, [0, 40, 14]], [62, 'AcousticPiano_C6', 84, 13042, 13276, [0, 80, 16]],
[77, 'AcousticPiano_Ds6', 87, 12368, 12869, [0, 20, 10]], [70, 'AcousticPiano_F5', 77, 12425, 12965, [0, 40, 14]],
[85, 'AcousticPiano_Ds6', 87, 12368, 12869, [0, 0, 8]], [77, 'AcousticPiano_Ds6', 87, 12368, 12869, [0, 20, 10]],
[90, 'AcousticPiano_Ds6', 87, 12368, 12869, [0, 0, 6]], [85, 'AcousticPiano_Ds6', 87, 12368, 12869, [0, 0, 8]],
[96, 'AcousticPiano_D7', 98, 7454, 7606, [0, 0, 3]], [90, 'AcousticPiano_Ds6', 87, 12368, 12869, [0, 0, 6]],
[128, 'AcousticPiano_D7', 98, 7454, 7606, [0, 0, 2]]], [96, 'AcousticPiano_D7', 98, 7454, 7606, [0, 0, 3]],
[128, 'AcousticPiano_D7', 98, 7454, 7606, [0, 0, 2]]
[[48, 'ElectricPiano_C2', 36, 15338, 17360, [0, 80, 10]], ],
[74, 'ElectricPiano_C4', 60, 11426, 12016, [0, 40, 8]], [
[128, 'ElectricPiano_C4', 60, 11426, 12016, [0, 0, 6]]], [48, 'ElectricPiano_C2', 36, 15338, 17360, [0, 80, 10]],
[74, 'ElectricPiano_C4', 60, 11426, 12016, [0, 40, 8]],
[[128, 'Organ_G2', 43, 1306, 3330]], [128, 'ElectricPiano_C4', 60, 11426, 12016, [0, 0, 6]]
],
[[40, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 15]], [
[56, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 13.5]], [128, 'Organ_G2', 43, 1306, 3330]
[60, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 12]], ],
[67, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 8.5]], [
[72, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 7]], [40, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 15]],
[83, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 5.5]], [56, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 13.5]],
[128, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 4.5]]], [60, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 12]],
[67, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 8.5]],
[[40, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 15]], [72, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 7]],
[56, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 13.5]], [83, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 5.5]],
[60, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 12]], [128, 'AcousticGuitar_F3', 53, 36665, 36791, [0, 0, 4.5]]
[67, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 8.5]], ],
[72, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 7]], [
[83, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 5.5]], [40, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 15]],
[128, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 4.5]]], [56, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 13.5]],
[60, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 12]],
[[34, 'ElectricBass_G1', 31, 41912, 42363, [0, 0, 17]], [67, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 8.5]],
[48, 'ElectricBass_G1', 31, 41912, 42363, [0, 0, 14]], [72, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 7]],
[64, 'ElectricBass_G1', 31, 41912, 42363, [0, 0, 12]], [83, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 5.5]],
[128, 'ElectricBass_G1', 31, 41912, 42363, [0, 0, 10]]], [128, 'ElectricGuitar_F3', 53, 34692, 34945, [0, 0, 4.5]]
],
[[38, 'Pizz_G2', 43, 8554, 8782, [0, 0, 5]], [
[45, 'Pizz_G2', 43, 8554, 8782, [0, 12, 4]], [34, 'ElectricBass_G1', 31, 41912, 42363, [0, 0, 17]],
[56, 'Pizz_A3', 57, 11460, 11659, [0, 0, 4]], [48, 'ElectricBass_G1', 31, 41912, 42363, [0, 0, 14]],
[64, 'Pizz_A3', 57, 11460, 11659, [0, 0, 3.2]], [64, 'ElectricBass_G1', 31, 41912, 42363, [0, 0, 12]],
[72, 'Pizz_E4', 64, 17525, 17592, [0, 0, 2.8]], [128, 'ElectricBass_G1', 31, 41912, 42363, [0, 0, 10]]
[80, 'Pizz_E4', 64, 17525, 17592, [0, 0, 2.2]], ],
[128, 'Pizz_E4', 64, 17525, 17592, [0, 0, 1.5]]], [
[38, 'Pizz_G2', 43, 8554, 8782, [0, 0, 5]],
[[41, 'Cello_C2', 36, 8548, 8885], [45, 'Pizz_G2', 43, 8554, 8782, [0, 12, 4]],
[52, 'Cello_As2', 46, 7465, 7845], [56, 'Pizz_A3', 57, 11460, 11659, [0, 0, 4]],
[62, 'Violin_D4', 62, 10608, 11360], [64, 'Pizz_A3', 57, 11460, 11659, [0, 0, 3.2]],
[75, 'Violin_A4', 69, 3111, 3314, [70, 0, 0]], [72, 'Pizz_E4', 64, 17525, 17592, [0, 0, 2.8]],
[128, 'Violin_E5', 76, 2383, 2484]], [80, 'Pizz_E4', 64, 17525, 17592, [0, 0, 2.2]],
[128, 'Pizz_E4', 64, 17525, 17592, [0, 0, 1.5]]
[[30, 'BassTrombone_A2_3', 45, 1357, 2360], ],
[40, 'BassTrombone_A2_2', 45, 1893, 2896], [
[55, 'Trombone_B3', 59, 2646, 3897], [41, 'Cello_C2', 36, 8548, 8885],
[88, 'Trombone_B3', 59, 2646, 3897, [50, 0, 0]], [52, 'Cello_As2', 46, 7465, 7845],
[128, 'Trumpet_E5', 76, 2884, 3152]], [62, 'Violin_D4', 62, 10608, 11360],
[75, 'Violin_A4', 69, 3111, 3314, [70, 0, 0]],
[[128, 'Clarinet_C4', 60, 14540, 15468]], [128, 'Violin_E5', 76, 2383, 2484]
],
[[40, 'TenorSax_C3', 48, 8939, 10794], [
[50, 'TenorSax_C3', 48, 8939, 10794, [20, 0, 0]], [30, 'BassTrombone_A2_3', 45, 1357, 2360],
[59, 'TenorSax_C3', 48, 8939, 10794, [40, 0, 0]], [40, 'BassTrombone_A2_2', 45, 1893, 2896],
[67, 'AltoSax_A3', 57, 8546, 9049], [55, 'Trombone_B3', 59, 2646, 3897],
[75, 'AltoSax_A3', 57, 8546, 9049, [20, 0, 0]], [88, 'Trombone_B3', 59, 2646, 3897, [50, 0, 0]],
[80, 'AltoSax_A3', 57, 8546, 9049, [20, 0, 0]], [128, 'Trumpet_E5', 76, 2884, 3152]
[128, 'AltoSax_C6', 84, 1258, 1848]], ],
[
[[61, 'Flute_B5_2', 83, 1859, 2259], [128, 'Clarinet_C4', 60, 14540, 15468]
[128, 'Flute_B5_1', 83, 2418, 2818]], ],
[
[[128, 'WoodenFlute_C5', 72, 11426, 15724]], [40, 'TenorSax_C3', 48, 8939, 10794],
[50, 'TenorSax_C3', 48, 8939, 10794, [20, 0, 0]],
[[57, 'Bassoon_C3', 48, 2428, 4284], [59, 'TenorSax_C3', 48, 8939, 10794, [40, 0, 0]],
[67, 'Bassoon_C3', 48, 2428, 4284, [40, 0, 0]], [67, 'AltoSax_A3', 57, 8546, 9049],
[76, 'Bassoon_C3', 48, 2428, 4284, [80, 0, 0]], [75, 'AltoSax_A3', 57, 8546, 9049, [20, 0, 0]],
[84, 'EnglishHorn_F3', 53, 7538, 8930, [40, 0, 0]], [80, 'AltoSax_A3', 57, 8546, 9049, [20, 0, 0]],
[128, 'EnglishHorn_D4', 62, 4857, 5231]], [128, 'AltoSax_C6', 84, 1258, 1848]
],
[[39, 'Choir_F3', 53, 14007, 41281], [
[50, 'Choir_F3', 53, 14007, 41281, [40, 0, 0]], [61, 'Flute_B5_2', 83, 1859, 2259],
[61, 'Choir_F3', 53, 14007, 41281, [60, 0, 0]], [128, 'Flute_B5_1', 83, 2418, 2818]
[72, 'Choir_F4', 65, 16351, 46436], ],
[128, 'Choir_F5', 77, 18440, 45391]], [
[128, 'WoodenFlute_C5', 72, 11426, 15724]
[[38, 'Vibraphone_C3', 48, 6202, 6370, [0, 100, 8]], ],
[48, 'Vibraphone_C3', 48, 6202, 6370, [0, 100, 7.5]], [
[59, 'Vibraphone_C3', 48, 6202, 6370, [0, 60, 7]], [57, 'Bassoon_C3', 48, 2428, 4284],
[70, 'Vibraphone_C3', 48, 6202, 6370, [0, 40, 6]], [67, 'Bassoon_C3', 48, 2428, 4284, [40, 0, 0]],
[78, 'Vibraphone_C3', 48, 6202, 6370, [0, 20, 5]], [76, 'Bassoon_C3', 48, 2428, 4284, [80, 0, 0]],
[86, 'Vibraphone_C3', 48, 6202, 6370, [0, 0, 4]], [84, 'EnglishHorn_F3', 53, 7538, 8930, [40, 0, 0]],
[128, 'Vibraphone_C3', 48, 6202, 6370, [0, 0, 3]]], [128, 'EnglishHorn_D4', 62, 4857, 5231]
],
[[128, 'MusicBox_C4', 60, 14278, 14700, [0, 0, 2]]], [
[39, 'Choir_F3', 53, 14007, 41281],
[[128, 'SteelDrum_D5', 74.4, -1, -1, [0, 0, 2]]], [50, 'Choir_F3', 53, 14007, 41281, [40, 0, 0]],
[61, 'Choir_F3', 53, 14007, 41281, [60, 0, 0]],
[[128, 'Marimba_C4', 60, -1, -1]], [72, 'Choir_F4', 65, 16351, 46436],
[128, 'Choir_F5', 77, 18440, 45391]
[[80, 'SynthLead_C4', 60, 135, 1400], ],
[128, 'SynthLead_C6', 84, 124, 356]], [
[38, 'Vibraphone_C3', 48, 6202, 6370, [0, 100, 8]],
[[38, 'SynthPad_A3', 57, 4212, 88017, [50, 0, 0]], [48, 'Vibraphone_C3', 48, 6202, 6370, [0, 100, 7.5]],
[50, 'SynthPad_A3', 57, 4212, 88017, [80, 0, 0]], [59, 'Vibraphone_C3', 48, 6202, 6370, [0, 60, 7]],
[62, 'SynthPad_A3', 57, 4212, 88017, [110, 0, 0]], [70, 'Vibraphone_C3', 48, 6202, 6370, [0, 40, 6]],
[74, 'SynthPad_A3', 57, 4212, 88017, [150, 0, 0]], [78, 'Vibraphone_C3', 48, 6202, 6370, [0, 20, 5]],
[86, 'SynthPad_A3', 57, 4212, 88017, [200, 0, 0]], [86, 'Vibraphone_C3', 48, 6202, 6370, [0, 0, 4]],
[128, 'SynthPad_C6', 84, 2575, 9202]], [128, 'Vibraphone_C3', 48, 6202, 6370, [0, 0, 3]]
],
[
[128, 'MusicBox_C4', 60, 14278, 14700, [0, 0, 2]]
],
[
[128, 'SteelDrum_D5', 74.4, -1, -1, [0, 0, 2]]
],
[
[128, 'Marimba_C4', 60, -1, -1]
],
[
[80, 'SynthLead_C4', 60, 135, 1400],
[128, 'SynthLead_C6', 84, 124, 356]
],
[
[38, 'SynthPad_A3', 57, 4212, 88017, [50, 0, 0]],
[50, 'SynthPad_A3', 57, 4212, 88017, [80, 0, 0]],
[62, 'SynthPad_A3', 57, 4212, 88017, [110, 0, 0]],
[74, 'SynthPad_A3', 57, 4212, 88017, [150, 0, 0]],
[86, 'SynthPad_A3', 57, 4212, 88017, [200, 0, 0]],
[128, 'SynthPad_C6', 84, 2575, 9202]
]
]; ];
// ----------------------------- // -----------------------------

20
makefile Normal file
View file

@ -0,0 +1,20 @@
JSCS_PATH = ./node_modules/.bin/jscs
KARMA_PATH = ./node_modules/.bin/karma
KARMA_CONFIG = ./test/fixtures/karma.conf.js
# Performs code governance (lint + style) test
lint:
@$(JSCS_PATH) ./js/*
@$(JSCS_PATH) ./test/unit/*
# Performs unit tests
unit:
@$(KARMA_PATH) start $(KARMA_CONFIG) $*
# Run all test targets
test:
@make lint
@make unit
# Ignore directory structure
.PHONY: lint unit test

View file

@ -2,10 +2,19 @@
"name": "scratch-html5", "name": "scratch-html5",
"description": "HTML 5 based Scratch project player", "description": "HTML 5 based Scratch project player",
"repository": "https://github.com/LLK/scratch-html5", "repository": "https://github.com/LLK/scratch-html5",
"scripts": {
"postinstall": "curl http://code.jquery.com/jquery-1.11.0.min.js > ./test/lib/jquery-1.11.0.min.js",
"test": "make test"
},
"engines": {
"node": ">=0.10"
},
"dependencies": {},
"devDependencies": { "devDependencies": {
"karma" : "~0.10", "jasmine-jquery": "~1.3.3",
"jasmine-jquery" : "1.3.3", "jscs": "~1.3.0",
"karma-html2js-preprocessor" : "~0.1.0", "karma": "~0.10",
"underscore" : "~1.6.0" "karma-html2js-preprocessor": "~0.1.0",
"underscore": "~1.6.0"
} }
} }

View file

@ -1,9 +0,0 @@
#!/bin/bash
BASE_DIR=`dirname $0`
echo ""
echo "Starting Karma Server (http://karma-runner.github.io)"
echo "-------------------------------------------------------------------"
$BASE_DIR/../node_modules/karma/bin/karma start $BASE_DIR/../config/karma.conf.js $*

View file

@ -1,6 +1,6 @@
module.exports = function(config){ module.exports = function(config){
config.set({ config.set({
basePath : '../', basePath : '../../',
files : [ files : [
'test/artifacts/**/*.js', 'test/artifacts/**/*.js',

View file

@ -1,86 +1,86 @@
/* jasmine specs for Interpreter.js go here */ /* jasmine specs for Interpreter.js go here */
describe('Interpreter', function() { describe('Interpreter', function() {
var interp; var interp;
beforeEach(function() {
interp = Interpreter;
});
describe('Initialized variables', function() {
var initInterp, realThread, realTimer;
beforeEach(function() { beforeEach(function() {
realThread = Thread; interp = Interpreter;
realTimer = Timer;
Thread = threadMock;
Timer = function() {};
initInterp = new interp();
}); });
afterEach(function() { describe('Initialized variables', function() {
Thread = realThread; var initInterp, realThread, realTimer;
Timer = realTimer; beforeEach(function() {
realThread = Thread;
realTimer = Timer;
Thread = threadMock;
Timer = function() {};
initInterp = new interp();
});
afterEach(function() {
Thread = realThread;
Timer = realTimer;
});
describe('Interpreter Variables', function() {
it('should have a primitiveTable collection', function() {
expect(initInterp.primitiveTable).toEqual({});
});
it('should have a variables collection', function() {
expect(initInterp.variables).toEqual({});
});
it('should have a threads array', function() {
expect(initInterp.threads).toEqual([]);
});
it('should have an activeThread variable', function() {
expect(initInterp.activeThread).toEqual(threadMock());
});
it('should have a WorkTime variable', function() {
expect(initInterp.WorkTime).toBe(30);
});
it('should have a currentMSecs variable', function() {
expect(initInterp.currentMSecs).toBe(null);
});
it('should have a timer variable', function() {
expect(initInterp.timer).toEqual({});
});
it('should have a yield variable', function() {
expect(initInterp.yield).toBe(false);
});
it('should have a doRedraw variable', function() {
expect(initInterp.doRedraw).toBe(false);
});
it('should have an opCount variable', function() {
expect(initInterp.opCount).toBe(0);
});
it('should have a debugOps variable', function() {
expect(initInterp.debugOps).toBe(false);
});
it('should have a debugFunc variable', function() {
expect(initInterp.debugFunc).toBe(null);
});
it('should have an opCount2 variable', function() {
expect(initInterp.opCount2).toBe(0);
});
});
}); });
describe('Interpreter Variables', function() { describe('TargetStage', function() {
it('should have a primitiveTable collection', function() { it('should return the target.stage object', function() {
expect(initInterp.primitiveTable).toEqual({}); runtime = new runtimeMock();
}); expect(interp.prototype.targetStage()).toEqual(runtime.stage);
});
it('should have a variables collection', function() {
expect(initInterp.variables).toEqual({});
});
it('should have a threads array', function() {
expect(initInterp.threads).toEqual([]);
});
it('should have an activeThread variable', function() {
expect(initInterp.activeThread).toEqual(threadMock());
});
it('should have a WorkTime variable', function() {
expect(initInterp.WorkTime).toBe(30);
});
it('should have a currentMSecs variable', function() {
expect(initInterp.currentMSecs).toBe(null);
});
it('should have a timer variable', function() {
expect(initInterp.timer).toEqual({});
});
it('should have a yield variable', function() {
expect(initInterp.yield).toBe(false);
});
it('should have a doRedraw variable', function() {
expect(initInterp.doRedraw).toBe(false);
});
it('should have an opCount variable', function() {
expect(initInterp.opCount).toBe(0);
});
it('should have a debugOps variable', function() {
expect(initInterp.debugOps).toBe(false);
});
it('should have a debugFunc variable', function() {
expect(initInterp.debugFunc).toBe(null);
});
it('should have an opCount2 variable', function() {
expect(initInterp.opCount2).toBe(0);
});
}); });
});
describe('TargetStage', function() {
it('should return the target.stage object', function() {
runtime = new runtimeMock();
expect(interp.prototype.targetStage()).toEqual(runtime.stage);
});
});
}); });

View file

@ -2,42 +2,42 @@
/* jasmine specs for IO.js go here */ /* jasmine specs for IO.js go here */
describe('IO', function(){ describe('IO', function() {
var io; var io;
beforeEach(function() { beforeEach(function() {
io = new IO(); io = new IO();
}); });
it('should have "null" data', function() { it('should have "null" data', function() {
expect(io.data).toBe(null); expect(io.data).toBe(null);
}); });
it('should have a base', function() { it('should have a base', function() {
expect(io.base).toBe(io_base); expect(io.base).toBe(io_base);
}); });
it('should have a project_base', function() { it('should have a project_base', function() {
expect(io.project_base).toBe(project_base); expect(io.project_base).toBe(project_base);
}); });
it('should have a project_suffix', function() { it('should have a project_suffix', function() {
expect(io.project_suffix).toBe(project_suffix); expect(io.project_suffix).toBe(project_suffix);
}); });
it('should have an asset_base', function() { it('should have an asset_base', function() {
expect(io.asset_base).toBe(asset_base); expect(io.asset_base).toBe(asset_base);
}); });
it('should have an asset_suffix', function() { it('should have an asset_suffix', function() {
expect(io.asset_suffix).toBe(asset_suffix); expect(io.asset_suffix).toBe(asset_suffix);
}); });
it('should have an soundbank_base', function() { it('should have an soundbank_base', function() {
expect(io.soundbank_base).toBe(soundbank_base); expect(io.soundbank_base).toBe(soundbank_base);
}); });
it('should have a spriteLayerCount', function() { it('should have a spriteLayerCount', function() {
expect(io.spriteLayerCount).toBe(spriteLayerCount); expect(io.spriteLayerCount).toBe(spriteLayerCount);
}); });
}); });

View file

@ -1,51 +1,51 @@
/* jasmine specs for primitives/LooksPrims.js go here */ /* jasmine specs for primitives/LooksPrims.js go here */
describe('LooksPrims', function() { describe('LooksPrims', function() {
var looksPrims, targetSpriteMock; var looksPrims, targetSpriteMock;
beforeEach(function() {
looksPrims = LooksPrims;
targetSpriteMock = targetMock();
});
describe('showBubble for say', function(){
var sayBlock;
beforeEach(function() { beforeEach(function() {
sayBlock = {'args': ['what to say']}; looksPrims = LooksPrims;
interp = interpreterMock({'targetSprite': targetSpriteMock }, {'arg': sayBlock}); targetSpriteMock = targetMock();
}); });
it('should call the showBubble method on the targetedSprite', function() { describe('showBubble for say', function() {
spyOn(targetSpriteMock, "showBubble"); var sayBlock;
showBubble(sayBlock, "say"); beforeEach(function() {
expect(targetSpriteMock.showBubble).toHaveBeenCalledWith({args:['what to say']}, 'say'); sayBlock = {'args': ['what to say']};
}); interp = interpreterMock({'targetSprite': targetSpriteMock }, {'arg': sayBlock});
}); });
describe('showBubble for think', function(){ it('should call the showBubble method on the targetedSprite', function() {
var thinkBlock; spyOn(targetSpriteMock, "showBubble");
beforeEach(function() { showBubble(sayBlock, "say");
thinkBlock = {'args': ['what to think']}; expect(targetSpriteMock.showBubble).toHaveBeenCalledWith({args:['what to say']}, 'say');
interp = interpreterMock({'targetSprite': targetSpriteMock }, {'arg': thinkBlock}); });
}); });
it('should call the showBubble method on the targetedSprite', function() { describe('showBubble for think', function() {
spyOn(targetSpriteMock, "showBubble"); var thinkBlock;
showBubble(thinkBlock, "think"); beforeEach(function() {
expect(targetSpriteMock.showBubble).toHaveBeenCalledWith({args:['what to think']}, 'think'); thinkBlock = {'args': ['what to think']};
}); interp = interpreterMock({'targetSprite': targetSpriteMock }, {'arg': thinkBlock});
}); });
describe('showBubble for ask', function(){ it('should call the showBubble method on the targetedSprite', function() {
var askBlock; spyOn(targetSpriteMock, "showBubble");
beforeEach(function() { showBubble(thinkBlock, "think");
askBlock = {'args': ['what to ask']}; expect(targetSpriteMock.showBubble).toHaveBeenCalledWith({args:['what to think']}, 'think');
interp = interpreterMock({'targetSprite': targetSpriteMock }, {'arg': askBlock}); });
}); });
it('should call the showBubble method on the targetedSprite', function() { describe('showBubble for ask', function() {
spyOn(targetSpriteMock, "showBubble"); var askBlock;
showBubble(askBlock, "ask"); beforeEach(function() {
expect(targetSpriteMock.showBubble).toHaveBeenCalledWith({args:['what to ask']}, 'ask'); askBlock = {'args': ['what to ask']};
interp = interpreterMock({'targetSprite': targetSpriteMock }, {'arg': askBlock});
});
it('should call the showBubble method on the targetedSprite', function() {
spyOn(targetSpriteMock, "showBubble");
showBubble(askBlock, "ask");
expect(targetSpriteMock.showBubble).toHaveBeenCalledWith({args:['what to ask']}, 'ask');
});
}); });
});
}); });

View file

@ -1,108 +1,108 @@
/* jasmine specs for Reporter.js go here */ /* jasmine specs for Reporter.js go here */
describe('Reporter', function() { describe('Reporter', function() {
var reporter, reporterValues; var reporter, reporterValues;
beforeEach(function() {
reporter = Reporter;
reporterValues = new ReporterValues();
});
describe('Initialized variables', function() {
var initReporter;
beforeEach(function() { beforeEach(function() {
io = new ioMock({'getCount': 4}); reporter = Reporter;
initReporter = new reporter(reporterValues.getStageVariables()); reporterValues = new ReporterValues();
}); });
describe('Reporter Variables', function() { describe('Initialized variables', function() {
it('should have a cmd variable', function() { var initReporter;
expect(initReporter.cmd).toBe('getVar:'); beforeEach(function() {
}); io = new ioMock({'getCount': 4});
initReporter = new reporter(reporterValues.getStageVariables());
});
it('should have a color variable', function() { describe('Reporter Variables', function() {
expect(initReporter.color).toBe(15629590); it('should have a cmd variable', function() {
}); expect(initReporter.cmd).toBe('getVar:');
});
it('should have a isDiscrete variable', function() { it('should have a color variable', function() {
expect(initReporter.isDiscrete).toBe(true); expect(initReporter.color).toBe(15629590);
}); });
it('should have a mode variable', function() { it('should have a isDiscrete variable', function() {
expect(initReporter.mode).toBe(1); expect(initReporter.isDiscrete).toBe(true);
}); });
it('should have a param variable', function() { it('should have a mode variable', function() {
expect(initReporter.param).toBe('myAnswer'); expect(initReporter.mode).toBe(1);
}); });
it('should have a sliderMax variable', function() { it('should have a param variable', function() {
expect(initReporter.sliderMax).toBe(100); expect(initReporter.param).toBe('myAnswer');
}); });
it('should have a sliderMin variable', function() { it('should have a sliderMax variable', function() {
expect(initReporter.sliderMin).toBe(0); expect(initReporter.sliderMax).toBe(100);
}); });
it('should have a target variable', function() { it('should have a sliderMin variable', function() {
expect(initReporter.target).toBe('Stage'); expect(initReporter.sliderMin).toBe(0);
}); });
it('should have a visible variable', function() { it('should have a target variable', function() {
expect(initReporter.visible).toBe(true); expect(initReporter.target).toBe('Stage');
}); });
it('should have a x variable', function() { it('should have a visible variable', function() {
expect(initReporter.x).toBe(5); expect(initReporter.visible).toBe(true);
}); });
it('should have a y variable', function() { it('should have a x variable', function() {
expect(initReporter.y).toBe(5); expect(initReporter.x).toBe(5);
}); });
it('should have a z variable', function() { it('should have a y variable', function() {
expect(initReporter.z).toBe(4); expect(initReporter.y).toBe(5);
}); });
it('should have a label variable', function() { it('should have a z variable', function() {
expect(initReporter.label).toBe('myAnswer'); expect(initReporter.z).toBe(4);
}); });
it('should have an el variable', function() { it('should have a label variable', function() {
expect(initReporter.el).toBe(null); expect(initReporter.label).toBe('myAnswer');
}); });
it('should have an valueEl variable', function() { it('should have an el variable', function() {
expect(initReporter.valueEl).toBe(null); expect(initReporter.el).toBe(null);
}); });
it('should have an slider variable', function() { it('should have an valueEl variable', function() {
expect(initReporter.slider).toBe(null); expect(initReporter.valueEl).toBe(null);
}); });
});
});
describe('determineReporterLabel', function() { it('should have an slider variable', function() {
it('should return a stage variable', function() { expect(initReporter.slider).toBe(null);
reporter.prototype.target = "Stage"; });
reporter.prototype.param = "myAnswer"; });
reporter.prototype.cmd = "getVar:";
expect(reporter.prototype.determineReporterLabel()).toBe('myAnswer');
}); });
it('should return a sprite variable', function() { describe('determineReporterLabel', function() {
reporter.prototype.target = "Sprite 1"; it('should return a stage variable', function() {
reporter.prototype.param = "localAnswer"; reporter.prototype.target = "Stage";
reporter.prototype.cmd = "getVar:"; reporter.prototype.param = "myAnswer";
expect(reporter.prototype.determineReporterLabel()).toBe('Sprite 1: localAnswer'); reporter.prototype.cmd = "getVar:";
}); expect(reporter.prototype.determineReporterLabel()).toBe('myAnswer');
});
it('should return a stage answer variable', function() { it('should return a sprite variable', function() {
reporter.prototype.target = "Stage"; reporter.prototype.target = "Sprite 1";
reporter.prototype.param = null; reporter.prototype.param = "localAnswer";
reporter.prototype.cmd = "answer"; reporter.prototype.cmd = "getVar:";
expect(reporter.prototype.determineReporterLabel()).toBe('answer'); expect(reporter.prototype.determineReporterLabel()).toBe('Sprite 1: localAnswer');
}); });
}); it('should return a stage answer variable', function() {
reporter.prototype.target = "Stage";
reporter.prototype.param = null;
reporter.prototype.cmd = "answer";
expect(reporter.prototype.determineReporterLabel()).toBe('answer');
});
});
}); });

View file

@ -1,113 +1,113 @@
/* jasmine specs for Runtime.js go here */ /* jasmine specs for Runtime.js go here */
describe('Runtime', function() { describe('Runtime', function() {
var runtimeObj; var runtimeObj;
beforeEach(function() {
runtimeObj = Runtime;
});
describe('Initialized variables', function() {
var initRuntime, lineCanvas;
beforeEach(function() { beforeEach(function() {
initRuntime = new runtimeObj(); runtimeObj = Runtime;
}); });
describe('Runtime Variables', function() { describe('Initialized variables', function() {
it('should have a scene variable', function() { var initRuntime, lineCanvas;
expect(initRuntime.scene).toBe(null); beforeEach(function() {
}); initRuntime = new runtimeObj();
});
it('should have a sprites array', function() { describe('Runtime Variables', function() {
expect(initRuntime.sprites).toEqual([]); it('should have a scene variable', function() {
}); expect(initRuntime.scene).toBe(null);
});
it('should have a reporters array', function() { it('should have a sprites array', function() {
expect(initRuntime.reporters).toEqual([]); expect(initRuntime.sprites).toEqual([]);
}); });
it('should have a keysDown array', function() { it('should have a reporters array', function() {
expect(initRuntime.keysDown).toEqual([]); expect(initRuntime.reporters).toEqual([]);
}); });
it('should have a mouseDown variable', function() { it('should have a keysDown array', function() {
expect(initRuntime.mouseDown).toBe(false); expect(initRuntime.keysDown).toEqual([]);
}); });
it('should have a mousePos array', function() { it('should have a mouseDown variable', function() {
expect(initRuntime.mousePos).toEqual([0,0]); expect(initRuntime.mouseDown).toBe(false);
}); });
it('should have an audioContext variable', function() { it('should have a mousePos array', function() {
expect(initRuntime.audioContext).toBe(null); expect(initRuntime.mousePos).toEqual([0,0]);
}); });
it('should have an audoGain variable', function() { it('should have an audioContext variable', function() {
expect(initRuntime.audioGain).toBe(null); expect(initRuntime.audioContext).toBe(null);
}); });
it('should have an audioPlaying array', function() { it('should have an audoGain variable', function() {
expect(initRuntime.audioPlaying).toEqual([]); expect(initRuntime.audioGain).toBe(null);
}); });
it('should have a notesPlaying array', function() { it('should have an audioPlaying array', function() {
expect(initRuntime.notesPlaying).toEqual([]); expect(initRuntime.audioPlaying).toEqual([]);
}); });
it('should have a projectLoaded variable', function() { it('should have a notesPlaying array', function() {
expect(initRuntime.projectLoaded).toBe(false); expect(initRuntime.notesPlaying).toEqual([]);
}); });
});
});
describe('Stop All', function() { it('should have a projectLoaded variable', function() {
var realThread; expect(initRuntime.projectLoaded).toBe(false);
beforeEach(function() { });
runtime = new runtimeMock });
spyOn(window, "stopAllSounds");
spyOn(runtime.stage, "resetFilters");
spyOn(runtime.sprites[0], "hideBubble");
spyOn(runtime.sprites[0], "resetFilters");
spyOn(runtime.sprites[0], "hideAsk");
realThread = Thread;
Thread = threadMock;
interp = new interpreterMock();
}); });
afterEach(function() { describe('Stop All', function() {
Thread = realThread; var realThread;
}); beforeEach(function() {
runtime = new runtimeMock
spyOn(window, "stopAllSounds");
spyOn(runtime.stage, "resetFilters");
spyOn(runtime.sprites[0], "hideBubble");
spyOn(runtime.sprites[0], "resetFilters");
spyOn(runtime.sprites[0], "hideAsk");
realThread = Thread;
Thread = threadMock;
interp = new interpreterMock();
});
it('should call a new Thread Object', function() { afterEach(function() {
runtimeObj.prototype.stopAll(); Thread = realThread;
expect(interp.activeThread).toEqual(new threadMock()); });
});
it('should intitialize an empty threads array', function() { it('should call a new Thread Object', function() {
runtimeObj.prototype.stopAll(); runtimeObj.prototype.stopAll();
expect(interp.threads).toEqual([]); expect(interp.activeThread).toEqual(new threadMock());
}); });
it('should call stopAllSounds', function() { it('should intitialize an empty threads array', function() {
runtimeObj.prototype.stopAll(); runtimeObj.prototype.stopAll();
expect(window.stopAllSounds).toHaveBeenCalled(); expect(interp.threads).toEqual([]);
}); });
it('should call sprites.hideBubble', function() { it('should call stopAllSounds', function() {
runtimeObj.prototype.stopAll(); runtimeObj.prototype.stopAll();
expect(runtime.sprites[0].hideBubble).toHaveBeenCalled(); expect(window.stopAllSounds).toHaveBeenCalled();
}); });
it('should call sprites.resetFilters', function() { it('should call sprites.hideBubble', function() {
runtimeObj.prototype.stopAll(); runtimeObj.prototype.stopAll();
expect(runtime.sprites[0].resetFilters).toHaveBeenCalled(); expect(runtime.sprites[0].hideBubble).toHaveBeenCalled();
}); });
it('should call sprites.hideAsk', function() { it('should call sprites.resetFilters', function() {
runtimeObj.prototype.stopAll(); runtimeObj.prototype.stopAll();
expect(runtime.sprites[0].hideAsk).toHaveBeenCalled(); expect(runtime.sprites[0].resetFilters).toHaveBeenCalled();
}); });
}); it('should call sprites.hideAsk', function() {
runtimeObj.prototype.stopAll();
expect(runtime.sprites[0].hideAsk).toHaveBeenCalled();
});
});
}); });

View file

@ -4,63 +4,63 @@ describe('Scratch', function() {
var scratch; var scratch;
beforeEach(function() { beforeEach(function() {
spyOn(IO.prototype, "loadProject"); spyOn(IO.prototype, "loadProject");
spyOn(Runtime.prototype, "init"); spyOn(Runtime.prototype, "init");
spyOn(Interpreter.prototype, "initPrims"); spyOn(Interpreter.prototype, "initPrims");
scratch = Scratch; scratch = Scratch;
}); });
describe('Scratch - Load Project', function(){ describe('Scratch - Load Project', function() {
beforeEach(function() { beforeEach(function() {
scratch(project_id); scratch(project_id);
}); });
it('should call the IO loadProject Method', function() { it('should call the IO loadProject Method', function() {
expect(IO.prototype.loadProject).toHaveBeenCalled(); expect(IO.prototype.loadProject).toHaveBeenCalled();
}); });
it('should call the Runtime init method', function() { it('should call the Runtime init method', function() {
expect(Runtime.prototype.init).toHaveBeenCalled(); expect(Runtime.prototype.init).toHaveBeenCalled();
}); });
it('should call the Interpreter initPrims method', function() { it('should call the Interpreter initPrims method', function() {
expect(Interpreter.prototype.initPrims).toHaveBeenCalled(); expect(Interpreter.prototype.initPrims).toHaveBeenCalled();
}); });
}); });
describe('Scratch - Click Green Flag', function(){ describe('Scratch - Click Green Flag', function() {
beforeEach(function() { beforeEach(function() {
setFixtures('<button id=trigger-green-flag tabindex=2></button><div id="overlay"></div>'); setFixtures('<button id=trigger-green-flag tabindex=2></button><div id="overlay"></div>');
scratch(project_id); scratch(project_id);
}); });
it('should not click on the green flag if the project is loading', function() { it('should not click on the green flag if the project is loading', function() {
runtime.projectLoaded = false; runtime.projectLoaded = false;
spyOn(runtime, 'greenFlag'); spyOn(runtime, 'greenFlag');
$('#trigger-green-flag').click(); $('#trigger-green-flag').click();
expect(runtime.greenFlag).not.toHaveBeenCalled(); expect(runtime.greenFlag).not.toHaveBeenCalled();
expect($('#overlay').css('display')).toBe('block'); expect($('#overlay').css('display')).toBe('block');
}); });
it('should click on the green flag if the project is loaded', function() { it('should click on the green flag if the project is loaded', function() {
runtime.projectLoaded = true; runtime.projectLoaded = true;
spyOn(runtime, 'greenFlag'); spyOn(runtime, 'greenFlag');
$('#trigger-green-flag').click(); $('#trigger-green-flag').click();
expect(runtime.greenFlag).toHaveBeenCalled(); expect(runtime.greenFlag).toHaveBeenCalled();
expect($('#overlay').css('display')).toBe('none'); expect($('#overlay').css('display')).toBe('none');
}); });
}); });
describe('Scratch - Click Stop', function(){ describe('Scratch - Click Stop', function() {
beforeEach(function() { beforeEach(function() {
setFixtures('<button id=trigger-stop tabindex=3></button>'); setFixtures('<button id=trigger-stop tabindex=3></button>');
scratch(project_id); scratch(project_id);
}); });
it('should not click on the green flag if the project is loading', function() { it('should not click on the green flag if the project is loading', function() {
spyOn(runtime, 'stopAll'); spyOn(runtime, 'stopAll');
$('#trigger-stop').click(); $('#trigger-stop').click();
expect(runtime.stopAll).toHaveBeenCalled(); expect(runtime.stopAll).toHaveBeenCalled();
}); });
}); });
}); });

View file

@ -1,112 +1,109 @@
/* jasmine specs for primitives/SensingPrims.js go here */ /* jasmine specs for primitives/SensingPrims.js go here */
describe('SensingPrims', function() { describe('SensingPrims', function() {
var sensingPrims; var sensingPrims;
beforeEach(function() {
sensingPrims = SensingPrims;
realDate = Date;
});
afterEach(function () {
Date = realDate;
});
describe('primTimestamp', function(){
beforeEach(function() { beforeEach(function() {
/* MonkeyPatching the built-in Javascript Date */ sensingPrims = SensingPrims;
var epochDate = new Date(2000, 0, 1); realDate = Date;
var nowDate = new Date(2014, 5, 16);
Date = function () {
return (arguments.length ? epochDate : nowDate);
};
}); });
it('should return the days since 2000', function() { afterEach(function() {
expect(sensingPrims.prototype.primTimestamp()).toBeCloseTo(5280); Date = realDate;
});
});
describe('primTimeDate', function(){
beforeEach(function() {
/* MonkeyPatching the built-in Javascript Date */
Date = function () {
return {
'getFullYear' : function() { return 2014;},
'getMonth' : function() { return 4;},
'getDate' : function() { return 16;},
'getDay' : function() { return 4;},
'getHours' : function() { return 9;},
'getMinutes' : function() { return 18;},
'getSeconds' : function() { return 36;},
'getTime' : function() {}
};
};
}); });
it('should return the year', function() { describe('primTimestamp', function() {
var block = {'args' : ['year']}; beforeEach(function() {
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(2014); /* MonkeyPatching the built-in Javascript Date */
var epochDate = new Date(2000, 0, 1);
var nowDate = new Date(2014, 5, 16);
Date = function() {
return (arguments.length ? epochDate : nowDate);
};
});
it('should return the days since 2000', function() {
expect(sensingPrims.prototype.primTimestamp()).toBeCloseTo(5280);
});
}); });
it('should return the month of the year', function() { describe('primTimeDate', function() {
var block = {'args' : ['month']}; beforeEach(function() {
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(5); /* MonkeyPatching the built-in Javascript Date */
Date = function() {
return {
'getFullYear': function() { return 2014;},
'getMonth': function() { return 4;},
'getDate': function() { return 16;},
'getDay': function() { return 4;},
'getHours': function() { return 9;},
'getMinutes': function() { return 18;},
'getSeconds': function() { return 36;},
'getTime': function() {}
};
};
});
it('should return the year', function() {
var block = {'args': ['year']};
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(2014);
});
it('should return the month of the year', function() {
var block = {'args': ['month']};
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(5);
});
it('should return the day of the week', function() {
var block = {'args': ['day of week']};
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(5);
});
it('should return the hour of the day', function() {
var block = {'args': ['hour']};
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(9);
});
it('should return the minute of the hour', function() {
var block = {'args': ['minute']};
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(18);
});
it('should return the second of the minute', function() {
var block = {'args': ['second']};
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(36);
});
it('should return the 0 on year', function() {
var block = {'args': ['anythingElse']};
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(0);
});
}); });
it('should return the day of the week', function() { describe('primAnswer', function() {
var block = {'args' : ['day of week']}; beforeEach(function() {
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(5); interp = interpreterMock({'targetSprite': new targetMock()});
});
it('should return the answer variable from the targetedSprite', function() {
expect(sensingPrims.prototype.primAnswer()).toBe(12);
});
}); });
it('should return the hour of the day', function() { describe('primDoAsk', function() {
var block = {'args' : ['hour']}; var askBlock, targetSpriteMock;
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(9); beforeEach(function() {
targetSpriteMock = targetMock();
askBlock = {'args': 'what to ask'};
interp = interpreterMock({'targetSprite': targetSpriteMock}, {'arg': askBlock});
});
it('should call the showBubble method on the targetedSprite', function() {
spyOn(window, "showBubble");
spyOn(targetSpriteMock, "showAsk");
sensingPrims.prototype.primDoAsk(askBlock);
expect(window.showBubble).toHaveBeenCalledWith({args:'what to ask'}, 'doAsk');
expect(targetSpriteMock.showAsk).toHaveBeenCalled;
expect(interp.activeThread.paused).toBe(true);
});
}); });
it('should return the minute of the hour', function() {
var block = {'args' : ['minute']};
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(18);
});
it('should return the second of the minute', function() {
var block = {'args' : ['second']};
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(36);
});
it('should return the 0 on year', function() {
var block = {'args' : ['anythingElse']};
expect(sensingPrims.prototype.primTimeDate(block)).toEqual(0);
});
});
describe('primAnswer', function(){
beforeEach(function() {
interp = interpreterMock({'targetSprite': new targetMock()});
});
it('should return the answer variable from the targetedSprite', function() {
expect(sensingPrims.prototype.primAnswer()).toBe(12);
});
});
describe('primDoAsk', function(){
var askBlock, targetSpriteMock;
beforeEach(function() {
targetSpriteMock = targetMock();
askBlock = {'args': 'what to ask'};
interp = interpreterMock({'targetSprite': targetSpriteMock}, {'arg': askBlock});
});
it('should call the showBubble method on the targetedSprite', function() {
spyOn(window, "showBubble");
spyOn(targetSpriteMock, "showAsk");
sensingPrims.prototype.primDoAsk(askBlock);
expect(window.showBubble).toHaveBeenCalledWith({args:'what to ask'}, 'doAsk');
expect(targetSpriteMock.showAsk).toHaveBeenCalled;
expect(interp.activeThread.paused).toBe(true);
});
});
}); });

View file

@ -1,396 +1,396 @@
/* jasmine specs for Sprite.js go here */ /* jasmine specs for Sprite.js go here */
describe('Sprite', function() { describe('Sprite', function() {
var sprite; var sprite;
beforeEach(function() {
sprite = Sprite;
});
describe('Initialized variables', function() {
var initSprite;
beforeEach(function() { beforeEach(function() {
var spriteObject = sensingData.children[0]; sprite = Sprite;
initSprite = new sprite(spriteObject);
}); });
describe('Sprite Variables', function() { describe('Initialized variables', function() {
it('should have a visible variable', function() { var initSprite;
expect(initSprite.visible).toBe(true); beforeEach(function() {
}); var spriteObject = sensingData.children[0];
initSprite = new sprite(spriteObject);
});
describe('Sprite Variables', function() {
it('should have a visible variable', function() {
expect(initSprite.visible).toBe(true);
});
});
describe('Pen Variables', function() {
it('should have a penIsDown variable', function() {
expect(initSprite.penIsDown).toBe(false);
});
it('should have a penWidth variable', function() {
expect(initSprite.penWidth).toBe(1);
});
it('should have a penHue variable', function() {
expect(initSprite.penHue).toBe(120);
});
it('should have a penShade variable', function() {
expect(initSprite.penShade).toBe(50);
});
it('should have a penColorCache variable', function() {
expect(initSprite.penColorCache).toBe(0x0000FF);
});
});
describe('Ask Bubble', function() {
it('should have an askInput variable', function() {
expect(initSprite.askInput).toBe(null);
});
it('should have an askInputBox variable', function() {
expect(initSprite.askInputField).toBe(null);
});
it('should have an askInputStyler variable', function() {
expect(initSprite.askInputButton).toBe(null);
});
it('should have an askInputOn variable', function() {
expect(initSprite.askInputOn).toBe(false);
});
});
})
describe('showBubble', function() {
var spriteProto;
beforeEach(function() {
spriteProto = deepCopy(sprite.prototype);
spriteProto.visible = true;
setFixtures('<div class="bubble-container"></div>');
spriteProto.talkBubble = $('.bubble-container');
spriteProto.talkBubble.css('display', 'none');
spriteProto.talkBubbleBox = $('<div class="bubble"></div>');
spriteProto.talkBubbleStyler = $('<div class="bubble-say"></div>');
spriteProto.talkBubble.append(spriteProto.talkBubbleBox);
spriteProto.talkBubble.append(spriteProto.talkBubbleStyler);
});
describe('Say', function() {
it('should call the showBubble method on the Sprite', function() {
var text = "What to say";
spyOn(spriteProto, "getTalkBubbleXY").andReturn([50,50]);;
spriteProto.showBubble(text, "say");
expect($('.bubble').html()).toBe(text);
expect($('.bubble-say').hasClass('bubble-say')).toBe(true);
expect($('.bubble').hasClass('say-think-border')).toBe(true);
expect($('.bubble-container').css('display')).toBe('inline-block');
});
});
describe('Think', function() {
it('should call the showBubble method on the Sprite', function() {
var text = "What to think";
spyOn(spriteProto, "getTalkBubbleXY").andReturn([50,50]);;
spriteProto.showBubble(text, "think");
expect($('.bubble').html()).toBe(text);
expect($('.bubble-think').hasClass('bubble-think')).toBe(true);
expect($('.bubble').hasClass('say-think-border')).toBe(true);
expect($('.bubble-container').css('display')).toBe('inline-block');
});
});
describe('Ask', function() {
it('should call the showBubble method on the Sprite', function() {
var text = "What to Ask";
spyOn(spriteProto, "getTalkBubbleXY").andReturn([50,50]);;
spriteProto.showBubble(text, "doAsk");
expect($('.bubble').html()).toBe(text);
expect($('.bubble-ask').hasClass('bubble-ask')).toBe(true);
expect($('.bubble').hasClass('ask-border')).toBe(true);
expect($('.bubble-container').css('display')).toBe('inline-block');
});
});
describe('Any Bubble with visible false', function() {
it('should call the showBubble method on the Sprite and not display it', function() {
spriteProto.visible = false;
var text = "What to Ask";
spyOn(spriteProto, "getTalkBubbleXY").andReturn([50,50]);;
spriteProto.showBubble(text, "doAsk");
expect($('.bubble').html()).toBe(text);
expect($('.bubble-ask').hasClass('bubble-ask')).toBe(true);
expect($('.bubble').hasClass('ask-border')).toBe(true);
expect($('.bubble-container').css('display')).toBe('none');
});
});
}); });
describe('Pen Variables', function() { describe('hideBubble', function() {
it('should have a penIsDown variable', function() { var spriteProto;
expect(initSprite.penIsDown).toBe(false); beforeEach(function() {
}); spriteProto = deepCopy(sprite.prototype);
setFixtures('<div class="bubble-container"></div>');
spriteProto.talkBubble = $('.bubble-container');
spriteProto.talkBubble.css('display', 'inline');
});
it('should have a penWidth variable', function() { it('should hide the bubble', function() {
expect(initSprite.penWidth).toBe(1); spriteProto.hideBubble();
}); expect($('.bubble-container').css('display')).toBe('none');
expect(spriteProto.talkBubbleOn).toBe(false);
it('should have a penHue variable', function() { });
expect(initSprite.penHue).toBe(120);
});
it('should have a penShade variable', function() {
expect(initSprite.penShade).toBe(50);
});
it('should have a penColorCache variable', function() {
expect(initSprite.penColorCache).toBe(0x0000FF);
});
}); });
describe('Ask Bubble', function() { describe('showAsk', function() {
it('should have an askInput variable', function() { var spriteProto;
expect(initSprite.askInput).toBe(null); beforeEach(function() {
}); spriteProto = deepCopy(sprite.prototype);
spriteProto.visible = true;
spriteProto.z = 22;
setFixtures('<div class="ask-container"></div>');
spriteProto.askInput= $('.ask-container');
spriteProto.askInput.css('display','none');
spriteProto.askInput.css('position','relative');
spriteProto.askInputField = $('<div class="ask-input"></div>');
spriteProto.askInputTextField = $('<input type="text" class="ask-text-field"></input>');
spriteProto.askInputField.append(spriteProto.askInputTextField);
spriteProto.askInputButton = $('<div class="ask-button"></div>');
spriteProto.askInput.append(spriteProto.askInputField);
spriteProto.askInput.append(spriteProto.askInputButton);
});
it('should have an askInputBox variable', function() { it('should show the ask input if visible is true', function() {
expect(initSprite.askInputField).toBe(null); spriteProto.showAsk();
}); expect($('.ask-container').css('display')).toBe('inline-block');
expect($('.ask-container').css('z-index')).toBe('22');
expect($('.ask-container').css('left')).toBe('15px');
expect($('.ask-container').css('right')).toBe('15px');
expect($('.ask-container').css('bottom')).toBe('7px');
expect($('.ask-container').css('height')).toBe('25px');
expect($('.ask-container').css('height')).toBe('25px');
expect(
$('.ask-text-field').is(':focus') ||
document.activeElement.className.match(/ask-text-field/) !== null
).toBe(true);
expect(spriteProto.askInputOn).toBe(true);
});
it('should have an askInputStyler variable', function() { it('should not show the ask input if visible is false', function() {
expect(initSprite.askInputButton).toBe(null); spriteProto.visible = false;
}); spriteProto.showAsk();
expect($('.ask-container').css('display')).toBe('none');
it('should have an askInputOn variable', function() { expect(
expect(initSprite.askInputOn).toBe(false); $('.ask-text-field').is(':focus') ||
}); document.activeElement.className.match(/ask-text-field/) !== null
}); ).toBe(false);
}) });
describe('showBubble', function() {
var spriteProto;
beforeEach(function() {
spriteProto = deepCopy(sprite.prototype);
spriteProto.visible = true;
setFixtures('<div class="bubble-container"></div>');
spriteProto.talkBubble = $('.bubble-container');
spriteProto.talkBubble.css('display', 'none');
spriteProto.talkBubbleBox = $('<div class="bubble"></div>');
spriteProto.talkBubbleStyler = $('<div class="bubble-say"></div>');
spriteProto.talkBubble.append(spriteProto.talkBubbleBox);
spriteProto.talkBubble.append(spriteProto.talkBubbleStyler);
}); });
describe('Say', function(){ describe('hideAsk', function() {
it('should call the showBubble method on the Sprite', function() { var spriteProto;
var text = "What to say"; beforeEach(function() {
spyOn(spriteProto, "getTalkBubbleXY").andReturn([50,50]);; spriteProto = deepCopy(sprite.prototype);
spriteProto.showBubble(text, "say"); setFixtures('<div class="ask-container"></div>');
expect($('.bubble').html()).toBe(text); spriteProto.askInput = $('.ask-container');
expect($('.bubble-say').hasClass('bubble-say')).toBe(true); spriteProto.askInputTextField = $('<input type="text" class="ask-text-field"></input>');
expect($('.bubble').hasClass('say-think-border')).toBe(true); spriteProto.askInputTextField.val("Delete Me");
expect($('.bubble-container').css('display')).toBe('inline-block'); spriteProto.askInput.css('display', 'inline');
}); });
it('should hide the ask input', function() {
spriteProto.hideAsk();
expect($('.ask-container').css('display')).toBe('none');
expect(spriteProto.askInputOn).toBe(false);
expect(spriteProto.askInputTextField.val()).toBe('');
});
}); });
describe('Think', function(){ describe('bindAsk', function() {
it('should call the showBubble method on the Sprite', function() { beforeEach(function() {
var text = "What to think"; spriteProto = deepCopy(sprite.prototype);
spyOn(spriteProto, "getTalkBubbleXY").andReturn([50,50]);; spriteProto.askInputTextField = $('<input type="text" class="ask-text-field"></input>');
spriteProto.showBubble(text, "think"); spriteProto.askInputButton = $('<div class="ask-button"></div>');
expect($('.bubble').html()).toBe(text); spyOn(spriteProto, "hideBubble");
expect($('.bubble-think').hasClass('bubble-think')).toBe(true); spyOn(spriteProto, "hideAsk");
expect($('.bubble').hasClass('say-think-border')).toBe(true); });
expect($('.bubble-container').css('display')).toBe('inline-block');
}); it('should bind to the askInputButton and handle a click', function() {
interp = new interpreterMock();
spyOn(interp, "targetStage").andCallThrough();
$(spriteProto.askInputTextField).val('Hellow World');
spriteProto.bindDoAskButton();
$(spriteProto.askInputButton).click();
expect(interp.targetStage).toHaveBeenCalled();
});
it('should bind to the askInputButton and handle a enter/return', function() {
interp = new interpreterMock();
spyOn(interp, "targetStage").andCallThrough();
spriteProto.bindDoAskButton();
var e = $.Event( "keypress", { which: 13 } );
$(spriteProto.askInputButton).trigger(e);
expect(interp.targetStage).toHaveBeenCalled();
});
it('should call hideBubble', function() {
spriteProto.bindDoAskButton();
$(spriteProto.askInputButton).click();
expect(spriteProto.hideBubble).toHaveBeenCalled();
expect(spriteProto.hideAsk).toHaveBeenCalled();
});
it('should call hideAsk', function() {
spriteProto.bindDoAskButton();
$(spriteProto.askInputButton).click();
expect(spriteProto.hideAsk).toHaveBeenCalled();
});
it('should have interp.activeThread.paused be false', function() {
interp = new interpreterMock();
spriteProto.bindDoAskButton();
$(spriteProto.askInputButton).click();
expect(interp.activeThread.paused).toBe(false);
});
}); });
describe('Ask', function(){ describe('updateLayer', function() {
it('should call the showBubble method on the Sprite', function() { var spriteProto;
var text = "What to Ask"; beforeEach(function() {
spyOn(spriteProto, "getTalkBubbleXY").andReturn([50,50]);; spriteProto = deepCopy(sprite.prototype);
spriteProto.showBubble(text, "doAsk"); setFixtures('<img class="mesh"></img><div class="bubble-container"></div><div class="ask-container"></div>');
expect($('.bubble').html()).toBe(text); spriteProto.talkBubble = $('.bubble-container');
expect($('.bubble-ask').hasClass('bubble-ask')).toBe(true); spriteProto.talkBubble.css('position', 'relative');
expect($('.bubble').hasClass('ask-border')).toBe(true); spriteProto.askInput = $('.ask-container');
expect($('.bubble-container').css('display')).toBe('inline-block'); spriteProto.askInput.css('position', 'relative');
}); spriteProto.mesh = $('.mesh');
spriteProto.mesh.css('position', 'relative');
spriteProto.z = 22;
});
it('should update the mesh z-index', function() {
expect($('.mesh').css('z-index')).toBe('auto');
spriteProto.updateLayer();
expect($('.mesh').css('z-index')).toBe('22');
});
it('should update the talkBubble z-index', function() {
expect($('.bubble-container').css('z-index')).toBe('auto');
spriteProto.updateLayer();
expect($('.bubble-container').css('z-index')).toBe('22');
});
it('should update the askInput z-index', function() {
expect($('.ask-container').css('z-index')).toBe('auto');
spriteProto.updateLayer();
expect($('.ask-container').css('z-index')).toBe('22');
});
}); });
describe('Any Bubble with visible false', function(){ describe('updateVisible', function() {
it('should call the showBubble method on the Sprite and not display it', function() { var spriteProto;
spriteProto.visible = false; beforeEach(function() {
var text = "What to Ask"; spriteProto = deepCopy(sprite.prototype);
spyOn(spriteProto, "getTalkBubbleXY").andReturn([50,50]);; setFixtures('<img class="mesh"></img><div class="bubble-container"></div><div class="ask-container"></div>');
spriteProto.showBubble(text, "doAsk"); spriteProto.talkBubble = $('.bubble-container');
expect($('.bubble').html()).toBe(text); spriteProto.talkBubble.css('display', 'none');
expect($('.bubble-ask').hasClass('bubble-ask')).toBe(true); spriteProto.askInput = $('.ask-container');
expect($('.bubble').hasClass('ask-border')).toBe(true); spriteProto.askInput.css('display', 'none');
expect($('.bubble-container').css('display')).toBe('none'); spriteProto.mesh = $('.mesh');
}); spriteProto.mesh.css('display', 'none');
}); });
});
describe('hideBubble', function() { describe('mesh', function() {
var spriteProto; it('should update the mesh display on false', function() {
beforeEach(function() { expect($('.mesh').css('display')).toBe('none');
spriteProto = deepCopy(sprite.prototype); spriteProto.visible = false;
setFixtures('<div class="bubble-container"></div>'); spriteProto.updateVisible();
spriteProto.talkBubble = $('.bubble-container'); expect($('.mesh').css('display')).toBe('none');
spriteProto.talkBubble.css('display', 'inline'); });
});
it('should hide the bubble', function() { it('should update the mesh display on true', function() {
spriteProto.hideBubble(); expect($('.mesh').css('display')).toBe('none');
expect($('.bubble-container').css('display')).toBe('none'); spriteProto.visible = true;
expect(spriteProto.talkBubbleOn).toBe(false); spriteProto.updateVisible();
expect($('.mesh').css('display')).toBe('inline');
});
}); });
});
describe('showAsk', function() { describe('talkBubble', function() {
var spriteProto; it('should update the talkBubble on talkBubble true and visible true', function() {
beforeEach(function() { expect($('.bubble-container').css('display')).toBe('none');
spriteProto = deepCopy(sprite.prototype); spriteProto.talkBubbleOn = true;
spriteProto.visible = true; spriteProto.visible = true;
spriteProto.z = 22; spriteProto.updateVisible();
setFixtures('<div class="ask-container"></div>'); expect($('.bubble-container').css('display')).toBe('inline-block');
spriteProto.askInput= $('.ask-container'); });
spriteProto.askInput.css('display','none');
spriteProto.askInput.css('position','relative');
spriteProto.askInputField = $('<div class="ask-input"></div>');
spriteProto.askInputTextField = $('<input type="text" class="ask-text-field"></input>');
spriteProto.askInputField.append(spriteProto.askInputTextField);
spriteProto.askInputButton = $('<div class="ask-button"></div>');
spriteProto.askInput.append(spriteProto.askInputField);
spriteProto.askInput.append(spriteProto.askInputButton);
});
it('should show the ask input if visible is true', function() { it('should update the talkBubble on talkBubble false and visible true', function() {
spriteProto.showAsk(); expect($('.bubble-container').css('display')).toBe('none');
expect($('.ask-container').css('display')).toBe('inline-block'); spriteProto.talkBubbleOn = false;
expect($('.ask-container').css('z-index')).toBe('22'); spriteProto.visible = true;
expect($('.ask-container').css('left')).toBe('15px'); spriteProto.updateVisible();
expect($('.ask-container').css('right')).toBe('15px'); expect($('.bubble-container').css('display')).toBe('none');
expect($('.ask-container').css('bottom')).toBe('7px'); });
expect($('.ask-container').css('height')).toBe('25px');
expect($('.ask-container').css('height')).toBe('25px');
expect(
$('.ask-text-field').is(':focus') ||
document.activeElement.className.match(/ask-text-field/) !== null
).toBe(true);
expect(spriteProto.askInputOn).toBe(true);
});
it('should not show the ask input if visible is false', function() { it('should update the talkBubble on talkBubble true and visible false', function() {
spriteProto.visible = false; expect($('.bubble-container').css('display')).toBe('none');
spriteProto.showAsk(); spriteProto.talkBubbleOn = true;
expect($('.ask-container').css('display')).toBe('none'); spriteProto.visible = false;
expect( spriteProto.updateVisible();
$('.ask-text-field').is(':focus') || expect($('.bubble-container').css('display')).toBe('none');
document.activeElement.className.match(/ask-text-field/) !== null });
).toBe(false); });
});
});
describe('hideAsk', function() { describe('askContainer', function() {
var spriteProto; it('should update the askInput on askInput true and visible true', function() {
beforeEach(function() { expect($('.ask-container').css('display')).toBe('none');
spriteProto = deepCopy(sprite.prototype); spriteProto.askInputOn = true;
setFixtures('<div class="ask-container"></div>'); spriteProto.visible = true;
spriteProto.askInput = $('.ask-container'); spriteProto.updateVisible();
spriteProto.askInputTextField = $('<input type="text" class="ask-text-field"></input>'); expect($('.ask-container').css('display')).toBe('inline-block');
spriteProto.askInputTextField.val("Delete Me"); });
spriteProto.askInput.css('display', 'inline');
});
it('should hide the ask input', function() { it('should update the askInput on askInput false and visible true', function() {
spriteProto.hideAsk(); expect($('.ask-container').css('display')).toBe('none');
expect($('.ask-container').css('display')).toBe('none'); spriteProto.askInputOn = false;
expect(spriteProto.askInputOn).toBe(false); spriteProto.visible = true;
expect(spriteProto.askInputTextField.val()).toBe(''); spriteProto.updateVisible();
}); expect($('.ask-container').css('display')).toBe('none');
}); });
describe('bindAsk', function() { it('should update the askInput on askInput true and visible false', function() {
beforeEach(function() { expect($('.ask-container').css('display')).toBe('none');
spriteProto = deepCopy(sprite.prototype); spriteProto.askInputOn = true;
spriteProto.askInputTextField = $('<input type="text" class="ask-text-field"></input>'); spriteProto.visible = false;
spriteProto.askInputButton = $('<div class="ask-button"></div>'); spriteProto.updateVisible();
spyOn(spriteProto, "hideBubble"); expect($('.ask-container').css('display')).toBe('none');
spyOn(spriteProto, "hideAsk"); });
}); });
it('should bind to the askInputButton and handle a click', function() {
interp = new interpreterMock();
spyOn(interp, "targetStage").andCallThrough();
$(spriteProto.askInputTextField).val('Hellow World');
spriteProto.bindDoAskButton();
$(spriteProto.askInputButton).click();
expect(interp.targetStage).toHaveBeenCalled();
});
it('should bind to the askInputButton and handle a enter/return', function() {
interp = new interpreterMock();
spyOn(interp, "targetStage").andCallThrough();
spriteProto.bindDoAskButton();
var e = $.Event( "keypress", { which: 13 } );
$(spriteProto.askInputButton).trigger(e);
expect(interp.targetStage).toHaveBeenCalled();
});
it('should call hideBubble', function() {
spriteProto.bindDoAskButton();
$(spriteProto.askInputButton).click();
expect(spriteProto.hideBubble).toHaveBeenCalled();
expect(spriteProto.hideAsk).toHaveBeenCalled();
});
it('should call hideAsk', function() {
spriteProto.bindDoAskButton();
$(spriteProto.askInputButton).click();
expect(spriteProto.hideAsk).toHaveBeenCalled();
});
it('should have interp.activeThread.paused be false', function() {
interp = new interpreterMock();
spriteProto.bindDoAskButton();
$(spriteProto.askInputButton).click();
expect(interp.activeThread.paused).toBe(false);
});
});
describe('updateLayer', function() {
var spriteProto;
beforeEach(function() {
spriteProto = deepCopy(sprite.prototype);
setFixtures('<img class="mesh"></img><div class="bubble-container"></div><div class="ask-container"></div>');
spriteProto.talkBubble = $('.bubble-container');
spriteProto.talkBubble.css('position', 'relative');
spriteProto.askInput = $('.ask-container');
spriteProto.askInput.css('position', 'relative');
spriteProto.mesh = $('.mesh');
spriteProto.mesh.css('position', 'relative');
spriteProto.z = 22;
});
it('should update the mesh z-index', function() {
expect($('.mesh').css('z-index')).toBe('auto');
spriteProto.updateLayer();
expect($('.mesh').css('z-index')).toBe('22');
});
it('should update the talkBubble z-index', function() {
expect($('.bubble-container').css('z-index')).toBe('auto');
spriteProto.updateLayer();
expect($('.bubble-container').css('z-index')).toBe('22');
});
it('should update the askInput z-index', function() {
expect($('.ask-container').css('z-index')).toBe('auto');
spriteProto.updateLayer();
expect($('.ask-container').css('z-index')).toBe('22');
});
});
describe('updateVisible', function() {
var spriteProto;
beforeEach(function() {
spriteProto = deepCopy(sprite.prototype);
setFixtures('<img class="mesh"></img><div class="bubble-container"></div><div class="ask-container"></div>');
spriteProto.talkBubble = $('.bubble-container');
spriteProto.talkBubble.css('display', 'none');
spriteProto.askInput = $('.ask-container');
spriteProto.askInput.css('display', 'none');
spriteProto.mesh = $('.mesh');
spriteProto.mesh.css('display', 'none');
});
describe('mesh', function() {
it('should update the mesh display on false', function() {
expect($('.mesh').css('display')).toBe('none');
spriteProto.visible = false;
spriteProto.updateVisible();
expect($('.mesh').css('display')).toBe('none');
});
it('should update the mesh display on true', function() {
expect($('.mesh').css('display')).toBe('none');
spriteProto.visible = true;
spriteProto.updateVisible();
expect($('.mesh').css('display')).toBe('inline');
});
}); });
describe('talkBubble', function() { describe('setVisible', function() {
it('should update the talkBubble on talkBubble true and visible true', function() { var spriteProto;
expect($('.bubble-container').css('display')).toBe('none'); beforeEach(function() {
spriteProto.talkBubbleOn = true; spriteProto = deepCopy(sprite.prototype);
spriteProto.visible = true; spyOn(spriteProto, "updateVisible");
spriteProto.updateVisible(); });
expect($('.bubble-container').css('display')).toBe('inline-block');
});
it('should update the talkBubble on talkBubble false and visible true', function() { it('should set visible to true', function() {
expect($('.bubble-container').css('display')).toBe('none'); expect(spriteProto.visible).toBe(undefined);
spriteProto.talkBubbleOn = false; spriteProto.setVisible(true);
spriteProto.visible = true; expect(spriteProto.visible).toBe(true);
spriteProto.updateVisible(); expect(spriteProto.updateVisible).toHaveBeenCalled();
expect($('.bubble-container').css('display')).toBe('none'); });
});
it('should update the talkBubble on talkBubble true and visible false', function() { it('should set visible to false', function() {
expect($('.bubble-container').css('display')).toBe('none'); spriteProto.visible = true;
spriteProto.talkBubbleOn = true; spriteProto.setVisible(false);
spriteProto.visible = false; expect(spriteProto.visible).toBe(false);
spriteProto.updateVisible(); expect(spriteProto.updateVisible).toHaveBeenCalled();
expect($('.bubble-container').css('display')).toBe('none'); });
});
}); });
describe('askContainer', function() {
it('should update the askInput on askInput true and visible true', function() {
expect($('.ask-container').css('display')).toBe('none');
spriteProto.askInputOn = true;
spriteProto.visible = true;
spriteProto.updateVisible();
expect($('.ask-container').css('display')).toBe('inline-block');
});
it('should update the askInput on askInput false and visible true', function() {
expect($('.ask-container').css('display')).toBe('none');
spriteProto.askInputOn = false;
spriteProto.visible = true;
spriteProto.updateVisible();
expect($('.ask-container').css('display')).toBe('none');
});
it('should update the askInput on askInput true and visible false', function() {
expect($('.ask-container').css('display')).toBe('none');
spriteProto.askInputOn = true;
spriteProto.visible = false;
spriteProto.updateVisible();
expect($('.ask-container').css('display')).toBe('none');
});
});
});
describe('setVisible', function() {
var spriteProto;
beforeEach(function() {
spriteProto = deepCopy(sprite.prototype);
spyOn(spriteProto, "updateVisible");
});
it('should set visible to true', function() {
expect(spriteProto.visible).toBe(undefined);
spriteProto.setVisible(true);
expect(spriteProto.visible).toBe(true);
expect(spriteProto.updateVisible).toHaveBeenCalled();
});
it('should set visible to false', function() {
spriteProto.visible = true;
spriteProto.setVisible(false);
expect(spriteProto.visible).toBe(false);
expect(spriteProto.updateVisible).toHaveBeenCalled();
});
});
}); });

View file

@ -1,55 +1,55 @@
/* jasmine specs for Stage.js go here */ /* jasmine specs for Stage.js go here */
describe('Stage', function() { describe('Stage', function() {
var stage; var stage;
beforeEach(function() {
stage = Stage;
});
describe('Initialized variables', function() {
var initStage, lineCanvas;
beforeEach(function() { beforeEach(function() {
spyOn(Sprite, "call"); stage = Stage;
initStage = new stage(sensingData);
}); });
describe('Stage Variables', function() { describe('Initialized variables', function() {
it('should have a z variable', function() { var initStage, lineCanvas;
expect(initStage.z).toBe(-2); beforeEach(function() {
}); spyOn(Sprite, "call");
initStage = new stage(sensingData);
});
it('should have a penLayerLoaded variable', function() { describe('Stage Variables', function() {
expect(initStage.penLayerLoaded).toBe(false); it('should have a z variable', function() {
}); expect(initStage.z).toBe(-2);
});
it('should have a lineCanvas element', function() { it('should have a penLayerLoaded variable', function() {
expect(initStage.lineCanvas).toBeDefined(); expect(initStage.penLayerLoaded).toBe(false);
}); });
it('should have a lineCanvas width', function() { it('should have a lineCanvas element', function() {
expect(initStage.lineCanvas.width).toBe(480); expect(initStage.lineCanvas).toBeDefined();
}); });
it('should have a lineCanvas height', function() { it('should have a lineCanvas width', function() {
expect(initStage.lineCanvas.height).toBe(360); expect(initStage.lineCanvas.width).toBe(480);
}); });
it('should have a lineCache variable', function() { it('should have a lineCanvas height', function() {
expect(initStage.lineCache).toBeDefined(); expect(initStage.lineCanvas.height).toBe(360);
}); });
it('should have a isStage variable', function() { it('should have a lineCache variable', function() {
expect(initStage.isStage).toBe(true); expect(initStage.lineCache).toBeDefined();
}); });
it('should have an askAnswer variable', function() { it('should have a isStage variable', function() {
expect(initStage.askAnswer).toBe(""); expect(initStage.isStage).toBe(true);
}); });
it('should have called Sprite.call', function() { it('should have an askAnswer variable', function() {
expect(Sprite.call).toHaveBeenCalled(); expect(initStage.askAnswer).toBe("");
}); });
it('should have called Sprite.call', function() {
expect(Sprite.call).toHaveBeenCalled();
});
});
}); });
});
}); });

View file

@ -1,50 +1,50 @@
/* jasmine specs for Interpreter.js -> Thread go here */ /* jasmine specs for Interpreter.js -> Thread go here */
describe('Thread', function() { describe('Thread', function() {
var thread; var thread;
beforeEach(function() {
thread = Thread;
});
describe('Initialized variables', function() {
var initThread;
beforeEach(function() { beforeEach(function() {
initThread = new thread('block', 'target'); thread = Thread;
}); });
describe('Thread Variables', function() { describe('Initialized variables', function() {
it('should have a nextBlock variable', function() { var initThread;
expect(initThread.nextBlock).toBe('block'); beforeEach(function() {
}); initThread = new thread('block', 'target');
});
it('should have a firstBlock variable', function() { describe('Thread Variables', function() {
expect(initThread.firstBlock).toBe('block'); it('should have a nextBlock variable', function() {
}); expect(initThread.nextBlock).toBe('block');
});
it('should have a stack variable', function() { it('should have a firstBlock variable', function() {
expect(initThread.stack).toEqual([]); expect(initThread.firstBlock).toBe('block');
}); });
it('should have a target variable', function() { it('should have a stack variable', function() {
expect(initThread.target).toBe('target'); expect(initThread.stack).toEqual([]);
}); });
it('should have a tmp variable', function() { it('should have a target variable', function() {
expect(initThread.tmp).toBe(null); expect(initThread.target).toBe('target');
}); });
it('should have a tmpObj variable', function() { it('should have a tmp variable', function() {
expect(initThread.tmpObj).toEqual([]); expect(initThread.tmp).toBe(null);
}); });
it('should have a firstTime variable', function() { it('should have a tmpObj variable', function() {
expect(initThread.firstTime).toBe(true); expect(initThread.tmpObj).toEqual([]);
}); });
it('should have a paused variable', function() { it('should have a firstTime variable', function() {
expect(initThread.paused).toBe(false); expect(initThread.firstTime).toBe(true);
}); });
it('should have a paused variable', function() {
expect(initThread.paused).toBe(false);
});
});
}); });
});
}); });