aboutsummaryrefslogtreecommitdiff
path: root/kamon-core-tests
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2017-09-15 02:49:36 +0200
committerIvan Topolnjak <ivantopo@gmail.com>2017-09-15 02:49:36 +0200
commitead4fd7743895ffe1d34e37c23eceab575fb907e (patch)
treef40bb164931b4b1d519193b7154b4a4e4501cf49 /kamon-core-tests
parentfdbac7aa95a2103ee823894c44e5fc2f354cbd4a (diff)
downloadKamon-ead4fd7743895ffe1d34e37c23eceab575fb907e.tar.gz
Kamon-ead4fd7743895ffe1d34e37c23eceab575fb907e.tar.bz2
Kamon-ead4fd7743895ffe1d34e37c23eceab575fb907e.zip
create new DifferentialSource utility
Diffstat (limited to 'kamon-core-tests')
-rw-r--r--kamon-core-tests/src/test/scala/kamon/util/DifferentialSourceSpec.scala40
1 files changed, 40 insertions, 0 deletions
diff --git a/kamon-core-tests/src/test/scala/kamon/util/DifferentialSourceSpec.scala b/kamon-core-tests/src/test/scala/kamon/util/DifferentialSourceSpec.scala
new file mode 100644
index 00000000..0a2f83e5
--- /dev/null
+++ b/kamon-core-tests/src/test/scala/kamon/util/DifferentialSourceSpec.scala
@@ -0,0 +1,40 @@
+package kamon.util
+
+import org.scalatest.{Matchers, WordSpec}
+
+class DifferentialSourceSpec extends WordSpec with Matchers {
+
+ "a Differential Source" should {
+ "get the difference between the last two observations" in {
+ val source = sourceOf(0, 0, 1, 1, 2, 3, 4, 6, 8, 10, 12, 16, 18)
+ val expectedDiffs = Seq(0, 1, 0, 1, 1, 1, 2, 2, 2, 2, 4, 2)
+
+ values(expectedDiffs.length, source) should contain theSameElementsInOrderAs(expectedDiffs)
+ }
+
+ "ignore decrements in observations" in {
+ val source = sourceOf(10, 10, 5, 5, 10, 10)
+ val expectedDiffs = Seq(0, 0, 0, 5, 0)
+
+ values(expectedDiffs.length, source) should contain theSameElementsInOrderAs(expectedDiffs)
+ }
+ }
+
+ def sourceOf(numbers: Long*): DifferentialSource = DifferentialSource(new (() => Long) {
+ var remaining = numbers.toList
+
+ override def apply(): Long = {
+ if(remaining.isEmpty) 0 else {
+ val head = remaining.head
+ remaining = remaining.tail
+ head
+ }
+ }
+ })
+
+ def values(count: Int, source: DifferentialSource): Seq[Long] = {
+ for(_ <- 1 to count) yield source.get()
+ }
+}
+
+