From 30455beaf961455188fc361e7c329945d87509f9 Mon Sep 17 00:00:00 2001 From: Renan Verissimo de vasconcelos Date: Tue, 13 Nov 2018 18:10:24 -0200 Subject: [PATCH] =?UTF-8?q?Cria=C3=A7=C3=A3o=20dos=20modelos=20+=20inicio?= =?UTF-8?q?=20da=20l=C3=B3gica=20da=20cria=C3=A7=C3=A3o=20dos=20brackets.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bracketzada.test.ts | 32 +++++++++++++--- src/bracketzada.ts | 85 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 5 deletions(-) diff --git a/src/bracketzada.test.ts b/src/bracketzada.test.ts index b2feb60..099470d 100644 --- a/src/bracketzada.test.ts +++ b/src/bracketzada.test.ts @@ -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"); }); }); }); \ No newline at end of file diff --git a/src/bracketzada.ts b/src/bracketzada.ts index e69de29..2be7f15 100644 --- a/src/bracketzada.ts +++ b/src/bracketzada.ts @@ -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, playerLeft?: Player, playerRight?: Player) { + this.id = id; + this.idChilden = idChilden; + this.playerLeft = playerLeft; + this.playerRight = playerRight; + } + + public addParent(ids: Array) { + 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, winner?: Player) { + super(id, idChilden); + this.playerWinner = winner; + } +} + +export class Tournament { + public name: any; + public players: Array; + + constructor(players: Array, 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, players: Array) { + + } + + public generateBrackets() { + let numNodes = this._numberNodes(this.players.length); + let graph = this._generateGraph(numNodes); + + } +} \ No newline at end of file