私は何を間違っていますか:
assert 'foo' == 'foo' //PASS
assert '500' == '500' //PASS
assert '500' < '1000' //FAIL <-- Supposed to pass
assert '500' <= '1000' //FAIL <-- Supposed to pass
assert '1000' > '500' //FAIL <-- Supposed to pass
assert '1000' >= '500' //FAIL <-- Supposed to pass
これは、カスタマイズ可能な「条件」オブジェクト用です。
class Condition {
static def compareClosure = [
'==' : { a, b -> a == b},
'!=' : { a, b -> a != b},
'<' : { a, b -> a < b},
'<=' : { a, b -> a <= b},
'>' : { a, b -> a > b},
'>=' : { a, b -> a >= b}
]
String comparator
def value
Condition(String comparator, String value) {
this.value = value
this.comparator = comparator
}
boolean isSatisfiedBy(def value) {
compareClosure[comparator](value, this.value)
}
}
そう
assert new Condition('<=', '1000').isSatisfiedBy('500') //FAIL
値を数値型に変換せずにこれを行う方法はありますか?