Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
julianandrews committed Sep 19, 2015
1 parent d1147e1 commit 45cb4eb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
13 changes: 2 additions & 11 deletions eval7/test.py → eval7/test_eval7.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,9 @@

import unittest
import eval7
import eval7.wh_rand


class TestEval7(unittest.TestCase):
def test_wh_random(self):
# 0.9s
result = {n: 0 for n in range(52)}
for i in xrange(1900000):
result[eval7.wh_rand.py_wh_randint(52)] += 1
for i in range(52):
self.assertAlmostEqual(result[i], 36500, delta=1000)

def test_hand_to_mask(self):
# Highest and lowest cards
cards = map(eval7.Card, ["As", "2c"])
Expand All @@ -35,8 +26,8 @@ def test_evaluate(self):
(['2c', '3h', '4h', '5s', 'Jh', '7h', '6h'], 84497441, 'Flush'),
(['Ac', '3h', 'Th', 'Ts', 'Ks', 'Kh', 'Kd'], 101416960, 'Full House'),
(['Ac', '3h', 'Th', 'Ks', 'Kh', 'Kd', 'Kc'], 118210560, 'Quads'),
(['3c', '2c', '5c', 'Ac', '4c', 'Kd', 'Kc'], 134414336, 'Straight Flush')
)
(['3c', '2c', '5c', 'Ac', '4c', 'Kd', 'Kc'], 134414336, 'Straight Flush'),
)
for card_strs, expected_val, expected_type in cases:
cards = map(eval7.Card, card_strs)
value = eval7.evaluate(cards)
Expand Down
36 changes: 36 additions & 0 deletions eval7/test_wh_rand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2014 Anonymous7 from Reddit, Julian Andrews
#
# This software may be modified and distributed under the terms
# of the MIT license. See the LICENSE file for details.

from __future__ import absolute_import, division

import unittest
from collections import Counter

import eval7.wh_rand


class WhRandTestCase(unittest.TestCase):
SAMPLE_RANGE = 52
SAMPLE_COUNT = 36500 * SAMPLE_RANGE
DELTA = 1000

def setUp(self):
self.results = Counter(eval7.wh_rand.py_wh_randint(self.SAMPLE_RANGE)
for i in range(self.SAMPLE_COUNT))

def test_rand_int_in_range(self):
allowed_values = list(range(52))
for i, count in self.results.items():
self.assertIn(i, allowed_values)

def test_rand_int_is_uniform(self):
expected_count = self.SAMPLE_COUNT / self.SAMPLE_RANGE
for i in range(self.SAMPLE_RANGE):
self.assertIn(i, self.results)
self.assertAlmostEqual(
self.results[i], expected_count, delta=self.DELTA
)

suite = unittest.TestLoader().loadTestsFromTestCase(WhRandTestCase)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
keywords='poker equity library',
packages=['eval7'],
ext_modules=extensions,
install_requires=['pyparsing'],
install_requires=['pyparsing', 'future'],
)

0 comments on commit 45cb4eb

Please sign in to comment.