1
exercism fetch scala run-length-encoding

src/test/scala/RunLengthEncodingTests.scala

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import org.scalatest.{Matchers, FunSuite}

/** @version 1.0.0 */
class RunLengthEncodingTest extends FunSuite with Matchers {

  test("encode - empty string") {
    RunLengthEncoding.encode("") should be ("")
  }

  test("encode - single characters only are encoded without count") {
    pending
    RunLengthEncoding.encode("XYZ") should be ("XYZ")
  }

  test("encode - string with no single characters") {
    pending
    RunLengthEncoding.encode("AABBBCCCC") should be ("2A3B4C")
  }

  test("encode - single characters mixed with repeated characters") {
    pending
    RunLengthEncoding.encode("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB") should be ("12WB12W3B24WB")
  }

  test("encode - multiple whitespace mixed in string") {
    pending
    RunLengthEncoding.encode("  hsqq qww  ") should be ("2 hs2q q2w2 ")
  }

  test("encode - lowercase characters") {
    pending
    RunLengthEncoding.encode("aabbbcccc") should be ("2a3b4c")
  }

  test("decode - empty string") {
    pending
    RunLengthEncoding.decode("") should be ("")
  }

  test("decode - single characters only") {
    pending
    RunLengthEncoding.decode("XYZ") should be ("XYZ")
  }

  test("decode - string with no single characters") {
    pending
    RunLengthEncoding.decode("2A3B4C") should be ("AABBBCCCC")
  }

  test("decode - single characters with repeated characters") {
    pending
    RunLengthEncoding.decode("12WB12W3B24WB") should be ("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB")
  }

  test("decode - multiple whitespace mixed in string") {
    pending
    RunLengthEncoding.decode("2 hs2q q2w2 ") should be ("  hsqq qww  ")
  }

  test("decode - lower case string") {
    pending
    RunLengthEncoding.decode("2a3b4c") should be ("aabbbcccc")
  }

  test("consistency - encode followed by decode gives original string") {
    pending
    RunLengthEncoding.decode(RunLengthEncoding.encode("zzz ZZ  zZ")) should be ("zzz ZZ  zZ")
  }
}