-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor fixes + início da criação dos testes unitários.
- Loading branch information
Renan Verissimo de vasconcelos
committed
Nov 14, 2018
1 parent
2849ed6
commit 36a0117
Showing
2 changed files
with
285 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,252 @@ | ||
import {expect} from 'chai'; | ||
import {Tournament, Player} from './bracketzada.js'; | ||
describe('Teste do teste', function() { | ||
describe('_generateGraph', function() { | ||
it('Deve retornar um array com os nós conectados corretamente.', function() { | ||
let players = [ | ||
new Player('a', 0), | ||
new Player('b', 1), | ||
new Player('c', 2), | ||
new Player('d', 3), | ||
new Player('e', 4), | ||
new Player('f', 5), | ||
new Player('g', 6), | ||
new Player('h', 7) | ||
] | ||
|
||
let champ = new Tournament(players); | ||
champ.generateBrackets(); | ||
//champ.setWinnerMatch(4, 6); | ||
//expect(graph[0].idParent).equals("Kappa"); | ||
|
||
describe('Player Class', function() { | ||
describe('Instance', function() { | ||
it('Must have id and name instantiating a new Player.', function() { | ||
let player = new Player(1, "Kappa"); | ||
|
||
expect(player.id).equal(1); | ||
expect(player.name).equal("Kappa"); | ||
}) | ||
}) | ||
}) | ||
|
||
describe('Tournament Class', function() { | ||
describe('Instance', function() { | ||
it('Must have a Players array.', function() { | ||
let players = [ | ||
new Player(0, 'a'), | ||
new Player(1, 'b'), | ||
new Player(2, 'c'), | ||
new Player(3, 'a') | ||
]; | ||
let tournament = new Tournament(players); | ||
|
||
expect(tournament.name).equal('Bracketzada Tournament'); | ||
expect(tournament.players).equals(players); | ||
}) | ||
|
||
it('Name should be overwritten.', function() { | ||
let players = [ | ||
new Player(0, 'a'), | ||
new Player(1, 'b'), | ||
new Player(2, 'c'), | ||
new Player(3, 'a') | ||
]; | ||
let tournament = new Tournament(players, "Charlinhos Cup!"); | ||
|
||
expect(tournament.name).equal('Charlinhos Cup!'); | ||
expect(tournament.players).equals(players); | ||
}) | ||
}) | ||
|
||
describe('numberNodes', function() { | ||
it('Should return 0 as there are no players on the tournament.', function() { | ||
let players: Player[] = []; | ||
let tournament = new Tournament(players); | ||
|
||
expect(tournament.numberNodes()).equal(0); | ||
}); | ||
|
||
it('Should return 1 as there is 1 player on the tournament.', function() { | ||
let players = [ | ||
new Player(0, 'a') | ||
]; | ||
let tournament = new Tournament(players); | ||
|
||
expect(tournament.numberNodes()).equal(1); | ||
}); | ||
|
||
it('Should return 2 as there are 2 player on the tournament.', function() { | ||
let players = [ | ||
new Player(0, 'a'), | ||
new Player(1, 'b'), | ||
]; | ||
let tournament = new Tournament(players); | ||
|
||
expect(tournament.numberNodes()).equal(2); | ||
}); | ||
|
||
it('Should return 4 as there are 3 player on the tournament.', function() { | ||
let players = [ | ||
new Player(0, 'a'), | ||
new Player(1, 'b'), | ||
new Player(2, 'c') | ||
]; | ||
let tournament = new Tournament(players); | ||
|
||
expect(tournament.numberNodes()).equal(4); | ||
}); | ||
|
||
it('Should return 16 as there are 9 player on the tournament.', function() { | ||
let players = [ | ||
new Player(0, 'a'), | ||
new Player(1, 'b'), | ||
new Player(2, 'c'), | ||
new Player(3, 'd'), | ||
new Player(4, 'e'), | ||
new Player(5, 'f'), | ||
new Player(6, 'g'), | ||
new Player(7, 'h'), | ||
new Player(8, 'i') | ||
]; | ||
let tournament = new Tournament(players); | ||
|
||
expect(tournament.numberNodes()).equal(16); | ||
}); | ||
|
||
it('Should return 32 as there are 31 player on the tournament.', function() { | ||
let players = []; | ||
for (let i = 0; i < 31; i++) { | ||
players.push(new Player(i, 'PogChamp')); | ||
} | ||
let tournament = new Tournament(players); | ||
|
||
expect(tournament.numberNodes()).equal(32); | ||
}); | ||
|
||
it('Should return 128 as there are 115 player on the tournament.', function() { | ||
let players = []; | ||
for (let i = 0; i < 115; i++) { | ||
players.push(new Player(i, 'PogChamp')); | ||
} | ||
let tournament = new Tournament(players); | ||
|
||
expect(tournament.numberNodes()).equal(128); | ||
}); | ||
|
||
it('Should return 1024 as there are 1000 player on the tournament.', function() { | ||
let players = []; | ||
for (let i = 0; i < 1000; i++) { | ||
players.push(new Player(i, 'PogChamp')); | ||
} | ||
let tournament = new Tournament(players); | ||
|
||
expect(tournament.numberNodes()).equal(1024); | ||
}); | ||
}); | ||
|
||
describe('generateBrackets', function() { | ||
it('As there are no players on the tournament, should throw error.', function() { | ||
let players: Player[] = []; | ||
let tournament = new Tournament(players); | ||
|
||
expect(function(){tournament.generateBrackets()}).to.throw(Error, "Players array can't be empty."); | ||
}); | ||
|
||
it('As there is 1 players on the tournament, should return the right bracket.', function() { | ||
let players = [ | ||
new Player(0, 'a') | ||
]; | ||
let tournament = new Tournament(players); | ||
|
||
expect(function(){tournament.generateBrackets()}).to.throw(Error, "Must have more then 1 player."); | ||
}); | ||
|
||
it('As there are 2 players on the tournament, should return the right bracket.', function() { | ||
let players = [ | ||
new Player(0, 'a'), | ||
new Player(1, 'b') | ||
]; | ||
let tournament = new Tournament(players); | ||
let brackets = tournament.generateBrackets(); | ||
|
||
expect(brackets[0].id).equal(0); | ||
expect(brackets[0].idChildren[0]).equal(1); | ||
expect(brackets[0].playerLeft).equal(undefined); | ||
expect(brackets[0].playerRight).equal(undefined); | ||
|
||
expect(brackets[1].id).equal(1); | ||
expect(brackets[1].idChildren[0]).equal(undefined); | ||
expect(brackets[1].playerLeft.id).equal(0); | ||
expect(brackets[1].playerLeft.name).equal('a'); | ||
expect(brackets[1].playerRight.id).equal(1); | ||
expect(brackets[1].playerRight.name).equal('b'); | ||
}); | ||
|
||
it('As there are 4 players on the tournament, should return the right bracket.', function() { | ||
let players = [ | ||
new Player(0, 'a'), | ||
new Player(1, 'b'), | ||
new Player(2, 'c'), | ||
new Player(3, 'd') | ||
]; | ||
let tournament = new Tournament(players); | ||
let brackets = tournament.generateBrackets(); | ||
|
||
expect(brackets[0].id).equal(0); | ||
expect(brackets[0].idChildren[0]).equal(1); | ||
expect(brackets[0].playerLeft).equal(undefined); | ||
expect(brackets[0].playerRight).equal(undefined); | ||
|
||
expect(brackets[1].id).equal(1); | ||
expect(brackets[1].idChildren[0]).equal(2); | ||
expect(brackets[1].idChildren[1]).equal(3); | ||
expect(brackets[0].playerLeft).equal(undefined); | ||
expect(brackets[0].playerRight).equal(undefined); | ||
|
||
expect(brackets[2].id).equal(2); | ||
expect(brackets[2].idChildren[0]).equal(undefined); | ||
expect(brackets[2].playerLeft.id).equal(0); | ||
expect(brackets[2].playerLeft.name).equal('a'); | ||
expect(brackets[2].playerRight.id).equal(1); | ||
expect(brackets[2].playerRight.name).equal('b'); | ||
|
||
expect(brackets[3].id).equal(3); | ||
expect(brackets[3].idChildren[0]).equal(undefined); | ||
expect(brackets[3].playerLeft.id).equal(2); | ||
expect(brackets[3].playerLeft.name).equal('c'); | ||
expect(brackets[3].playerRight.id).equal(3); | ||
expect(brackets[3].playerRight.name).equal('d'); | ||
}); | ||
}) | ||
|
||
describe('setWinnerMatch', function() { | ||
it('If id of match doesnt exist, must throw.', function() { | ||
let players = [ | ||
new Player(0, 'a'), | ||
new Player(1, 'b'), | ||
new Player(2, 'c'), | ||
new Player(3, 'd') | ||
]; | ||
let tournament = new Tournament(players); | ||
tournament.generateBrackets(); | ||
|
||
expect(function(){tournament.setWinnerMatch(5, 0);}).to.Throw("Match not found."); | ||
}) | ||
|
||
it('If id of player doesnt exist inside the match, must throw.', function() { | ||
let players = [ | ||
new Player(0, 'a'), | ||
new Player(1, 'b'), | ||
new Player(2, 'c'), | ||
new Player(3, 'd') | ||
]; | ||
let tournament = new Tournament(players); | ||
tournament.generateBrackets(); | ||
|
||
expect(function(){tournament.setWinnerMatch(2, 2);}).to.Throw("Winner's ID not found."); | ||
}) | ||
|
||
it('Should pass the winner to the next match and respect the right position.', function() { | ||
let players = [ | ||
new Player(0, 'a'), | ||
new Player(1, 'b'), | ||
new Player(2, 'c'), | ||
new Player(3, 'd') | ||
]; | ||
let tournament = new Tournament(players); | ||
tournament.generateBrackets(); | ||
tournament.setWinnerMatch(2, 2); | ||
|
||
// Continue from here. | ||
}) | ||
}) | ||
|
||
describe('findMatch', function() { | ||
it('', function() { | ||
|
||
}) | ||
}) | ||
}); |
Oops, something went wrong.