Skip to content

Commit ffa8088

Browse files
committed
more tests
1 parent e2dc851 commit ffa8088

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/test/scala/com/fulcrumgenomics/util/MetricBuilderTest.scala

+18
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@
2525

2626
package com.fulcrumgenomics.util
2727

28+
import com.fulcrumgenomics.cmdline.FgBioMain.FailureException
2829
import com.fulcrumgenomics.testing.UnitSpec
2930

3031

3132
case class MetricBuilderTestMetric(name: String, count: Long = 1) extends Metric
3233

34+
case class MetricBuilderNameMetric(first: String, second: String, age: Int) extends Metric
35+
3336
class MetricBuilderTest extends UnitSpec {
3437
private val builder = new MetricBuilder[MetricBuilderTestMetric]()
3538

@@ -40,4 +43,19 @@ class MetricBuilderTest extends UnitSpec {
4043
it should "build a metric from an argmap with only required values specified" in {
4144
builder.fromArgMap(Map("name" -> "foo")) shouldBe MetricBuilderTestMetric(name="foo")
4245
}
46+
47+
it should "build a metric from a delimited line" in {
48+
builder.fromLine(line = "Foo Bar\t42", 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\ttwo")
58+
an[FailureException] should be thrownBy builder.fromLine(line="one\ttwo\t3\tfour", lineNumber=Some(1))
59+
an[FailureException] should be thrownBy builder.fromLine(line="one\ttwo\tthree")
60+
}
4361
}

0 commit comments

Comments
 (0)