Exemplo n.º 1
0
def test_generator_combined():
    my_generator = plate_generator.generator_combined(n=1000)
    for output in my_generator:
        assert isinstance(output.plate, plate_generator.core.Plate)
        assert isinstance(output.plate.name, list)
        assert isinstance(output.int, list)
    my_generator = plate_generator.generator_combined(n=1000)
    # check that at least some of the plates have been combined
    combined = 0
    for output in my_generator:
        assert len(output.plate.name) == len(output.int)
        if len(output.plate.name) > 1:
            combined += 1
    assert combined > 0
Exemplo n.º 2
0
def test_generator_combined_raises_invalid_op():
    with pytest.raises(ValueError):
        # NOTE: doesn't error on creating the variable, only when
        # actually iterating through the generator
        my_generator = plate_generator.generator_combined(100, op="//")
        for output in my_generator:
            pass
Exemplo n.º 3
0
def test_generator_combined_max_combinations():
    max_combinations = 3
    my_generator = plate_generator.generator_combined(
        n=1000, max_combinations=max_combinations)
    for output in my_generator:
        assert len(output.plate.name) <= max_combinations
    ###########
    max_combinations = 1
    my_generator = plate_generator.generator_combined(
        n=1000, max_combinations=max_combinations)
    for output in my_generator:
        assert len(output.plate.name) <= max_combinations
    #####
    max_combinations = 5
    my_generator = plate_generator.generator_combined(
        n=1000, max_combinations=max_combinations)
    for output in my_generator:
        assert len(output.plate.name) <= max_combinations
Exemplo n.º 4
0
def test_generator_combined_effect_list():
    funcs_to_use = [
        plate_generator.core.normal_plate,
        plate_generator.core.h_grad_plate,
        plate_generator.core.v_grad_plate,
    ]
    my_generator = plate_generator.generator_combined(n=1000,
                                                      effects=funcs_to_use)
    for output in my_generator:
        # always returned as a list, so get the first element
        assert output.int[0] in [0, 1, 2]
Exemplo n.º 5
0
def test_generator_combined_is_not_too_slow():
    # 1500 plates per second minimum
    time_limit = 10
    n = 15000
    my_generator = plate_generator.generator_combined(n)
    time_start = time()
    for plate in my_generator:
        _ = plate
    time_end = time()
    time_taken = abs(time_end - time_start)
    print(time_taken)
    assert time_taken <= time_limit
Exemplo n.º 6
0
def test_generator_effect_list():
    funcs_to_use = [
        plate_generator.core.normal_plate,
        plate_generator.core.h_grad_plate,
        plate_generator.core.v_grad_plate,
    ]
    my_generator = plate_generator.generator_combined(n=1000,
                                                      effects=funcs_to_use)
    for output in my_generator:
        for integer in output.int:
            assert integer in [0, 1, 2]
        for effect_name in output.plate.name:
            assert effect_name in ("random", "horizontal_gradient",
                                   "vertical_gradient")
Exemplo n.º 7
0
def test_generator_combined_correct_n():
    count = 0
    n = 1000
    for i in plate_generator.generator_combined(n=n):
        count += 1
    assert count == n
Exemplo n.º 8
0
def test_generator_combined_for_duplicate_classes():
    my_gen = plate_generator.generator_combined(n=10000)
    for i in my_gen:
        if len(i.plate.name) > 1:
            assert "random" not in i.plate.name
            assert len(i.plate.name) == len(set(i.plate.name))
Exemplo n.º 9
0
def test_generator_combined_random_size():
    my_generator = plate_generator.generator_combined(1000, size="either")
    sizes = []
    for plate in my_generator:
        sizes.append(plate.plate.size)
    assert len(Counter(sizes)) == 2
Exemplo n.º 10
0
def test_generator_combined_size():
    size = 384
    my_generator = plate_generator.generator_combined(1000, size=384)
    for output in my_generator:
        assert output.plate.size == 384