diff options
author | Martin Odersky <odersky@gmail.com> | 2010-03-19 17:36:46 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2010-03-19 17:36:46 +0000 |
commit | d2726ea60562d1603a0fa11dacd9ddc51015b6ca (patch) | |
tree | d2d3e6195c901a07cd95e52855560baaed576f5a /test/files/run | |
parent | c059e09cc7fee862e605c4d4d054447bc460aa2a (diff) | |
download | scala-d2726ea60562d1603a0fa11dacd9ddc51015b6ca.tar.gz scala-d2726ea60562d1603a0fa11dacd9ddc51015b6ca.tar.bz2 scala-d2726ea60562d1603a0fa11dacd9ddc51015b6ca.zip |
new version of decode that does not need a length.
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/bytecodecs.scala | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/files/run/bytecodecs.scala b/test/files/run/bytecodecs.scala new file mode 100644 index 0000000000..bf8a0f8ed3 --- /dev/null +++ b/test/files/run/bytecodecs.scala @@ -0,0 +1,39 @@ +import scala.reflect.generic.ByteCodecs._ + +object Test { + + def test8to7(xs: Array[Byte]) { + val ys = encode8to7(xs) + decode7to8(ys, ys.length) + assert(ys.take(xs.length).deep == xs.deep, + "test8to7("+xs.deep+") failed, result = "+ys.take(xs.length).deep) + } + + def testAll(xs: Array[Byte]) { + val ys = encode(xs) + decode(ys) + assert(ys.take(xs.length).deep == xs.deep, + "testAll("+xs.deep+") failed, result = "+ys.take(xs.length).deep) + } + + def test(inputs: Array[Byte]*) { + for (input <- inputs) { + test8to7(input) + testAll(input) + } + } + + def main(args: Array[String]) { + test( + Array(1, 2, 3), + Array(1, 2, 3, 4, 5, 6, 7), + Array(1, -2, 0, -3, -5, -6, -7), + Array(1, 3, -1, -128, 0, 0, -128, 1, 2, 3)) + val rand = new scala.util.Random() + for (i <- 1 until 5000) { + var xs = new Array[Byte](i) + rand.nextBytes(xs) + test(xs) + } + } +} |