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.
no subject
(no subject)
(no subject)
no subject
(no subject)
(no subject)
What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
"Should provide that data"?
Re: "Should provide that data"?
Nondeterministic function
Re: Nondeterministic function
Re: Nondeterministic function
Re: Nondeterministic function
Re: Nondeterministic function
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Re: What to test in time-dependent function?
Multiple separate places to modify code
Re: Multiple separate places to modify code
Re: Multiple separate places to modify code
Re: Multiple separate places to modify code
Re: Multiple separate places to modify code
Re: Multiple separate places to modify code
Re: Multiple separate places to modify code
Re: Multiple separate places to modify code
Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Re: Tests self-diagnostic
Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Признаки непонимания
Re: Признаки непонимания
Re: Признаки непонимания
Re: Признаки непонимания
Re: Признаки непонимания
Re: Признаки непонимания
Re: Признаки непонимания
Re: Признаки непонимания
Re: Признаки непонимания
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
"Mock" и "mocking" in programming
Re: "Mock" и "mocking" in programming
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
Re: Is full service test coverage possible with mocks?
no subject
Remember, remember the 19th of January 2038.
(no subject)
no subject
I am not sure I understand what one could do about it. How do you defend against this? Write a piece of code for validating the randoms provided are sufficiently random?
It makes more sense to write tests supposing the entropy is depleted. (and the rng device blocks indefinitely)
(no subject)
(no subject)
no subject
время есть область ответственности оси, прикладной софт не должно парить что где там переполнилось вообще
(no subject)
(no subject)
How to test nondeterministic functions
What you describe as "FUNCTION", is usually called "deterministic function".
~~~~~~~~~~
https://www.google.com/search?q=deterministic+function
Deterministic functions always return the same result any time they are called with a specific set of input values and given the same state of the database.
~~~~~~~~~~
Why did you chose using non-standard "function" label for "deterministic function" concept?
> So, if your code is written as something that retrieves this kind of data, to test your code, you should provide that data.
Not necessarily.
It depends on what exactly we are testing.
For example, if it is sufficient for us to test that nondeterministic function output contains specific phrase that does not depend on random input -- why should we provide random data to that test?
> Make sure that your tests don't depend on anything.
Test that does not depend on anything - does not test production code.
Do you use non-standard definition of word "anything" or phrase "don't depend"?
Re: How to test nondeterministic functions
Re: How to test nondeterministic functions
Re: How to test nondeterministic functions
Re: How to test nondeterministic functions
Re: How to test nondeterministic functions
"Idiots" sign
Re: "Idiots" sign
Re: "Idiots" sign
Re: "Idiots" sign
Sings of understanding
Re: Sings of understanding
Re: Sings of understanding
Re: Sings of understanding
The book
Re: The book
Re: The book
Re: The book
Re: The book
Re: How to test nondeterministic functions
Is "nondeterministic function" a useful concept
Re: Is "nondeterministic function" a useful concept
Re: Is "nondeterministic function" a useful concept
Re: Is "nondeterministic function" a useful concept
Re: Is "nondeterministic function" a useful concept
Re: Is "nondeterministic function" a useful concept
Re: Is "nondeterministic function" a useful concept
Re: Is "nondeterministic function" a useful concept
Usage of term "deterministic function"
Sweeping the uncomfortable facts under the carpet
Misunderstanding question
Re: "то есть" trick
Expecting answers to unasked questions
Re: Expecting answers to unasked questions
Re: Expecting answers to unasked questions
Re: "то есть" trick
Infallible teacher
Because you are perfect and cannot make mistakes, right?
Re: Infallible teacher
Re: Infallible teacher
Re: Infallible teacher
Re: Infallible teacher
Re: Infallible teacher
no subject
Мне очевидно, что любое конечное количество моков - это happy path при бесконечном оригинале.
Ну и так же, что все, что придумает конкретный программист, - это тоже happy path, т.к. он уже это придумал, и значит предусмотрел в коде.
Я считаю, что тесты бывают только двух видов: integration - что реально видит наш юзер и regression - настоящий un-happy path из баг репортов. Все остальное - карго культ.