-
Notifications
You must be signed in to change notification settings - Fork 0
Introduce CustomDataProvider #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- 10 and 100 of values from 1 to 99 - 10 fo values from 1 to 999
|
🤦 Overcomplicate StuffYou could write fancy scripts and trow magical awk commands onto files that are so large that they crash your IDE. Or just stick to the basics. May i present the new version of "I need arrays": $numbers = range(1, 999); // Create an array of numbers from 1 to 999
for ($i=0; $i<10; $i++) {
shuffle($numbers); // Randomly shuffle the array
print_r(json_encode([$numbers]). ","); // Print the array inside an array and add a comma
}Copy the output and add it to an array and return it. Autoformatting will make it pretty in the end and everything takes less then a few secods. |



💡🤔 Idea
Since every logic, method and class serve a single process, namly the sorting of numbers, the test ware easily written. But since the basicly all test the same functionality, the tests evolve to be a copy of a copy of a copy...
This may or may not lead to some inconsistency in the future and therefor not the perfect condition to have results that match accross the board on every testrun and deliver comparable values accross the different algorithms used.
🔍🕵️ Basics
Since the easiest test for a sorting algorithm is to randomize a array and compare it to the original, the most simple solution would be to do exactly this. This leads to two simple problems:
range(1,9)would be approved by him but it should be kept to a minimum.🔬📈 Path to and Solution
The best way to provide data to the tests was already impelemented. Hardcoding arrays and providing them to the classes to expect a result-array that is either also hard coded or expected to be the previously mentioned
range(x,y)ist simple but effective. Just make sure to use the same array in every test and there is no problem.This howevery violates the DRY Principle and like this and having the fact in mind, that some day or time in the future the data which are used for test would have to change, this PR was born.
🎯 Focus on the basics
Since the best way to test was already implemented, the only thing left to do is to collect the data in one place and distribute it among the tests. This was how it startet and The now called
CustomDataProviderwas implemented. But keeping it simple should have been just the beginning.1️⃣ Iteration
Write a method that returns a bunch of predefined arrays and be done with it. Generating a permutation of every combination of the numbers between 1 and 9 proved to be more difficult then initially expected. 362880 elements more difficult to be exact (definetly not recommend trying to copy paste that stuff using PHPStrom). But the generation worked:
After that it was as simple as retrieving random lines from
permutations.txtand dumping them into the return of the method.Here the command for that with 10 arrays:
And since nobody likes to instantioate that thing, just make them static to beginn with.
2️⃣ Make it fancy
But what if we would like to have variance in our provided data? Maybe have different test pipelines, small once that give imidiate feedback while developing? The thing should provide a level of compfort. Allow the method to take a number and return array sizes based on that. But nobody whats to write endless amount of static code into his project, just so someone may want a dataprovider with 1337 elements just to be funny. So downhill we go:
3️⃣ Go absolutly bonkers
With the implementation for a dataprovider that returns array in the range of 1 to 9 in sizes of 1, 10 and 1000 done the next logical step was clear. Make the numbers to up Up Up
There we have it. The methods
oneToNine,oneToNineNineandoneToNineNineNinewhere there and my sleep was gone.🪦💀 Final words
The feature nobody asked for in overdone is done. If it makes any sence is for you to diced and for me to sleep over. Sadness and sorrow to the fellows of
oneToNineNineandoneToNineNineNinewhich got only a single array to provide but that should be fixable if I am allowed to push such stuff.Until then happy review and Good Night 🌃