ChanGan
ChanGan

Reputation: 4318

when using assertion in ranges, getting failure?

I've seen some examples for ranges.

assert (0.0 .. 1.0).contains(0.5)

I would expecte True for this but I am getting false for this?

Any clue why this assertion failed?

Upvotes: 1

Views: 153

Answers (1)

Peter Niederwieser
Peter Niederwieser

Reputation: 123910

A groovy.lang.Range is a List of Comparable values, two in this case. That's why List.contains returns false for 0.5. What you want instead is Range.containsWithinBounds.

Upvotes: 1

Related Questions