Am new in unit testing, I have a function which doesn't return anything and generates numbers randomly from a certain number to another, I read about the mocking library but it's still confusing to me, how can I unit test this function.
What I want to test
- Testing if numbers are generated between
1000
and8876
. - Checking the positions of different numbers with a 4 -digit values are not equal to each other. e.g
1234
, this number is allowed because it has no repetitions. but1123
is not allowed because it has a number repeated in different positions. That's what thewhile
loop is doing.
I tried to read similar questions e.g link 1 link 2 but I couldn't connect to this scenario
def num(self):
random = randint(1000, 8876)
random = list(map(int, str(random)))
while random[0] == random[1] or random[0] == random[2] or random[0] == random[3] or random[1] == random[2] or random[1] == random[3] or random[2] == random[3]:
random = randint(1000, 8876)
random = list(map(int, str(random)))
num = ""
self.num = int(num.join(map(str,random)))