Juan-Carlos Gandhi (
juan_gandhi) wrote2020-08-23 09:18 pm
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Entry tags:
TWIMC: tests using random and current time
So, if you think you call a function in your code, and this function returns current time, or a random number... IT'S NOT A FUNCTION. Your code is function of "random number", or "time".
So, if your code is written as something that retrieves this kind of data, to test your code, you should provide that data. Not just today, but try the time, like 10 years from now. As to "random", You provide the randomness. If your code cannot be fixed to behave as a function of those inputs, make your "random stream" or "time stream" not hard-coded, but substitutable. Mockable. And mock it in your tests. MAKE SURE that you don't provide just happy-path data. Provide anything. A sequence of 100 numbers 4 for random. Time that is 10 years from now. Or even 30 yeas from now.
Make sure that your tests don't depend on anything. Because test Must Be Reproducible.
All these things, I know, are obvious to some, and not obvious to others.
So, if your code is written as something that retrieves this kind of data, to test your code, you should provide that data. Not just today, but try the time, like 10 years from now. As to "random", You provide the randomness. If your code cannot be fixed to behave as a function of those inputs, make your "random stream" or "time stream" not hard-coded, but substitutable. Mockable. And mock it in your tests. MAKE SURE that you don't provide just happy-path data. Provide anything. A sequence of 100 numbers 4 for random. Time that is 10 years from now. Or even 30 yeas from now.
Make sure that your tests don't depend on anything. Because test Must Be Reproducible.
All these things, I know, are obvious to some, and not obvious to others.
If you still have questions, ask. But don't argue. Because what I say is math. Unless you have another math (some people do), or another logic (there's plenty of them), please don't argue.
I'd be glad to see how all this changes if logic is e.g. linear.
Re: Infallible teacher
No. Because you need to have a certain level of expertise to argue. Go ahead, demonstrate your expertise.
Re: Infallible teacher
I demonstrated my expertise.
Unfortunately, today you are unwilling to comprehend it.
What kind of demonstration would convince you?
Re: Infallible teacher
I see that it's bullshit. That's it. There's nothing to comprehend. Bullshit. If you learned some math, or something, you would see it yourself.
Re: Infallible teacher
If it is bullshit -- then there should be clear mistakes that are not too hard to identify.
But you are not identifying these mistakes.
> If you learned some math, or something, you would see it yourself.
1) I did learn some math.
2) I do not see how what I wrote is "bullshit".
3) Therefore your statement is incorrect.
4) Furthermore, unit tests are about programming and only tangentially about math.
Re: Infallible teacher
I identified the mistakes, that's why I wrote the post. The fact that you do not understand shit is none of my business. You don't have the right education; okay. None of my business. You want to learn - learn. You don't want to learn - ok, your business. I really don't care. You may have learned wrong math, or actually did not learn it, or forgot it, I don't know. I'm not your teacher. You are on your own.
There are many people here, in this network, that learned a lot during these last 10-15 years. You learned nothing in that area, math, programming, etc. Not my responsibility, really. You had time. You still have time. Get back in 5 years, we will see if you learned something. Now your knowledge is close to zero.