mercredi 28 janvier 2015

How to write Unit test, branch test, condition, branch and relational operator, definition use criteria for class writen in JAVA

I have to write unit test, branch test, condition.... but i have no idea how to do that Can someone help me ? I am beginner and i really don't understand testing... I read some simple examples given by the professor but this one...



class IntegerArray {

private int a[];

public IntegerArray(int a[]) {
this.a = Arrays.copyOf(a, a.length);
}

private IntegerArray(int a[],boolean to_copy) {
if ( to_copy )
this.a = a;
else
this.a = Arrays.copyOf(a, a.length);
}

public int length() {
return a.length;
}

public int getElementAt(int i) {
return a[i];
}

public int sum() {
int sum = 0;
for ( int e : a ) sum += e;
return sum;
}

public double average() {
return sum()*1.0/length();
}

public IntegerArray getSorted() {
int sorted_a[] = Arrays.copyOf(a, length());
Arrays.sort(sorted_a);
return new IntegerArray(sorted_a);
}

public IntegerArray concat(IntegerArray ia) {
int res_a[] = new int[a.length+ia.a.length];
System.arraycopy(a, 0, res_a, 0, a.length);
System.arraycopy(ia.a, 0, res_a, a.length, ia.a.length);
return new IntegerArray(res_a,true);
}

public String toString() {
return Arrays.toString(a);
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Arrays.hashCode(a);
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
IntegerArray other = (IntegerArray) obj;
if (!Arrays.equals(a, other.a))
return false;
return true;
}
}

Aucun commentaire:

Enregistrer un commentaire