Rewrite lib with typescript

This commit is contained in:
2020-03-21 17:59:41 +03:00
parent 474dae9748
commit 4bdd38ec15
28 changed files with 2374 additions and 7718 deletions

View File

@ -1,49 +0,0 @@
import expect from 'expect';
import Daemon from '../source/Daemon';
import Journal from '../source/Journal';
test('Get prediction for beginning', function() {
const m = new Journal();
const d = new Daemon(2, 1, 1);
expect(d.predict(m)).toEqual(0);
});
test('Can get power', function() {
const d = new Daemon(2, 5, 8);
expect(d.power).toEqual(13);
});
test('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).toEqual(step.prediction);
d.adjust(m, step.human);
m.makeMove(step.human, step.prediction);
});
});

52
tests/DaemonTest.ts Normal file
View File

@ -0,0 +1,52 @@
import { it, describe } from 'mocha';
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);
// });
it('Can get power', function() {
const d = new Daemon(2, 5, 8);
expect(d.power).to.eqls(13);
});
// 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

@ -1,30 +0,0 @@
import Journal from '../source/Journal';
import Move from '../source/Move';
import expect from 'expect';
test('Create with empty constructor', function() {
const m = new Journal();
expect(m.getLastMovements(5, 5)).toEqual([]);
});
test('Constructor with human steps', function() {
const m = new Journal([new Move(1, 1)]);
expect(m.getLastMovements(5, 5)).toEqual([1, 1]);
});
test('Make steps', function() {
const m = new Journal();
m.makeMove(1, 0);
expect(m.getLastMovements(5, 5)).toEqual([0, 1]);
});
test('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)).toEqual([1, 0, 0, 1]);
});

32
tests/JourlanTest.ts Normal file
View File

@ -0,0 +1,32 @@
import { it } from 'mocha';
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([]);
});
it('Constructor with human steps', function() {
const m = new Journal([new Move(1, 1)]);
expect(m.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('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]);
});