Restore tests

This commit is contained in:
2020-03-22 12:40:58 +03:00
parent 4a18dc5808
commit eb66b6904d
9 changed files with 110 additions and 164 deletions

View File

@ -4,49 +4,51 @@ import { expect } from 'chai';
import Daemon from '../src/Daemon';
import Journal from '../src/Journal';
// it('Get prediction for beginning', function() {
// const m = new Journal();
// const d = new Daemon(2, 1, 1);
// const predicted = d.predict(m);
// expect(predicted).to.equals(0);
// });
describe('Daemon', function() {
it('Get prediction for beginning', function() {
const journal = new Journal();
const daemon = new Daemon(2, 1, 1);
const predicted = daemon.predict(journal);
expect(predicted).to.equals(0);
});
it('Can get power', function() {
const d = new Daemon(2, 5, 8);
expect(d.power).to.eqls(13);
it('Can get power', function() {
const d = new Daemon(2, 5, 8);
expect(d.power).to.eqls(13);
});
it('Daemon 1-1', function() {
const journal = new Journal();
const daemon = new Daemon(2, 1, 1, 0.1);
const steps = [
{
prediction: 0,
human: 1,
},
{
prediction: 0,
human: 1,
},
{
prediction: 1,
human: 1,
},
{
prediction: 0,
human: 1,
},
{
prediction: 1,
human: 1,
},
];
steps.forEach(step => {
const prediction = daemon.predict(journal);
expect(prediction).to.eqls(step.prediction);
daemon.adjust(journal, step.human);
journal.makeMove(step.human, step.prediction);
});
});
});
// it('Daemon 1-1', function() {
// const m = new Journal();
// const d = new Daemon(2, 1, 1);
//
// const steps = [
// {
// prediction: 0,
// human: 1,
// },
// {
// prediction: 0,
// human: 1,
// },
// {
// prediction: 1,
// human: 1,
// },
// {
// prediction: 0,
// human: 1,
// },
// {
// prediction: 1,
// human: 1,
// },
// ];
//
// steps.forEach(step => {
// const prediction = d.predict(m);
// expect(prediction).to.eqls(step.prediction);
// d.adjust(m, step.human);
// m.makeMove(step.human, step.prediction);
// });
// });

View File

@ -4,29 +4,34 @@ import { expect } from 'chai';
import Journal from '../src/Journal';
import Move from '../src/Move';
it('Create with empty constructor', function() {
const m = new Journal();
expect(m.getLastMovements(5, 5)).to.eqls([]);
});
describe('Journal', function() {
it('Create with empty constructor', function() {
const journal = new Journal();
expect(journal.length).to.equals(0);
expect(journal.getLastMovements(5, 5)).to.eqls([]);
});
it('Constructor with human steps', function() {
const m = new Journal([new Move(1, 1)]);
expect(m.getLastMovements(5, 5)).to.eqls([1, 1]);
});
it('Constructor with human steps', function() {
const journal = new Journal([new Move(1, 1)]);
expect(journal.length).equals(1);
expect(journal.getLastMovements(5, 5)).to.eqls([1, 1]);
});
it('Make steps', function() {
const m = new Journal();
m.makeMove(1, 0);
expect(m.getLastMovements(5, 5)).to.eqls([0, 1]);
});
it('Make steps', function() {
const journal = new Journal();
journal.makeMove(1, 0);
journal.makeMove(1, 1);
expect(journal.length).to.equals(2);
expect(journal.getLastMovements(2, 2)).to.eqls([0, 1, 1, 1]);
});
it('Get slice', function() {
const m = new Journal([
new Move(1, 1),
new Move(0, 1),
new Move(0, 1),
new Move(1, 0),
]);
expect(m.getLastMovements(2, 2)).to.eqls([1, 0, 0, 1]);
it('Get slice', function() {
const m = new Journal([
new Move(1, 1),
new Move(0, 1),
new Move(0, 1),
new Move(1, 0),
]);
expect(m.getLastMovements(2, 2)).to.eqls([1, 0, 0, 1]);
});
});