This commit is contained in:
2018-05-21 08:12:29 +03:00
commit 0d4e25dbf8
14 changed files with 12923 additions and 0 deletions

54
tests/DaemonTest.js Normal file
View File

@ -0,0 +1,54 @@
import Daemon from '../source/Daemon';
import expect from 'expect';
import Movements from '../source/Movements';
test('Get prediction for beginning', function() {
const m = new Movements();
const d = new Daemon(1, 1);
expect(d.predict(m)).toEqual(0);
});
test('Daemon 1-1', function() {
const m = new Movements();
const d = new Daemon(1, 1);
const step_slice = s => {
return [].concat(
s.slice(-1).slice.map(i => i.robot),
s.slice(-1).slice.map(i => i.human)
);
};
const steps = [
{
robot: 0,
human: 1,
},
{
robot: 0,
human: 1,
},
{
robot: 1,
human: 1,
},
{
robot: 0,
human: 1,
},
{
robot: 1,
human: 1,
},
];
steps.forEach((step, index) => {
const robot = d.predict(m);
// expect(d._getStepSlice(m)).toEqual(step_slice(steps));
expect(robot).toEqual(step.robot);
d.adjust(m, step.human, index + 1);
m.makeHumanMove(step.human);
m.makeRobotMove(step.robot);
console.log('Step', index + 1, d);
});
});

38
tests/MovementsTest.js Normal file
View File

@ -0,0 +1,38 @@
import Movements from '../source/Movements';
import expect from 'expect';
test('Create with empty constructor', function() {
const m = new Movements();
expect(m.getLastMovements(5, 5)).toEqual([]);
});
test('Constructor with human steps', function() {
const m = new Movements([1, 1]);
expect(m.getLastMovements(5, 5)).toEqual([1, 1]);
});
test('Make human step', function() {
const m = new Movements();
m.makeHumanMove(1);
m.makeHumanMove(0);
expect(m.getLastMovements(5, 5)).toEqual([1, 0]);
});
test('Make robot step', function() {
const m = new Movements();
m.makeRobotMove(0);
m.makeRobotMove(1);
expect(m.getLastMovements(5, 5)).toEqual([0, 1]);
});
test('Make mixed steps', function() {
const m = new Movements();
m.makeHumanMove(1);
m.makeRobotMove(0);
expect(m.getLastMovements(5, 5)).toEqual([0, 1]);
});
test('Get slice', function() {
const m = new Movements([1, 0, 0, 1], [1, 1, 0, 0]);
expect(m.getLastMovements(2, 2)).toEqual([0, 0, 0, 1]);
});