ran npm run tdd & generated TDD
This commit is contained in:
18
test/elo/elo.js
Normal file
18
test/elo/elo.js
Normal file
@ -0,0 +1,18 @@
|
||||
module.exports = ([...ratings], kFactor = 32, selfRating) => {
|
||||
const [a, b] = ratings;
|
||||
const expectedScore = (self, opponent) => 1 / (1 + 10 ** ((opponent - self) / 400));
|
||||
const newRating = (rating, i) =>
|
||||
(selfRating || rating) + kFactor * (i - expectedScore(i ? a : b, i ? b : a));
|
||||
if (ratings.length === 2) {
|
||||
return [newRating(a, 1), newRating(b, 0)];
|
||||
} else {
|
||||
for (let i = 0; i < ratings.length; i++) {
|
||||
let j = i;
|
||||
while (j < ratings.length - 1) {
|
||||
[ratings[i], ratings[j + 1]] = elo([ratings[i], ratings[j + 1]], kFactor);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ratings;
|
||||
};
|
||||
13
test/elo/elo.test.js
Normal file
13
test/elo/elo.test.js
Normal file
@ -0,0 +1,13 @@
|
||||
const test = require('tape');
|
||||
const elo = require('./elo.js');
|
||||
|
||||
test('Testing elo', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof elo === 'function', 'elo is a Function');
|
||||
//t.deepEqual(elo(args..), 'Expected');
|
||||
//t.equal(elo(args..), 'Expected');
|
||||
//t.false(elo(args..), 'Expected');
|
||||
//t.throws(elo(args..), 'Expected');
|
||||
t.end();
|
||||
});
|
||||
Reference in New Issue
Block a user