There are some application domains(e.g. GameDev) in which a lot of functions should be created using random values for producing their output. One of examples is presented 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 the item's drop based on several random operations. The problem appears if you want to validate automatically correctness of this function. Generated values are not deterministic and writing of regression tests seems to be impossible.
My questions are:
- Is this possible to write useful regression tests for this type of functions?
- Is there any general approach for creating some other type of tests in this case?