Spock Web Console

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

Another Example

Published 4 months ago by Bl_nK
Actions  ➤ Edit In Console Back To Console Show/Hide Line Numbers View Recent Scripts
import spock.lang.*
import java.math.RoundingMode

class TaxUtil {
    static final Double TX_TAX = 0.0825 // 8.25%
    
    static BigDecimal calculateTax(BigDecimal amount, Double taxRate){
        return new BigDecimal(amount * taxRate).setScale(2, RoundingMode.HALF_UP)
    }
}


TaxUtil.calculateTax(1.3, TaxUtil.TX_TAX)
 
@Unroll
class UtilSpec extends Specification {
    def "Get Tax for purchases in TX"() {
    expect:
        TaxUtil.calculateTax(amount, TaxUtil.TX_TAX) == tax
 
    where:
        amount|tax
        500|41.25
        23984|1978.68
        1.56|0.13
    }
}