forked from udacity/fullstack-nanodegree-vm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
completed essential coding, added some extra credit from udacity#1
- Loading branch information
1 parent
ebcbda6
commit 379ab19
Showing
4 changed files
with
192 additions
and
13 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Test cases for tournament.py | ||
|
||
|
||
from tournament import * | ||
import math | ||
|
||
|
||
def testRematches(): | ||
deleteMatches() | ||
deletePlayers() | ||
#change player count to anything greater than 4, tested up to 64 players | ||
playerCount = 16 | ||
i = 0 | ||
while i < playerCount: | ||
registerPlayer("P%d" % i) | ||
i += 1 | ||
tour_round = 1 | ||
rounds = math.log(playerCount, 2) | ||
print "Rounds=%d" % rounds | ||
while tour_round <= rounds: | ||
pairings = swissPairings() | ||
i = 0 | ||
print "Pairings:" | ||
print pairings | ||
while i < len(pairings): | ||
reportMatch(pairings[i][0], pairings[i][2]) | ||
players_matched = matchCount(pairings[i][0], pairings[i][2]) | ||
print players_matched | ||
i += 1 | ||
tour_round += 1 | ||
print "Standings:" | ||
print playerStandings() | ||
if False: | ||
raise ValueError( | ||
"Players should only meet in one match.") | ||
print """1. After one match, players with one win are paired, avoiding. | ||
rematches between players!""" | ||
# db.close() | ||
|
||
|
||
if __name__ == '__main__': | ||
testRematches() | ||
print "Success! Tests for extra credit pass!" | ||
|
||
|
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
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,9 +1,31 @@ | ||
-- Table definitions for the tournament project. | ||
-- | ||
-- Put your SQL 'create table' statements in this file; also 'create view' | ||
-- statements if you choose to use it. | ||
-- | ||
-- You can write comments in this file by starting them with two dashes, like | ||
-- these lines here. | ||
/* Tournament Project 2 is copyright 2015 Deanna M. Wagner. | ||
* DATABASE definition for the tournament project is found in tournament.sql file. | ||
* SQL 'CREATE TABLE' statements are in this file. | ||
*/ | ||
|
||
|
||
DROP DATABASE IF EXISTS tournament; | ||
CREATE database tournament; | ||
|
||
\c tournament; | ||
|
||
CREATE TABLE players ( | ||
id serial PRIMARY KEY NOT NULL, | ||
name varchar(80) NOT NULL ); | ||
|
||
CREATE TABLE matches ( | ||
match_id serial PRIMARY KEY NOT NULL, | ||
winner_id integer REFERENCES players(id), | ||
loser_id integer REFERENCES players(id) ); | ||
|
||
CREATE TABLE tournaments ( | ||
tour_id serial PRIMARY KEY NOT NULL, | ||
tour_name varchar(80) NOT NULL ); | ||
|
||
CREATE TABLE tournaments_players ( | ||
tournament_id integer REFERENCES tournaments(tour_id), | ||
player_id integer REFERENCES players(id) ); | ||
|
||
--Create View standings query | ||
|
||
\q |
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 |
---|---|---|
|
@@ -135,5 +135,3 @@ def testPairings(): | |
testReportMatches() | ||
testPairings() | ||
print "Success! All tests pass!" | ||
|
||
|