range: implements `==` method on ranges
authorAlexandre Terrasa <alexandre@moz-code.org>
Mon, 24 Nov 2014 18:44:23 +0000 (13:44 -0500)
committerAlexandre Terrasa <alexandre@moz-code.org>
Tue, 25 Nov 2014 21:12:18 +0000 (16:12 -0500)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/standard/collection/range.nit

index 27dd3f4..665b263 100644 (file)
@@ -95,6 +95,20 @@ class Range[E: Discrete]
                last = to.predecessor(1)
                after = to
        end
+
+       # Two ranges are equals if they have the same first and last elements.
+       #
+       #     var a = new Range[Int](10, 15)
+       #     var b = new Range[Int].without_last(10, 15)
+       #     assert a == [10..15]
+       #     assert a == [10..16[
+       #     assert not a == [10..15[
+       #     assert b == [10..15[
+       #     assert b == [10..14]
+       #     assert not b == [10..15]
+       redef fun ==(o) do
+               return o isa Range[E] and self.first == o.first and self.last == o.last
+       end
 end
 
 private class IteratorRange[E: Discrete]