Spock Web Console

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

Eric

Published 1 week ago by Operations
Actions  ➤ Edit In Console Back To Console Show/Hide Line Numbers View Recent Scripts
package intro

import spock.lang.*

@Narrative("""
Take a look at these math questions.

Make the tests pass by putting in the right operation or answer
""")
class OperationsSpec extends Specification {
    def "Fix the operations to get expected results"() {
        expect:"Basic Math operations"
        1 + 2 == null
        5 - 2 == null
        6 / 2 == null
        7 % 2 == null
        2 * 100 == null

        and:"Little more complex, order of operations"
        1 + 2 - 3     == null
        7 + 2 * 3 / 1 == null

        and:"Explicit ordering with `()`'s"
        ((2 + 2) * 3) / 2 == null

        and:"increment & decrement"
        ++1 == null
        --1 == null
    }

    @See("Stop when you get to this")
    def "Comparison"() {
        expect: "Boolean comparison"
        true == true
        true != false

        and: "other types too"
        2 != 1
        "Erin" != "Aaron"
        "ABC" * 2 == "ABCABC"

        and: "operators"
        true || false == true    // Or
        true && false == false   // And
        true && !false == true   // And Not

        and: "gt, lt"
        1 < 2 == true
        3 >= 1 == true
        3 <= 1 == false

        and: "put many together"
        3 >= 1 && 4 > 3 == true
    }
}