Spock Web Console

subscribe to the feed Subscribe
Various Input Techniques (via #spockwebconsole)
tweet this script Tweet

Various Input Techniques

Published 2 years ago by Zack with tags where set non-primative
Actions  ➤ Edit In Console Back To Console Show/Hide Line Numbers View Recent Scripts
import spock.lang.*

// Set of test which vary input and non-primative objects
// Hit 'Run Script' below to see results
class VariousInputTechniques extends Specification {
  def "Max test with varying input"() {
    expect:
    Math.max(a, b) == c
    where:
    a << [5, 3, -3]
    b << [1, 9, -1]
    c << [5, 9, -1]
  }

  def "Verify Sorting in TreeSet"() {
    setup:
    def set = new TreeSet()
    set.add(7)
    set.add(3)
    set.add(3)
    set.add(5)

    expect:
    set.getAt(0) == 3
    set.getAt(1) == 5
    set.getAt(2) == 7
  }

  def "Test sorting where provided a series of non-primative objects"() {
    expect:
    set.remove(1)
    set.getAt(0) == 2
    where:
    set << [new TreeSet([3, 2 , 1]), new TreeSet([1 , 2 , 3])]
  }

// COMMENTED OUT DUE TO LACK OF PUBLIC SQL SERVER
//  def "Source values from SQL"() {
//    setup:
//    def sql = Sql.newInstance("jdbc:derby:spockdata","org.apache.derby.jdbc.EmbeddedDriver")
//    // quite expensive should be shared resource typically
//
//    expect:
//    Math.max(a, b) == c
// 
//    where:
//    row << sql.rows("select * from maxdata")
//    a = row["a"]
//    b = row["b"]
//    c = row["c"]
//  }
}