Spock Web Console

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

EricClassFuncSpec

Published 1 week ago by Eric2
Actions  ➤ Edit In Console Back To Console Show/Hide Line Numbers View Recent Scripts
import spock.lang.*

class FunctionsSpec extends Specification {

    // Begin your functions
    static addNumbers(num1, num2) {

    }
    static largest(num1, num2) {

    }
    static left() {

    }
    static right() {

    }
    static move(direction) {

    }

    static move(direction, times) {

    }
    // End your functions

    def "A function that adds 2 numbers"() {
        expect: "Write a function to make this test pass"
        addNumbers(2, 3) == 5
    }

    def "A function that finds the biggest number"() {
        expect: "Write a function to make this test pass"
        largest(1, 10) == 10
        largest(3, 3)  == 3
    }

    def "Move turtle"() {
        expect: "Write a function to make this test pass"
        left()  == "Turtle moved Left!"
        right() == "Turtle moved Right!"

        and: "How can we re-use the functions above to have a different API?"
        move("left")  == "Turtle moved Left!"
        move("right") == "Turtle moved Right!"

        and: "How can we move multiple times with one command?"
        move("left", 2) == "Turtle moved Left! Turtle moved Left!"
    }
}