-
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.
Criação dos modelos + inicio da lógica da criação dos brackets.
- Loading branch information
Renan Verissimo de vasconcelos
committed
Nov 13, 2018
1 parent
81a6e4e
commit 30455be
Showing
2 changed files
with
112 additions
and
5 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,8 +1,30 @@ | ||
import {assert} from 'chai'; | ||
describe('Array', function() { | ||
describe('#indexOf()', function() { | ||
it('should return -1 when the value is not present', function() { | ||
assert.equal([1,2,3].indexOf(4), -1); | ||
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('a', 1), | ||
new Player('a', 2), | ||
new Player('a', 3), | ||
new Player('a', 4), | ||
new Player('a', 5), | ||
new Player('a', 6), | ||
new Player('a', 7), | ||
new Player('a', 0), | ||
new Player('a', 1), | ||
new Player('a', 2), | ||
new Player('a', 3), | ||
new Player('a', 4), | ||
new Player('a', 5), | ||
new Player('a', 6), | ||
new Player('a', 7), | ||
] | ||
|
||
let champ = new Tournament(players); | ||
let graph = champ.generateBrackets(); | ||
//expect(graph[0].idParent).equals("Kappa"); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
export class Player { | ||
public id: number; | ||
public name: string; | ||
|
||
constructor(name: string, id: number) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
} | ||
|
||
class Node { | ||
public id: number; | ||
public idChilden: any; | ||
public playerLeft: any; | ||
public playerRight: any; | ||
|
||
constructor(id: number, idChilden?: Array<number>, playerLeft?: Player, playerRight?: Player) { | ||
this.id = id; | ||
this.idChilden = idChilden; | ||
this.playerLeft = playerLeft; | ||
this.playerRight = playerRight; | ||
} | ||
|
||
public addParent(ids: Array<number>) { | ||
this.idChilden = ids; | ||
} | ||
|
||
public addPlayerLeft(player: Player) { | ||
this.playerLeft = player; | ||
} | ||
|
||
public addPlayerRight(player: Player) { | ||
this.playerRight = player; | ||
} | ||
} | ||
|
||
class NodeWinner extends Node { | ||
public playerWinner: any; | ||
|
||
constructor(id: number, idChilden?: Array<number>, winner?: Player) { | ||
super(id, idChilden); | ||
this.playerWinner = winner; | ||
} | ||
} | ||
|
||
export class Tournament { | ||
public name: any; | ||
public players: Array<Player>; | ||
|
||
constructor(players: Array<Player>, name?: string) { | ||
this.name = name || 'Bracketzada Tournament'; | ||
this.players = players; | ||
} | ||
|
||
private _numberNodes(numberPlayers: number) : number { | ||
return Math.pow(2, Math.ceil(Math.log2(numberPlayers))); | ||
} | ||
|
||
private _generateGraph(numNodes: number) { | ||
let graph = []; | ||
|
||
//Winner Node | ||
graph.push(new NodeWinner(0, [1])); | ||
|
||
let actualParent = 1; | ||
for (let i = 1; i < numNodes; i++) { | ||
graph.push( | ||
new Node(i, [actualParent, actualParent+1]) | ||
) | ||
} | ||
|
||
//this._setPlayers(graph, this.players); | ||
|
||
} | ||
|
||
private _setPlayers(graph: Array<Node>, players: Array<Player>) { | ||
|
||
} | ||
|
||
public generateBrackets() { | ||
let numNodes = this._numberNodes(this.players.length); | ||
let graph = this._generateGraph(numNodes); | ||
|
||
} | ||
} |