私はこのコードを持っています:
static def parseString(String inputRow, Particle particle) {
def map = inputRow.split()
particle.mass = map[0].toDouble()
particle.x = map[1].toDouble()
particle.y = map[2].toDouble()
}
そして、このテストコード:
static final inputRow = "1 -5.2 3.8"
def particle1 = new Particle()
def "string should be parsed into particles"() {
when:
RepulsionForce.parseString(inputRow, particle1);
then:
particle1.mass == 1
particle1.x == -5.2
particle1.y == 3.8
}
上記のテストはそのままパスします。ただし、parseString コードを以下のコードに変更すると:
static def parseString(String inputRow, Particle particle) {
def map = inputRow.split()
particle.mass = map[0].toFloat()
particle.x = map[1].toFloat()
particle.y = map[2].toFloat()
}
同じテストが次のエラーで失敗します。
Condition not satisfied:
particle1.x == -5.2
| | |
| | false
| -5.2
Particle@a548695