From 36ac83da7fb1556416fc4c5e86ceac69adefc6c8 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 19 Mar 2011 23:20:19 +0000 Subject: Fix for a big bug in lastIndexOfSlice and some ... Fix for a big bug in lastIndexOfSlice and some latent negative index bugs in both that and indexOfSlice. This stuff is taxing. Closes #4348, no review. --- test/files/run/seqlike-kmp.check | 90 ++++++++++++++++++++++++++++++++++++++++ test/files/run/seqlike-kmp.scala | 32 ++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 test/files/run/seqlike-kmp.check create mode 100644 test/files/run/seqlike-kmp.scala (limited to 'test/files') diff --git a/test/files/run/seqlike-kmp.check b/test/files/run/seqlike-kmp.check new file mode 100644 index 0000000000..6040710c7c --- /dev/null +++ b/test/files/run/seqlike-kmp.check @@ -0,0 +1,90 @@ +indexOfSlice + (97) with idx >= -1 = 97 + (97) with idx >= 0 = 97 + (97) with idx >= 1 = 97 + (97) with idx >= 2 = 97 + (97) with idx >= 97 = 97 + (97) with idx >= 98 = -1 + (97) with idx >= 99 = -1 + (97) with idx >= 100 = -1 +lastIndexOfSlice + (97) with idx <= -1 = -1 + (97) with idx <= 0 = -1 + (97) with idx <= 1 = -1 + (97) with idx <= 2 = -1 + (97) with idx <= 97 = 97 + (97) with idx <= 98 = 97 + (97) with idx <= 99 = 97 + (97) with idx <= 100 = 97 +indexOfSlice + (97, 98) with idx >= -1 = 97 + (97, 98) with idx >= 0 = 97 + (97, 98) with idx >= 1 = 97 + (97, 98) with idx >= 2 = 97 + (97, 98) with idx >= 97 = 97 + (97, 98) with idx >= 98 = -1 + (97, 98) with idx >= 99 = -1 + (97, 98) with idx >= 100 = -1 +lastIndexOfSlice + (97, 98) with idx <= -1 = -1 + (97, 98) with idx <= 0 = -1 + (97, 98) with idx <= 1 = -1 + (97, 98) with idx <= 2 = -1 + (97, 98) with idx <= 97 = 97 + (97, 98) with idx <= 98 = 97 + (97, 98) with idx <= 99 = 97 + (97, 98) with idx <= 100 = 97 +indexOfSlice + (97, 98, 99) with idx >= -1 = 97 + (97, 98, 99) with idx >= 0 = 97 + (97, 98, 99) with idx >= 1 = 97 + (97, 98, 99) with idx >= 2 = 97 + (97, 98, 99) with idx >= 97 = 97 + (97, 98, 99) with idx >= 98 = -1 + (97, 98, 99) with idx >= 99 = -1 + (97, 98, 99) with idx >= 100 = -1 +lastIndexOfSlice + (97, 98, 99) with idx <= -1 = -1 + (97, 98, 99) with idx <= 0 = -1 + (97, 98, 99) with idx <= 1 = -1 + (97, 98, 99) with idx <= 2 = -1 + (97, 98, 99) with idx <= 97 = 97 + (97, 98, 99) with idx <= 98 = 97 + (97, 98, 99) with idx <= 99 = 97 + (97, 98, 99) with idx <= 100 = 97 +indexOfSlice + (98, 99) with idx >= -1 = 98 + (98, 99) with idx >= 0 = 98 + (98, 99) with idx >= 1 = 98 + (98, 99) with idx >= 2 = 98 + (98, 99) with idx >= 97 = 98 + (98, 99) with idx >= 98 = 98 + (98, 99) with idx >= 99 = -1 + (98, 99) with idx >= 100 = -1 +lastIndexOfSlice + (98, 99) with idx <= -1 = -1 + (98, 99) with idx <= 0 = -1 + (98, 99) with idx <= 1 = -1 + (98, 99) with idx <= 2 = -1 + (98, 99) with idx <= 97 = -1 + (98, 99) with idx <= 98 = 98 + (98, 99) with idx <= 99 = 98 + (98, 99) with idx <= 100 = 98 +indexOfSlice + (99) with idx >= -1 = 99 + (99) with idx >= 0 = 99 + (99) with idx >= 1 = 99 + (99) with idx >= 2 = 99 + (99) with idx >= 97 = 99 + (99) with idx >= 98 = 99 + (99) with idx >= 99 = 99 + (99) with idx >= 100 = -1 +lastIndexOfSlice + (99) with idx <= -1 = -1 + (99) with idx <= 0 = -1 + (99) with idx <= 1 = -1 + (99) with idx <= 2 = -1 + (99) with idx <= 97 = -1 + (99) with idx <= 98 = -1 + (99) with idx <= 99 = 99 + (99) with idx <= 100 = 99 diff --git a/test/files/run/seqlike-kmp.scala b/test/files/run/seqlike-kmp.scala new file mode 100644 index 0000000000..af39fda9af --- /dev/null +++ b/test/files/run/seqlike-kmp.scala @@ -0,0 +1,32 @@ +object Test { + val source = 0 to 99 + val idxes = (-1 to 2) ++ (97 to 100) + def str(xs: Seq[Int]) = xs.mkString("(", ", ", ")") + + def f(tgt: Seq[Int]) = { + println("indexOfSlice") + // the first index `>= from` such that... + for (x <- idxes) { + val res = source.indexOfSlice(tgt, x) + println(" %s with idx >= %d = %d".format(str(tgt), x, res)) + } + // the last index `<= end` such that... + println("lastIndexOfSlice") + for (x <- idxes) { + val res = source.lastIndexOfSlice(tgt, x) + println(" %s with idx <= %d = %d".format(str(tgt), x, res)) + } + } + + def g(idx: Int, len: Int) = { + f(source.slice(idx, idx + len)) + } + + def main(args: Array[String]): Unit = { + g(97, 1) + g(97, 2) + g(97, 3) + g(98, 2) + g(99, 1) + } +} -- cgit v1.2.3