Introduce new thread tests.
This commit is contained in:
parent
fa42953d58
commit
a33f4728da
1 changed files with 63 additions and 0 deletions
|
@ -5,6 +5,7 @@ describe('Thread', function() {
|
|||
|
||||
beforeEach(function() {
|
||||
thread = Thread;
|
||||
io = new ioMock();
|
||||
});
|
||||
|
||||
describe('Initialized variables', function() {
|
||||
|
@ -47,4 +48,66 @@ describe('Thread', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test execution of threads', function() {
|
||||
var initInterp, task;
|
||||
|
||||
beforeEach(function() {
|
||||
interp = new Interpreter();
|
||||
interp.initPrims();
|
||||
});
|
||||
|
||||
it('One thread gets executed eventually', function() {
|
||||
var isThreadExecuted = false;
|
||||
interp.primitiveTable['mocktask'] = function() {
|
||||
isThreadExecuted = true;
|
||||
};
|
||||
var runblock = new Block(['mocktask'], null);
|
||||
|
||||
interp.startThread(runblock, new Sprite({}));
|
||||
interp.stepThreads();
|
||||
|
||||
expect(isThreadExecuted).toBe(true);
|
||||
});
|
||||
|
||||
it('Every thread gets executed eventually', function() {
|
||||
var isThread1Executed = false;
|
||||
var isThread2Executed = false;
|
||||
interp.primitiveTable['mocktask1'] = function() {
|
||||
isThread1Executed = true;
|
||||
};
|
||||
interp.primitiveTable['mocktask2'] = function() {
|
||||
isThread2Executed = true;
|
||||
};
|
||||
var runblock1 = new Block(['mocktask1'], null);
|
||||
var runblock2 = new Block(['mocktask2'], null);
|
||||
interp.startThread(runblock1, new Sprite({}));
|
||||
interp.startThread(runblock2, new Sprite({}));
|
||||
|
||||
interp.stepThreads();
|
||||
|
||||
expect(isThread1Executed).toBe(true);
|
||||
expect(isThread2Executed).toBe(true);
|
||||
});
|
||||
|
||||
it('stepActiveThread should execute only the active thread', function() {
|
||||
var isThread1Executed = false;
|
||||
var isThread2Executed = false;
|
||||
interp.primitiveTable['mocktask1'] = function() {
|
||||
isThread1Executed = true;
|
||||
};
|
||||
interp.primitiveTable['mocktask2'] = function() {
|
||||
isThread2Executed = true;
|
||||
};
|
||||
var runblock1 = new Block(['mocktask1'], null);
|
||||
var runblock2 = new Block(['mocktask2'], null);
|
||||
interp.startThread(runblock1, new Sprite({}));
|
||||
interp.startThread(runblock2, new Sprite({}));
|
||||
|
||||
interp.stepActiveThread();
|
||||
|
||||
expect(isThread1Executed).toBe(false);
|
||||
expect(isThread2Executed).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Reference in a new issue