-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1147e1
commit 45cb4eb
Showing
3 changed files
with
39 additions
and
12 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
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,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) |
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