summaryrefslogtreecommitdiff
path: root/test/disabled/coder/Coder.scala
diff options
context:
space:
mode:
authorHubert Plociniczak <hubert.plociniczak@epfl.ch>2011-11-02 14:34:35 +0000
committerHubert Plociniczak <hubert.plociniczak@epfl.ch>2011-11-02 14:34:35 +0000
commitb6778be91900b8161e705dc2598ef7af86842b0b (patch)
treed15e8ec18a37eec212f50f1ace27714d7e7d4d34 /test/disabled/coder/Coder.scala
parentac6c76f26d884a94d0c9ff54f055d3f9ab750bac (diff)
downloadscala-b6778be91900b8161e705dc2598ef7af86842b0b.tar.gz
scala-b6778be91900b8161e705dc2598ef7af86842b0b.tar.bz2
scala-b6778be91900b8161e705dc2598ef7af86842b0b.zip
Begone t1737...
Diffstat (limited to 'test/disabled/coder/Coder.scala')
-rw-r--r--test/disabled/coder/Coder.scala74
1 files changed, 37 insertions, 37 deletions
diff --git a/test/disabled/coder/Coder.scala b/test/disabled/coder/Coder.scala
index 06dd4b6355..4e29c2a6ee 100644
--- a/test/disabled/coder/Coder.scala
+++ b/test/disabled/coder/Coder.scala
@@ -5,31 +5,31 @@ import collection.parallel.immutable._
class SeqCoder(words: List[String]) {
-
+
private val m = Map(
- '2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL",
+ '2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL",
'6' -> "MNO", '7' -> "PQRS", '8' -> "TUV", '9' -> "WXYZ")
-
+
/** Invert the mnemnonics map to give a map from chars 'A' ... 'Z' to '2' ... '9' */
- private val charCode: Map[Char, Char] =
+ private val charCode: Map[Char, Char] =
for ((digit, letters) <- m; letter <- letters) yield letter -> digit
-
- /** Maps a word to the digit string it represents,
+
+ /** Maps a word to the digit string it represents,
* e.g. `Java` -> `5282` */
private def wordCode(word: String): String = word.toUpperCase map charCode
-
- /** A map from digit strings to the words that represent
+
+ /** A map from digit strings to the words that represent
* them e.g. `5282` -> List(`Java`, `Kata`, `Lava`, ...)
*/
- val wordsForNum: Map[String, List[String]] =
+ val wordsForNum: Map[String, List[String]] =
words groupBy wordCode withDefaultValue List()
-
+
val memo = collection.mutable.Map[String, Set[List[String]]]("" -> Set(List()))
val wfnmemo = collection.mutable.Map[(String, String), Set[List[String]]]()
val subsmemo = collection.mutable.Map[(String, String, String), Set[List[String]]]()
-
+
/** All ways to encode a number as a list of words */
- def encode(number: String): Set[List[String]] =
+ def encode(number: String): Set[List[String]] =
if (number.isEmpty) Set(List())
else {
val splits = (1 to number.length).toSet
@@ -51,38 +51,38 @@ class SeqCoder(words: List[String]) {
memo += number -> r
r
}
-
- /** Maps a number to a list of all word phrases that can
+
+ /** Maps a number to a list of all word phrases that can
* represent it */
def translate(number: String): Set[String] = encode(number) map (_ mkString " ")
-
+
def ??? : Nothing = throw new UnsupportedOperationException
}
class ParCoder(words: List[String]) {
-
+
private val m = Map(
- '2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL",
+ '2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL",
'6' -> "MNO", '7' -> "PQRS", '8' -> "TUV", '9' -> "WXYZ")
-
+
/** Invert the mnemnonics map to give a map from chars 'A' ... 'Z' to '2' ... '9' */
- private val charCode: Map[Char, Char] =
+ private val charCode: Map[Char, Char] =
for ((digit, letters) <- m; letter <- letters) yield letter -> digit
-
- /** Maps a word to the digit string it represents,
+
+ /** Maps a word to the digit string it represents,
* e.g. `Java` -> `5282` */
private def wordCode(word: String): String = word.toUpperCase map charCode
-
- /** A map from digit strings to the words that represent
+
+ /** A map from digit strings to the words that represent
* them e.g. `5282` -> List(`Java`, `Kata`, `Lava`, ...)
*/
- val wordsForNum: Map[String, List[String]] =
+ val wordsForNum: Map[String, List[String]] =
words groupBy wordCode withDefaultValue List()
-
+
val comparison = new SeqCoder(words)
-
+
/** All ways to encode a number as a list of words */
- def encode(number: String): ParSet[List[String]] =
+ def encode(number: String): ParSet[List[String]] =
if (number.isEmpty) ParSet(List())
else {
val splits = (1 to number.length).toSet.par
@@ -105,7 +105,7 @@ class ParCoder(words: List[String]) {
assertNumber(number, r)
r
}
-
+
def assertSubs(num: String, subsfrom: String, word: String, r: ParSet[List[String]]) {
val m = comparison.subsmemo((num, subsfrom, word))
if (r != m) {
@@ -115,7 +115,7 @@ class ParCoder(words: List[String]) {
error("r != m")
}
}
-
+
def assertWfn(num: String, split: String, dropped: String, r: List[List[String]]) {
val m = comparison.wfnmemo((num, split))
val rs = r.toSet
@@ -139,7 +139,7 @@ class ParCoder(words: List[String]) {
error("rs != m")
}
}
-
+
def assertNumber(num: String, r: ParSet[List[String]]) {
val m = comparison.memo(num)
if (r != m) {
@@ -149,14 +149,14 @@ class ParCoder(words: List[String]) {
error("r != m")
}
}
-
- /** Maps a number to a list of all word phrases that can
+
+ /** Maps a number to a list of all word phrases that can
* represent it */
def translate(number: String): ParSet[String] = {
comparison.translate(number)
encode(number) map (_ mkString " ")
}
-
+
def ??? : Nothing = throw new UnsupportedOperationException
}
@@ -165,7 +165,7 @@ class ParCoder(words: List[String]) {
object Test {
val code = "2328437472947"//36262633"//837976"//"6477323986225453446"
//val code = "747294736262633"
-
+
/* */
def main(args : Array[String]) {
// import scala.concurrent.forkjoin.ForkJoinPool
@@ -173,16 +173,16 @@ object Test {
// case fj: ForkJoinPool => fj.setParallelism(1)
// }
// println(collection.parallel.tasksupport.parallelismLevel)
-
+
for (i <- 0 until 10) {
val seqcoder = new SeqCoder(Dictionary.wordlist)
val st = seqcoder.translate(code)
//println("Translation check: " + st.size)
-
+
val parcoder = new ParCoder(Dictionary.wordlist)
val pt = parcoder.translate(code)
//println("Translation check: " + pt.size)
-
+
// val st = sts.toList.sorted
// val pt = pts.toList.sorted
if (st.size != pt.size) {