There are some areas of applications (for example, GameDev) in which many functions must be created using random values ββto output their results. One example is given below:
def generate_key(monster_key_drop_coef):
key_letters = string.ascii_uppercase
rand = random.random()
if monster_key_drop_coef < rand:
return None
button = {}
button["type"] = random.choice([1,2,3])
button["letter"] = random.choice(key_letters)
return button
This function generates an element drop based on several random operations. The problem arises if you want to automatically check the correctness of this function. The generated values ββare not deterministic, and recording regression tests seems impossible.
My questions:
- Is it possible to write useful regression tests for this type of function?
- Is there a general approach for creating some other types of tests in this case?
source