Skip to content

Commit

Permalink
added test for 'say' operator #145
Browse files Browse the repository at this point in the history
from now, 'say' command works for all around organisms, not only one
  • Loading branch information
tmptrash committed Jun 24, 2018
1 parent 25dad99 commit ce56353
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 7 deletions.
10 changes: 7 additions & 3 deletions client/src/manager/plugins/organisms/dos/Operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,13 @@ class OperatorsDos extends Operators {

for (let v0 = 0; v0 < vars; v0++) {
eval(`Operators.global.fn = function say(line, num, org) {
let x = org.dirX;
let y = org.dirY;
IN_WORLD(x, y) && !(this._positions[x][y] <= 0) && (this._positions[x][y].msg = this.vars[${v0}]);
const poses = this._positions;
for (let x = org.x - 1, xlen = org.x + 2; x < xlen; x++) {
for (let y = org.y - 1, ylen = org.y + 2; y < ylen; y++) {
IN_WORLD(x, y) && !(poses[x][y] <= 0) && (poses[x][y].msg = this.vars[${v0}]);
}
}
return ++line;
}`);
ops[h(`${'110101'}${b(v0, bpv)}`)] = this.global.fn;
Expand Down
74 changes: 70 additions & 4 deletions client/src/manager/plugins/organisms/dos/OperatorsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1987,8 +1987,8 @@ describe("client/src/manager/plugins/organisms/dos/OperatorsDos", () => {
expect(global.man.positions[2][1]).toEqual(EMPTY);
expect(global.man.world.getDot(2,1)).toEqual(EMPTY);

global.man.positions[2][1] = EMPTY;
global.man.world.setDot(2,1,EMPTY);
global.man.positions[1][0] = EMPTY;
global.man.world.setDot(1,0,EMPTY);
});

describe('pick() operator with 3bits per var', () => {
Expand Down Expand Up @@ -2168,12 +2168,78 @@ describe("client/src/manager/plugins/organisms/dos/OperatorsDos", () => {
expect(global.man.positions[2][1]).toEqual(EMPTY);
expect(global.man.world.getDot(2,1)).toEqual(EMPTY);

global.man.positions[2][1] = EMPTY;
global.man.world.setDot(2,1,EMPTY);
global.man.positions[1][0] = EMPTY;
global.man.world.setDot(1,0,EMPTY);
});
});
});

describe('say() operator', () => {
it("Checking say to nothing", () => {
ops.vars[0] = 1;
expect(ops.operators[hex('110101 00')].call(ops, 0, hex('110101 00'), org)).toEqual(1);

expect(org.msg).toEqual(0);
expect(global.man.positions[1][0]).toEqual(EMPTY);
expect(global.man.world.getDot(1, 0)).toEqual(EMPTY);
});

it("Checking say to other organism 1", () => {
const org2 = new OrganismDos(1, 1, 0, {});
ops.vars[0] = 11;
org.x = 0;
org.y = 0;
global.man.positions[1][0] = org2;
expect(ops.operators[hex('110101 00')].call(ops, 0, hex('110101 00'), org)).toEqual(1);

expect(org2.msg).toEqual(11);
expect(ops.vars).toEqual([11, 1, 2, 3]);
global.man.positions[1][0] = EMPTY;
});
it("Checking say to other organism 2", () => {
const org2 = new OrganismDos(1, 1, 1, {});
ops.vars[0] = 11;
org.x = 0;
org.y = 0;
global.man.positions[1][1] = org2;
expect(ops.operators[hex('110101 00')].call(ops, 0, hex('110101 00'), org)).toEqual(1);

expect(org2.msg).toEqual(11);
expect(ops.vars).toEqual([11, 1, 2, 3]);
global.man.positions[1][1] = EMPTY;
});
it("Checking say to other organism 3", () => {
const org2 = new OrganismDos(1, 0, 1, {});
ops.vars[0] = 11;
org.x = 0;
org.y = 0;
global.man.positions[0][1] = org2;
expect(ops.operators[hex('110101 00')].call(ops, 0, hex('110101 00'), org)).toEqual(1);

expect(org2.msg).toEqual(11);
expect(ops.vars).toEqual([11, 1, 2, 3]);
global.man.positions[0][1] = EMPTY;
});

it("Checking say to many organisms", () => {
const org2 = new OrganismDos(1, 1, 0, {});
const org3 = new OrganismDos(1, 1, 1, {});

ops.vars[0] = 11;
org.x = 0;
org.y = 0;
global.man.positions[1][0] = org2;
global.man.positions[1][1] = org3;
expect(ops.operators[hex('110101 00')].call(ops, 0, hex('110101 00'), org)).toEqual(1);

expect(org2.msg).toEqual(11);
expect(org3.msg).toEqual(11);
expect(ops.vars).toEqual([11, 1, 2, 3]);
global.man.positions[1][0] = EMPTY;
global.man.positions[1][1] = EMPTY;
});
});

xdescribe('onCheckLeft() method', () => {
let org;
let ops;
Expand Down

0 comments on commit ce56353

Please sign in to comment.