• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What unit test would it be?

 
You Gin
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Moving to the testing forum.
 
You Gin
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...

Hope I was clear Thanks!
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
You Gin
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that is what I needed to know actually.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic