jQuery in Action, 2nd edition*
The moose likes Testing and the fly likes Why is it telling me that the two arrays are not the same? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Why is it telling me that the two arrays are not the same?" Watch "Why is it telling me that the two arrays are not the same?" New topic
Author

Why is it telling me that the two arrays are not the same?

Ahmed Samir Saleh
Greenhorn

Joined: Mar 07, 2013
Posts: 6
Skill[] Skills is an array of skills defined as an instance variable

public void setSkills(Skill []skills){
this.Skills=new Skill[skills.length];
for(int i=0;i<skills.length;i++){
this.Skills[i]=skills[i];
this.skillCount++;
}

}
public Skill[] getSkills(){
if (this.skillCount==0)
return null;
return this.Skills;
}
The test:
Test(timeout = 1000)
public void testGetSkills() {
instance.setSkills(skills);
assertSame("The returned skill array should be the same", instance.getSkills(), skills);
}
The failure:
java.lang.AssertionError: The returned skill array should be the same expected same:<[Leg.edu.guc.lol.game.champions.Skill;@1a8c4e7> was not:<[Leg.edu.guc.lol.game.champions.Skill;@1172e08>


Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3498
    
  13
Does this help ?


Joanne
Ahmed Samir Saleh
Greenhorn

Joined: Mar 07, 2013
Posts: 6
i already saw it before posting. i have a problem referring Skills array to the method parameter (input) skill array(i want them to refer to the same thing).(i mean i tried to write this.Skills=skills without the for loop, but it didnt work )
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3498
    
  13
Ahmed Samir Saleh wrote:i mean i tried to write this.Skills=skills without the for loop, but it didnt work

ItDoesntWorkIsUseless
Ahmed Samir Saleh
Greenhorn

Joined: Mar 07, 2013
Posts: 6
Joanne Neal wrote:
Ahmed Samir Saleh wrote:i mean i tried to write this.Skills=skills without the for loop, but it didnt work

ItDoesntWorkIsUseless


i made the setSkill method like that:
public void setSkills(Skill []skills){
this.Skills=new Skill[skills.length];
this.Skills=skills;
}
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3498
    
  13
Ahmed Samir Saleh wrote:
Joanne Neal wrote:
Ahmed Samir Saleh wrote:i mean i tried to write this.Skills=skills without the for loop, but it didnt work

ItDoesntWorkIsUseless


i made the setSkill method like that:

Okay. Apart from the creation of a new array on line 2 being redundant, what was the problem with this ?
Ahmed Samir Saleh
Greenhorn

Joined: Mar 07, 2013
Posts: 6
the problem is that the assertSame tells me that the two arrays are not equal and i need them to be the same but i dont know how.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3498
    
  13



Ahmed Samir Saleh wrote:the problem is that the assertSame tells me that the two arrays are not equal and i need them to be the same but i dont know how.

So when you had the setSkills method like this, how did you implement the getSkills method ? Was it the same as in your original post ?
Ahmed Samir Saleh
Greenhorn

Joined: Mar 07, 2013
Posts: 6

Ahmed Samir Saleh wrote:the problem is that the assertSame tells me that the two arrays are not equal and i need them to be the same but i dont know how.

So when you had the setSkills method like this, how did you implement the getSkills method ? Was it the same as in your original post ?


yes, exactly
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3498
    
  13
Well in your setSkills method you no longer alter the value of skillCount, so it would have its default value of 0. What does getSkills return if skillCount is 0 ?
Ahmed Samir Saleh
Greenhorn

Joined: Mar 07, 2013
Posts: 6
Joanne Neal wrote:Well in your setSkills method you no longer alter the value of skillCount, so it would have its default value of 0. What does getSkills return if skillCount is 0 ?

yes i know that is another problem but its solvable. i can make a counter for each skill in the Skills array. but the main problem is that i cant make the skills array equals to the Skills array (which is an instance variable) so it wont give me an assertion error
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3498
    
  13
Ahmed Samir Saleh wrote:
Joanne Neal wrote:Well in your setSkills method you no longer alter the value of skillCount, so it would have its default value of 0. What does getSkills return if skillCount is 0 ?

yes i know that is another problem but its solvable. i can make a counter for each skill in the Skills array. but the main problem is that i cant make the skills array equals to the Skills array (which is an instance variable) so it wont give me an assertion error

But in your assertSame statement you are comparing your skills array with what the getSkills method returns. So I ask you again, what does the getSkills method return if skillCount is 0 ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why is it telling me that the two arrays are not the same?