-2
IPv4アドレスが渡され、同じIPアドレスの場合はtrueを返します。オブジェクトの呼び出しがパラメータと同じことを表す場合はbooleanを返す方法は?
どんなに私がpublic boolean equals(IPAddress other){
//code here
}
を記述する必要がありますどのように
assertTrue(correct1.equals(correct4));
で
public void testEqualsIPAddress() {
correct1 = new IPAddress("0000192.168.1.0000254");
correct2 = new IPAddress("255.000255.00000255.255");
correct3 = new IPAddress("000.00.00.0000000000000");
correct4 = new IPAddress("192.168.1.254");
assertTrue(correct1.equals(correct4));
assertTrue(correct4.equals(correct1));
assertFalse(correct1.equals(correct3));
assertFalse(correct2.equals(correct4));
}
リターン障害以上、JUnitテストケースを書くどの方法が
/**
*
* @param other
* @return true if calling object and parameter object represent
* the same ip address, and false otherwise
*/
public boolean equals(IPAddress other) {
if(this.parts.equals(other.parts)){ //need help here
return true;
}
else
return false;
、?
編集:ここでは
はコンストラクタ
public class IPAddress {
private int[] parts;
ある場合にtrueを返します'IPAddress'コンストラクタが何をしているのか、' parts 'は何ですか? ---また、 'equals(IPAddress other)'は 'Object'から継承した' equals(Object) 'メソッドの実装ではないことに注意してください。 – Andreas
'correct1'の種類は何ですか? 'IPAdress'でなければ、動作しません。さらに、 'IPAddress'のコンストラクタが表示されていないので、問題を含む可能性もあります。 – fabian
@fabian - ' IPAddress'(またはスーパークラス)以外のものであれば、コンパイルされません。 –