trackler 2.2.1.29 → 2.2.1.30

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,80 +1,79 @@
1
- import play.api.libs.json.Json
1
+ import java.io.File
2
2
 
3
- import scala.io.Source
3
+ import testgen.{CanonicalDataParser, TestCaseData, TestSuiteBuilder}
4
+ import TestSuiteBuilder._
4
5
 
5
- // Generates test suite from json test definition for the VariableLengthQuantity exercise.
6
- class VariableLengthQuantityTestGenerator {
7
- implicit val vlqTestCaseReader = Json.reads[VlqTestCase]
8
-
9
- private val filename = "variable-length-quantity.json"
10
- private val fileContents = Source.fromFile(filename).getLines.mkString
11
- private val json = Json.parse(fileContents)
6
+ object VariableLengthQuantityTestGenerator {
12
7
 
13
- def write {
14
- val testBuilder = new TestBuilder("VariableLengthQuantityTest")
15
- addEncodeTests(testBuilder)
16
- addDecodeTests(testBuilder)
17
- testBuilder.toFile
8
+ private def mapListToString(arg: List[_]): String = {
9
+ s"List(${arg
10
+ .map {
11
+ case d: Double => "0x" + d.toLong.toHexString.toUpperCase
12
+ case i: Int => "0x" + i.toLong.toHexString.toUpperCase
13
+ case _ => throw new IllegalArgumentException()
14
+ }
15
+ .mkString(", ")})"
18
16
  }
19
17
 
20
- private def addEncodeTests(testBuilder: TestBuilder): Unit = {
21
- val description = (json \ "encode" \ "description").get.as[List[String]].mkString(" ")
22
- val encodeTestCases = (json \ "encode" \ "cases").validate[List[VlqTestCase]].asEither match {
23
- case Left(l) => List()
24
- case Right(r) => r
25
- }
26
-
27
- implicit def testCaseToGen(tc: VlqTestCase): TestCaseGen = {
28
- val callSUT = s"""VariableLengthQuantity.encode(${listToStr(tc.input)})"""
29
- val expected = listToStr(tc.expected)
30
- val result = s"val encoded = $callSUT"
31
- val checkResult = s"""encoded should be ($expected)"""
32
-
33
- TestCaseGen("encode: " + tc.description, callSUT, expected, result, checkResult)
18
+ private def toEncodeString(expected: CanonicalDataParser.Expected): String = {
19
+ expected match {
20
+ case Left(_) => "None"
21
+ case Right(null) => "None"
22
+ case Right(n) => s"${mapListToString(n.asInstanceOf[List[_]])}"
34
23
  }
35
-
36
- testBuilder.addTestCases(encodeTestCases, Some(description))
37
24
  }
38
25
 
39
- private def addDecodeTests(testBuilder: TestBuilder): Unit = {
40
- val description = (json \ "decode" \ "description").get.as[List[String]].mkString(" ")
41
- val decodeTestCases = (json \ "decode" \ "cases").validate[List[VlqTestCase]].asEither match {
42
- case Left(l) => List()
43
- case Right(r) => r
26
+ private def toDecodeString(expected: CanonicalDataParser.Expected): String = {
27
+ expected match {
28
+ case Left(_) => "true"
29
+ case Right(null) => "true"
30
+ case Right(n) => s"Right(${mapListToString(n.asInstanceOf[List[Any]])})"
44
31
  }
32
+ }
45
33
 
46
- implicit def testCaseToGen(tc: VlqTestCase): TestCaseGen = {
47
- val input = listToStr(tc.input)
48
- val callSUT = s"""VariableLengthQuantity.decode($input)"""
49
- val checkResult = tc.expected match {
50
- case None => "decoded.isLeft should be (true)"
51
- case Some(arr) => s"decoded should be (Right(${listToStr(arr)}))"
34
+ private def toSutCall(sut: String, property: String, args: String, expected: CanonicalDataParser.Expected): String = {
35
+ if (property.toString.equals("encode"))
36
+ s"""$sut.$property($args)"""
37
+ else {
38
+ expected match {
39
+ case Left(_) => s"""$sut.$property($args).isLeft"""
40
+ case Right(null) => s"""$sut.$property($args).isLeft"""
41
+ case Right(n) => s"""$sut.$property($args)"""
52
42
  }
53
- val result = s"val decoded = $callSUT"
54
-
55
- TestCaseGen("decode: " + tc.description, callSUT, "", result, checkResult)
56
43
  }
57
-
58
- testBuilder.addTestCases(decodeTestCases, Some(description))
59
44
  }
60
45
 
61
- private def listToStr(arr: Option[List[Long]]): String = {
62
- arr match {
63
- case None => "List[Int]()"
64
- case Some(x) => listToStr(x)
46
+ private def toArgString(any: Any): String = {
47
+ any match {
48
+ case list: List[_] => s"${mapListToString(list)}"
49
+ case _ => any.toString
65
50
  }
66
51
  }
67
52
 
68
- private def listToStr(arr: List[Long]): String = {
69
- val elements = arr.map(n => s"0x${n.toHexString}").mkString(", ")
70
- s"List($elements)"
71
- }
72
- }
73
-
74
- case class VlqTestCase(description: String, input: List[Long], expected: Option[List[Long]])
53
+ private def sutArgs(parseResult: CanonicalDataParser.ParseResult, argNames: String*): String =
54
+ argNames map (name => toArgString(parseResult(name))) mkString ", "
55
+
56
+
57
+ def fromLabeledTest(argNames: String*): ToTestCaseData =
58
+ withLabeledTest { sut =>
59
+ labeledTest =>
60
+ val args = sutArgs(labeledTest.result, argNames: _*)
61
+ val property = labeledTest.property
62
+ val sutCall = toSutCall(sut, property, args, labeledTest.expected)
63
+ val expected =
64
+ if (labeledTest.property.toString.equals("encode"))
65
+ toEncodeString(labeledTest.expected)
66
+ else
67
+ toDecodeString(labeledTest.expected)
68
+ TestCaseData(labeledTest.description, sutCall, expected)
69
+ }
75
70
 
76
- object VariableLengthQuantityTestGenerator {
77
71
  def main(args: Array[String]): Unit = {
78
- new VariableLengthQuantityTestGenerator().write
72
+ val file = new File("src/main/resources/variable-length-quantity.json")
73
+
74
+ val code = TestSuiteBuilder.build(file, fromLabeledTest("input"))
75
+ println(s"-------------")
76
+ println(code)
77
+ println(s"-------------")
79
78
  }
80
79
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trackler
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1.29
4
+ version: 2.2.1.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katrina Owen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-11 00:00:00.000000000 Z
11
+ date: 2017-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -3180,6 +3180,10 @@ files:
3180
3180
  - tracks/ecmascript/exercises/simple-cipher/example.js
3181
3181
  - tracks/ecmascript/exercises/simple-cipher/package.json
3182
3182
  - tracks/ecmascript/exercises/simple-cipher/simple-cipher.spec.js
3183
+ - tracks/ecmascript/exercises/simple-linked-list/README.md
3184
+ - tracks/ecmascript/exercises/simple-linked-list/example.js
3185
+ - tracks/ecmascript/exercises/simple-linked-list/package.json
3186
+ - tracks/ecmascript/exercises/simple-linked-list/simple-linked-list.spec.js
3183
3187
  - tracks/ecmascript/exercises/space-age/README.md
3184
3188
  - tracks/ecmascript/exercises/space-age/example.js
3185
3189
  - tracks/ecmascript/exercises/space-age/package.json
@@ -9319,6 +9323,7 @@ files:
9319
9323
  - tracks/powershell/config/exercise_readme.go.tmpl
9320
9324
  - tracks/powershell/config/maintainers.json
9321
9325
  - tracks/powershell/docs/EXERCISE_README_INSERT.md
9326
+ - tracks/powershell/docs/INSTRUCTIONS.md
9322
9327
  - tracks/powershell/docs/SNIPPET.txt
9323
9328
  - tracks/powershell/exercises/hamming/.version
9324
9329
  - tracks/powershell/exercises/hamming/README.md
@@ -11536,7 +11541,7 @@ files:
11536
11541
  - tracks/scala/exercises/variable-length-quantity/README.md
11537
11542
  - tracks/scala/exercises/variable-length-quantity/build.sbt
11538
11543
  - tracks/scala/exercises/variable-length-quantity/example.scala
11539
- - tracks/scala/exercises/variable-length-quantity/src/main/scala/VariableLengthQuantity.scala
11544
+ - tracks/scala/exercises/variable-length-quantity/src/main/scala/.keep
11540
11545
  - tracks/scala/exercises/variable-length-quantity/src/test/scala/VariableLengthQuantityTest.scala
11541
11546
  - tracks/scala/exercises/word-count/README.md
11542
11547
  - tracks/scala/exercises/word-count/build.sbt