def test_lcg():
    """Test that LCG generator works."""

    lcg = LCGRand(346)

    assert lcg.rand() == 5815222

    assert lcg.rand() == 1099672039
def test_infinite_numbers():
    """Test that the infinite generator works."""
    lcg = LCGRand(3)
    true = [50421, 847425747, 572982925, 807347327, 1284843143, 1410633816]
    for i, (rand,
            target) in enumerate(zip(lcg.infinite_random_sequence(), true)):
        assert rand == target, "The random number was incorrect"
    assert i == len(true) - 1, "The sequence stopped by itself"

    for i, target in enumerate(lcg.infinite_random_sequence()):
        if i > 100:
            break
    else:
        assert False, "The random sequence stopped by itself"
def test_rand_iter():
    """Test that the iterator works."""
    lcg = LCGRand(3)
    true = [50421, 847425747, 572982925]
    for rand, target in zip(lcg.random_sequence(3), true):
        assert rand == target
示例#4
0
def test_lcg():

    lcg = LCGRand(346)
    assert lcg.rand() == 5815222
    assert lcg.rand() == 1099672039