3 ms·
This seems to have been copied straight from the Spock Framework[1] (which I've been using for comprehensive tests for several years), but worse. Here's what i
by brabel 4y ago
This seems to have been copied straight from the Spock Framework[1] (which I've been using for comprehensive tests for several years), but worse.
Here's what it looks like in Spock:
@Canonical
class Person {
int balance
def wire(Person other, int amount) {
if (balance >= amount) {
balance -= amount
other.balance += amount
}
}
}
class PersonSpec extends Specification {
def 'transferring #amount amount'() {
given: 'two people'
def pa = new Person(balance = a), pb = new Person(balance = b)
when: 'an amount is transferred from a to b'
pa.wire(pb, amount)
then: 'the transfer succeeds if possible, or nothing happens otherwise'
pa.balance == expectedA && pb.balance == expectedB
where:
amount | a | b || expectedA | expectedB
0 | 0 | 0 || 0 | 0
10 | 20 | 0 || 10 | 10
10 | 10 | 10 || 0 | 20
10 | 9 | 10 || 9 | 10
}
}
[1] https://spockframework.org/spock/docs/2.1/spock_primer.html https://spockframework.org/spock/docs/2.1/spock_primer.html
- jleahy 4y agoSpock is not a system for formal (ie. exhaustive) verification.
- brabel 4y agoI did not say it is. I just said the Python code the parent commenter posted was just like Spock, but for Python. Also: tests like that can be provably comprehensive in the cases they handle (which can be generated, you don't need to manually list them all), but that was not my point.