25
25
26
26
package com .fulcrumgenomics .util
27
27
28
+ import com .fulcrumgenomics .cmdline .FgBioMain .FailureException
28
29
import com .fulcrumgenomics .testing .UnitSpec
29
30
30
31
31
32
case class MetricBuilderTestMetric (name : String , count : Long = 1 ) extends Metric
32
33
34
+ case class MetricBuilderNameMetric (first : String , second : String , age : Int ) extends Metric
35
+
33
36
class MetricBuilderTest extends UnitSpec {
34
37
private val builder = new MetricBuilder [MetricBuilderTestMetric ]()
35
38
@@ -40,4 +43,19 @@ class MetricBuilderTest extends UnitSpec {
40
43
it should " build a metric from an argmap with only required values specified" in {
41
44
builder.fromArgMap(Map (" name" -> " foo" )) shouldBe MetricBuilderTestMetric (name= " foo" )
42
45
}
46
+
47
+ it should " build a metric from a delimited line" in {
48
+ builder.fromLine(line = " Foo Bar\t 42" , delim = " \t " ) shouldBe MetricBuilderTestMetric (name= " Foo Bar" , count= 42 )
49
+ builder.fromLine(line = " Foo Bar,42" , delim = " ," ) shouldBe MetricBuilderTestMetric (name= " Foo Bar" , count= 42 )
50
+
51
+ val nameBuilder = new MetricBuilder [MetricBuilderNameMetric ]()
52
+ nameBuilder.fromLine(line = " Foo Bar 42" , delim = " " ) shouldBe MetricBuilderNameMetric (first= " Foo" , second= " Bar" , age= 42 )
53
+ }
54
+
55
+ it should " throw an FailureException when the # of values are incorrect or wrong type" in {
56
+ val builder = new MetricBuilder [MetricBuilderNameMetric ]()
57
+ an[FailureException ] should be thrownBy builder.fromLine(line= " one\t two" )
58
+ an[FailureException ] should be thrownBy builder.fromLine(line= " one\t two\t 3\t four" , lineNumber= Some (1 ))
59
+ an[FailureException ] should be thrownBy builder.fromLine(line= " one\t two\t three" )
60
+ }
43
61
}
0 commit comments