I have a Class with an array of int values in it and a method to shuffle an array.
I want to write a unit tests which would vefiry the array before and after the shuffling are not equal. Please advice what method of JUnit library should I use. Thank you very much in advance.
What method of JUnit? assertTrue (or assertFalse) and use an array comparison. I think there's also some array compares built in to later JUnit versions, too.
Of course, it would be completely possible for a shuffled array to have the same order as the original.
Well, OK. But what about general procedure? I can't use that approach because that is the only one array and there is no sense to compare it because the results will always be the same - arrays are equal.
Would it be OK to create a new array of the same type and size within a test class before any modifications with array and afterwards make comparisons using a copy of it?
Just in doubts is it a good practice to make any additional data in test methods...
You Gin wrote:Would it be OK to create a new array of the same type and size within a test class before any modifications with array and afterwards make comparisons using a copy of it?
Yes, you have no choice. You must use a copy of it, using for example Arrays#copyOf.