def setUp(self): self.table = Table() self.table.addPlayer("rohit") self.table.addPlayer("akhil") self.table.addPlayer("anshuman") self.table.addPlayer("suket") self.table.addPlayer("ray")
def setUp(self): self.table = Table() self.table.addPlayer("rohit") self.table.addPlayer("opponent") self.deck = self.table.deck # set high and low representatives of each type of hand self.hand = [] self.opponentsHand = []
FROM Employee GROUP BY department; CREATE VIEW DepartmentView AS SELECT l.id, l.name, l.manager_name, r.total_salary FROM __join_1 l LEFT JOIN __aggregate_1 r ON l.id=r.department; """ import gevent from engine import Table #from engine.aggregate import Sum Department = Table('Department', { 'id': int, 'name': str, 'manager': int, }) Employee = Table('Employee', { 'id': int, 'name': str, 'department': int, 'salary': int, }) # __join_1 = LeftJoin('__join_1', Department, 'manager', Employee, 'id', { # 'id': 'id', # 'name': 'name'}, { # 'manager_name': 'name', # })
class PokerTestCase(unittest.TestCase): def setUp(self): self.table = Table() self.table.addPlayer("rohit") self.table.addPlayer("akhil") self.table.addPlayer("anshuman") self.table.addPlayer("suket") self.table.addPlayer("ray") # self.table.addPlayer("siddharth") # self.table.addPlayer("pete") # def tearDown(self): # self.table = Table() # verify starting state of table/game def test_startingState(self): print "testing starting state:" self.assertEqual(self.table.pot, 0) self.assertEqual(self.table.dealerPosition, 0) self.assertEqual(self.table.actionPosition, 0) self.assertEqual(self.table.round, 0) self.assertEqual(len(self.table.deck.deck), 52) # verify that currentPlayers updates player objects correctly def test_currentPlayers(self): print "testing currentPlayers list:" self.table.setCurrentPlayers() self.assertEqual(self.table.allPlayers, self.table.currentPlayers) self.table.currentPlayers[0].stack += 100 # alter player object self.table.addPlayer("ishan") # alter main list self.assertEqual(self.table.allPlayers[0],self.table.currentPlayers[0]) # make sure currentPlayers holds references self.assertNotEqual(self.table.allPlayers, self.table.currentPlayers) # verify that positions increment and overrun properly def test_incrementPosition(self): print "testing incrementPosition:" pos = 3 pos = self.table.incrementPosition(pos,6) self.assertEqual(pos,4) pos = 3 pos = self.table.incrementPosition(pos,4) # should rollover to beginning index self.assertEqual(pos,0) # verify that hand starts in appropriate state for players and hands # tests table.startHand() def test_handStartConditions(self): # test pre-start conditions for player in self.table.allPlayers: self.assertEqual(player.currentBet,0,"player bet not set to 0 before hand starts") self.assertEqual(self.table.pot,0) # test that betting continues and ends properly in all scenarios (folds all around, check all around, raise all around, and all combinations thereof) # tests table.processPlayerAction() over multiple players def test_roundBetting(self): pass # verify that player's actions are processed appropriately # tests table.processPlayerAction internally def test_processPlayerAction(self): print "testing processPlayerAction" self.table.startHand() # print self.table lastActionPosition = self.table.actionPosition while self.table.actionPosition != self.table.bigBlindPosition: self.table.processPlayerAction(self.table.currentPlayers[self.table.actionPosition],"call") self.table.processPlayerAction(self.table.currentPlayers[self.table.actionPosition],"check") self.table.endBettingRound() self.assertEqual(self.table.pot,10) self.assertEqual(self.table.actionPosition,self.table.smallBlindPosition) self.assertEqual(self.table.round,2) # print self.table def test_fullHand(self): print "testing test_fullHand" self.table.startHand() print self.table self.table.showFlop() lastActionPosition = self.table.actionPosition while self.table.actionPosition != self.table.bigBlindPosition: self.table.processPlayerAction(self.table.currentPlayers[self.table.actionPosition],"call") self.table.processPlayerAction(self.table.currentPlayers[self.table.actionPosition],"check") self.table.endBettingRound() self.table.showTurn() lastActionPosition = self.table.actionPosition self.table.processPlayerAction(self.table.currentPlayers[self.table.actionPosition],"raise",10) while self.table.actionPosition != lastActionPosition: self.table.processPlayerAction(self.table.currentPlayers[self.table.actionPosition],"call") self.table.endBettingRound() self.table.showRiver() self.table.endHand()
class PokerTestCase(unittest.TestCase): def setUp(self): self.table = Table() self.table.addPlayer("rohit") self.table.addPlayer("opponent") self.deck = self.table.deck # set high and low representatives of each type of hand self.hand = [] self.opponentsHand = [] def tearDown(self): del self.hand[:] del self.opponentsHand[:] def test_straightFlush(self): print "test_straightFlush" # straight flush vs. straight flush openCards = [] openCards.append(self.deck.getSpecificCard(11,1)) openCards.append(self.deck.getSpecificCard(12,1)) openCards.append(self.deck.getSpecificCard(10,1)) openCards.append(self.deck.getSpecificCard(4,2)) # irrelevant card openCards.append(self.deck.getSpecificCard(3,2)) # irrelevant card self.hand.append(self.deck.getSpecificCard(14,1)) self.hand.append(self.deck.getSpecificCard(13,1)) self.opponentsHand.append(self.deck.getSpecificCard(9,2)) self.opponentsHand.append(self.deck.getSpecificCard(8,2)) self.assertTrue(evaluator.isFlush(openCards+self.hand)) self.assertTrue(evaluator.isStraightFlush(openCards+self.hand)) self.assertEqual(evaluator.determineWinningHand(self.hand,self.opponentsHand,openCards),1) # print self.hand # print self.opponentsHand # print openCards def test_quads(self): print "test_quads" openCards = [] openCards.append(self.deck.getSpecificCard(9,0)) openCards.append(self.deck.getSpecificCard(9,1)) openCards.append(self.deck.getSpecificCard(10,1)) # irrelevant card openCards.append(self.deck.getSpecificCard(4,2)) # irrelevant card openCards.append(self.deck.getSpecificCard(3,2)) # irrelevant card self.hand.append(self.deck.getSpecificCard(9,2)) self.hand.append(self.deck.getSpecificCard(9,3)) self.opponentsHand.append(self.deck.getSpecificCard(4,2)) self.opponentsHand.append(self.deck.getSpecificCard(4,0)) self.assertEqual(evaluator.determineWinningHand(self.hand,self.opponentsHand,openCards),1) self.assertTrue(evaluator.isQuads(openCards+self.hand)) def test_fullHouse(self): print "test_fullHouse" openCards = [] openCards.append(self.deck.getSpecificCard(9,0)) openCards.append(self.deck.getSpecificCard(9,1)) openCards.append(self.deck.getSpecificCard(10,1)) openCards.append(self.deck.getSpecificCard(4,2)) # irrelevant card openCards.append(self.deck.getSpecificCard(3,2)) # irrelevant card self.hand.append(self.deck.getSpecificCard(9,2)) self.hand.append(self.deck.getSpecificCard(10,3)) self.opponentsHand.append(self.deck.getSpecificCard(2,2)) self.opponentsHand.append(self.deck.getSpecificCard(2,0)) self.assertEqual(evaluator.determineWinningHand(self.hand,self.opponentsHand,openCards),1) self.assertTrue(evaluator.isFullHouse(openCards+self.hand)) def test_flush(self): print "test_flush" openCards = [] openCards.append(self.deck.getSpecificCard(3,3)) openCards.append(self.deck.getSpecificCard(7,3)) openCards.append(self.deck.getSpecificCard(10,2)) openCards.append(self.deck.getSpecificCard(8,3)) openCards.append(self.deck.getSpecificCard(13,3)) self.hand.append(self.deck.getSpecificCard(4,2)) self.hand.append(self.deck.getSpecificCard(10,3)) self.opponentsHand.append(self.deck.getSpecificCard(3,2)) self.opponentsHand.append(self.deck.getSpecificCard(7,0)) self.assertEqual(evaluator.determineWinningHand(self.hand,self.opponentsHand,openCards),1) self.assertTrue(evaluator.isFlush(openCards+self.hand)) def test_straight(self): print "test_straight" openCards = [] openCards.append(self.deck.getSpecificCard(3,1)) openCards.append(self.deck.getSpecificCard(4,1)) openCards.append(self.deck.getSpecificCard(5,2)) openCards.append(self.deck.getSpecificCard(10,0)) openCards.append(self.deck.getSpecificCard(13,3)) self.hand.append(self.deck.getSpecificCard(6,2)) self.hand.append(self.deck.getSpecificCard(7,3)) self.opponentsHand.append(self.deck.getSpecificCard(7,2)) self.opponentsHand.append(self.deck.getSpecificCard(8,0)) self.assertEqual(evaluator.determineWinningHand(self.hand,self.opponentsHand,openCards),1) self.assertTrue(evaluator.isStraight(openCards+self.hand)) def test_triple(self): print "test_triple" openCards = [] openCards.append(self.deck.getSpecificCard(3,1)) openCards.append(self.deck.getSpecificCard(4,1)) openCards.append(self.deck.getSpecificCard(5,2)) openCards.append(self.deck.getSpecificCard(10,0)) openCards.append(self.deck.getSpecificCard(13,3)) self.hand.append(self.deck.getSpecificCard(3,2)) self.hand.append(self.deck.getSpecificCard(5,3)) self.opponentsHand.append(self.deck.getSpecificCard(4,2)) self.opponentsHand.append(self.deck.getSpecificCard(4,0)) self.assertEqual(evaluator.determineWinningHand(self.hand,self.opponentsHand,openCards),-1) self.assertTrue(evaluator.isTriple(openCards+self.opponentsHand)) def test_twoPair(self): print "test_twoPair" openCards = [] openCards.append(self.deck.getSpecificCard(3,1)) openCards.append(self.deck.getSpecificCard(4,1)) openCards.append(self.deck.getSpecificCard(5,2)) openCards.append(self.deck.getSpecificCard(10,0)) openCards.append(self.deck.getSpecificCard(13,3)) self.hand.append(self.deck.getSpecificCard(3,2)) self.hand.append(self.deck.getSpecificCard(5,3)) self.assertTrue(evaluator.isTwoPair(openCards+self.hand)) def test_onePair(self): print "test_onePair" openCards = [] openCards.append(self.deck.getSpecificCard(3,1)) openCards.append(self.deck.getSpecificCard(4,1)) openCards.append(self.deck.getSpecificCard(5,2)) openCards.append(self.deck.getSpecificCard(10,0)) openCards.append(self.deck.getSpecificCard(13,3)) self.hand.append(self.deck.getSpecificCard(11,2)) self.hand.append(self.deck.getSpecificCard(10,3)) self.assertTrue(evaluator.isPair(openCards+self.hand)) def test_highCard(self): print "test_highCard" openCards = [] openCards.append(self.deck.getSpecificCard(3,1)) openCards.append(self.deck.getSpecificCard(4,1)) openCards.append(self.deck.getSpecificCard(5,2)) openCards.append(self.deck.getSpecificCard(10,0)) openCards.append(self.deck.getSpecificCard(13,3)) self.hand.append(self.deck.getSpecificCard(14,2)) self.hand.append(self.deck.getSpecificCard(7,3)) def test_misc(self): print "test_misc" openCards = [] openCards.append(self.deck.getSpecificCard(8,1)) openCards.append(self.deck.getSpecificCard(10,3)) openCards.append(self.deck.getSpecificCard(9,2)) openCards.append(self.deck.getSpecificCard(9,3)) openCards.append(self.deck.getSpecificCard(3,3)) self.hand.append(self.deck.getSpecificCard(14,2)) self.hand.append(self.deck.getSpecificCard(11,3)) self.opponentsHand.append(self.deck.getSpecificCard(6,3)) self.opponentsHand.append(self.deck.getSpecificCard(6,2)) # print self.hand # print self.opponentsHand # print openCards self.assertEqual(evaluator.determineWinningHand(self.hand,self.opponentsHand,openCards),-1)
from flask import Flask from flask import render_template from flask import request from flask import url_for from flask.ext.sqlalchemy import SQLAlchemy from engine import Table,Deck,Player app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/poker.db' db = SQLAlchemy(app) table = Table() table.addPlayer("computer1") table.addPlayer("computer2") table.addPlayer("computer3") table.addPlayer("computer4") table.addPlayer("computer5") @app.route('/', methods=['POST', 'GET']) def index(): # if request.method == "POST": # return url_for('game',playerName=request.form['player_name']) # if 'new_hand' in request.form: # currPlayer = table.currentPlayers[-1] # add player with # table.reset() # table.startHand() # for player in table.currentPlayers: # table.processPlayerAction(player,"call") # table.endBettingRound() # return render_template("game2.html",player=currPlayer,table=table)