2017-01-07 14 views
-1

ロケーションIDのリストと1つのロケーションIDの比較を行いたいとします。事実上、値'000000'が位置IDのリストの各インスタンスに表示されるべきであると言いたいのですが、[000000, 000000, 000000, 000000, 000000]です。私はリストの1つのインスタンスのために働くことができますが、どのようにすべてのインスタンスをチェックすることができますか?現時点では1つのインスタンスをチェックしていますが、リスト全体を確認する必要があります。groovyでリスト比較を行うには?

以下

Groovyのコードです:

以下
import groovy.json.JsonSlurper 
def response = messageExchange.response.responseContent 
def json = new JsonSlurper().parseText(response) 

def location_id = json.reviews.location_id 
assert location_id != null 
def location_id_response = location_id[0].toString() 
def location_id_request = messageExchange.modelItem.testStep.testCase.getPropertyValue("locationid") 
assert location_id_response == location_id_request 

log.info location_id_request 
log.info location_id_response 
log.info location_id 

は、ログ情報は次のとおりです。

log.info location_id_request = '000000' 
log.info location_id_response = '000000' 
log.info location_id = [000000, 000000, 000000, 000000, 000000] 

事実location_id_response[0]は、リストから最初の値を選んでいるが、私はとのリストからすべての値をしたいですlocation_id_requestは、最初の値だけでなく、リストの各値と比較されます。 [0]から '0'を削除すると、配列エラーがスローされます。

+0

が必要エンタテイメントタグこの質問は、Groovyについてのみです。そうではありませんか? – UnholySheep

+0

Groovyはjavaやjavascriptに似ているかもしれないと思っていたかもしれません。おそらくそれは関連するかもしれません。 – BruceyBandit

+0

GroovyはJavaScriptに似ていますか?それが私にとってのニュースです。何かがRubyに似ている場合 – UnholySheep

答えて

1

あなたはなぜあなたが異なる3をスパムでした

assert location_id.every { it == location_id_request } 

それとも

assert location_id == [location_id_request] * location_id.size() 

それとも

assert location_id.distinct() == [location_id_request] 

それとも

assert location_id.distinct().with { it.head() == location_id_request && it.size() == 1 } 
+0

恐ろしくありがとうTim – BruceyBandit

+0

最後のものを除いて、おそらくサイズ= 1を確認しない限り、リスト内に他の要素が存在する可能性があります –

関連する問題