欢迎访问宙启技术站
智能推送

使用gen_test()函数生成Python程序中的随机测试数据

发布时间:2024-01-02 12:30:58

def gen_test():

    """

    This function generates random test data for a Python program and provides usage examples.

    Example usage:

    >>> test_data = gen_test()

    >>> print(test_data)

    Outputs:

    {'input': 10, 'output': 20}

    :return: dict containing randomly generated test data

    """

    import random

    # Generate random input

    input_data = random.randint(1, 100)

    # Perform some operations on the input to get the output

    output_data = input_data * 2

    # Return the generated test data as a dictionary

    return {"input": input_data, "output": output_data}

    

test_data = gen_test()

print(test_data)

# Output:

# {'input': 10, 'output': 20}