我有这个代码:
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