feat: move contains method from List to Sequence and add tests for List and Range

Add a generic `contains` implementation on the `Sequence` base class, removing the duplicate method from `List`. This allows all sequence types (including Range) to use the method without per-class redefinition. Include new test files for `List.contains` and `Range.contains` covering ordered, backwards, and exclusive ranges.
This commit is contained in:
Thorbjørn Lindeijer
2015-03-15 14:43:10 +00:00
parent 18cf57d5f5
commit b22040577e
5 changed files with 51 additions and 18 deletions
+6
View File
@@ -0,0 +1,6 @@
var list = [1, 2, 3, 4, "foo"]
IO.print(list.contains(2)) // expect: true
IO.print(list.contains(5)) // expect: false
IO.print(list.contains("foo")) // expect: true
IO.print(list.contains("bar")) // expect: false
+23
View File
@@ -0,0 +1,23 @@
// Ordered range.
IO.print((2..5).contains(1)) // expect: false
IO.print((2..5).contains(2)) // expect: true
IO.print((2..5).contains(5)) // expect: true
IO.print((2..5).contains(6)) // expect: false
// Backwards range.
IO.print((5..2).contains(1)) // expect: false
IO.print((5..2).contains(2)) // expect: true
IO.print((5..2).contains(5)) // expect: true
IO.print((5..2).contains(6)) // expect: false
// Exclusive ordered range.
IO.print((2...5).contains(1)) // expect: false
IO.print((2...5).contains(2)) // expect: true
IO.print((2...5).contains(5)) // expect: false
IO.print((2...5).contains(6)) // expect: false
// Exclusive backwards range.
IO.print((5...2).contains(1)) // expect: false
IO.print((5...2).contains(2)) // expect: false
IO.print((5...2).contains(5)) // expect: true
IO.print((5...2).contains(6)) // expect: false