File: testnumbergen.py

package info (click to toggle)
python-param 2.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,048 kB
  • sloc: python: 17,980; makefile: 3
file content (35 lines) | stat: -rw-r--r-- 890 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
Test cases for the numbergen module.
"""
import unittest

import numbergen

_seed = 0  # keep tests deterministic
_iterations = 1000


class TestUniformRandom(unittest.TestCase):
    def test_range(self):
        lbound = 2.0
        ubound = 5.0
        gen = numbergen.UniformRandom(
                seed=_seed,
                lbound=lbound,
                ubound=ubound)
        for _ in range(_iterations):
            value = gen()
            self.assertTrue(lbound <= value < ubound)


class TestUniformRandomOffset(unittest.TestCase):
    def test_range(self):
        lbound = 2.0
        ubound = 5.0
        gen = numbergen.UniformRandomOffset(
                seed=_seed,
                mean=(ubound + lbound) / 2,
                range=ubound - lbound)
        for _ in range(_iterations):
            value = gen()
            self.assertTrue(lbound <= value < ubound)