Spock Web Console

subscribe to the feed Subscribe
Intersection test (via #spockwebconsole)
tweet this script Tweet

Intersection test

Published 7 months ago by crjoua with tags intersection collection
Actions  ➤ Edit In Console Back To Console Show/Hide Line Numbers View Recent Scripts
import spock.lang.*


class DevXercises extends Specification {
  def "intersection of two numbers"() {
    setup:

    def result = nums1.intersect(nums2)

    expect:
    result.containsAll(expected)
    expected.containsAll(result)

    where:
    nums1     |  nums2          | expected
    [4,9,5]   |  [9,4,9,8,4]    | [4,9]
    [1,2,2,1] |  [2,1,2]        | [1,2]
  }
}