Skip to content

Instantly share code, notes, and snippets.

@cmaier
Created May 24, 2017 05:00
Show Gist options
  • Save cmaier/ccf2b40b60b05d5f035410cdc5319cfb to your computer and use it in GitHub Desktop.
Save cmaier/ccf2b40b60b05d5f035410cdc5319cfb to your computer and use it in GitHub Desktop.
package me.sieben.kotlinutils
import io.kotlintest.matchers.shouldBe
import io.kotlintest.specs.WordSpec
import org.junit.Assert.assertNotNull
class AdditionalTuplesTest : WordSpec() {
init {
"Pair.letNotNull()" should {
"execute the higher order function if both values are nonnull" {
(Pair(1, 2).letNotNull { a, b ->
assertNotNull(a)
assertNotNull(b)
true
} ?: false) shouldBe true
(Pair(null, 2).letNotNull { _, _ -> true } ?: false) shouldBe false
}
}
"Triple.letNotNull()" should {
"execute the higher order function if all values are nonnull" {
(Triple(1, 2, 3).letNotNull { a, b, c ->
assertNotNull(a)
assertNotNull(b)
assertNotNull(c)
true
} ?: false) shouldBe true
(Triple(null, 2, 3).letNotNull { _, _, _ -> true } ?: false) shouldBe false
}
}
"Quadruple.toString()" should {
"return a comma separated string" {
Quadruple(1, 2, 3, 4).toString() shouldBe "(1, 2, 3, 4)"
}
}
"Quadruple.letNotNull()" should {
"execute the higher order function if all values are nonnull" {
(Quadruple(1, 2, 3, 4).letNotNull { a, b, c, d ->
assertNotNull(a)
assertNotNull(b)
assertNotNull(c)
assertNotNull(d)
true
} ?: false) shouldBe true
(Quadruple(null, 2, 3, 4).letNotNull { _, _, _, _ -> true } ?: false) shouldBe false
}
}
"Sextuple.toString()" should {
"return a comma separated string" {
Sextuple(1, 2, 3, 4, 5, 6).toString() shouldBe "(1, 2, 3, 4, 5, 6)"
}
}
"Sextuple.letNotNull()" should {
"execute the higher order function if all values are nonnull" {
(Sextuple(1, 2, 3, 4, 5, 6).letNotNull { a, b, c, d, e, f ->
assertNotNull(a)
assertNotNull(b)
assertNotNull(c)
assertNotNull(d)
assertNotNull(e)
assertNotNull(f)
true
} ?: false) shouldBe true
(Sextuple(null, 2, 3, 4, 5, 6).letNotNull { _, _, _, _, _, _ -> true } ?: false) shouldBe false
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment