Random Output Test Functions

  • I am working on a test project for testing a library of neural networks ...
  • The problem is that random numbers are sometimes used in this library.
  • I need to get test cases (input, expected output, actual output) ...

Does anyone have an idea how to output test cases (input, expected output, actual output) to a function that uses random numbers when taking actions and evaluating outputs?

+2
source share
2 answers

, , , , .

( Python, ).

def test_random_number():
    total = sum(random.uniform(0, 1) for _ in xrange(1000))
    assert 100 < total < 900

, , , - , , .

"", .

class DefaultRandomBehavior(object):
    def pick_left_or_right(self):
        return random.choice(['left', 'right'])

class AardvarkModeller(object):
    def __init__(self, random_source=None):
        self.random_source = random_source or DefaultRandomBehavior()

    def aardvark_direction(self):
        r = self.random_source.pick_left_or_right()
        return 'The aardvark faces ' + r

unit test , DefaultRandomBehavior, .

+4

, , . , , , - , , "" , , . PRNG . .

(, , ) - . , , . , , , , - , .

+2

Source: https://habr.com/ru/post/1775734/


All Articles