|
| 1 | +package com.baeldung.kotest.datadriven |
| 2 | + |
| 3 | +import io.kotest.core.spec.style.FunSpec |
| 4 | +import io.kotest.datatest.IsStableType |
| 5 | +import io.kotest.datatest.WithDataTestName |
| 6 | +import io.kotest.datatest.withData |
| 7 | +import io.kotest.matchers.shouldBe |
| 8 | + |
| 9 | +class PythagoreanTripleTest : FunSpec({ |
| 10 | + context("Pythagorean triples tests") { |
| 11 | + withData( |
| 12 | + DefaultPythagTriple(3, 4, 5), |
| 13 | + DefaultPythagTriple(6, 8, 10), |
| 14 | + DefaultPythagTriple(8, 15, 17), |
| 15 | + DefaultPythagTriple(7, 24, 25) |
| 16 | + ) { (a, b, c) -> |
| 17 | + isPythagTriple(a, b, c) shouldBe true |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | + context("StablePythagorean triples tests") { |
| 22 | + withData( |
| 23 | + StablePythagTriple(3, 4, 5), |
| 24 | + StablePythagTriple(6, 8, 10), |
| 25 | + StablePythagTriple(8, 15, 17), |
| 26 | + StablePythagTriple(7, 24, 25) |
| 27 | + ) { (a, b, c) -> |
| 28 | + isPythagTriple(a, b, c) shouldBe true |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + context("NamedPythagorean triples tests") { |
| 33 | + withData( |
| 34 | + NamedPythagTriple(3, 4, 5), |
| 35 | + NamedPythagTriple(6, 8, 10), |
| 36 | + NamedPythagTriple(8, 15, 17), |
| 37 | + NamedPythagTriple(7, 24, 25) |
| 38 | + ) { (a, b, c) -> |
| 39 | + isPythagTriple(a, b, c) shouldBe true |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + context("Pythagorean triples tests with map") { |
| 44 | + withData( |
| 45 | + mapOf( |
| 46 | + "3, 4, 5" to DefaultPythagTriple(3, 4, 5), |
| 47 | + "6, 8, 10" to DefaultPythagTriple(6, 8, 10), |
| 48 | + "8, 15, 17" to DefaultPythagTriple(8, 15, 17), |
| 49 | + "7, 24, 25" to DefaultPythagTriple(7, 24, 25) |
| 50 | + ) |
| 51 | + ) { (a, b, c) -> |
| 52 | + isPythagTriple(a, b, c) shouldBe true |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + context("Pythagorean triples tests with name function") { |
| 57 | + withData( |
| 58 | + nameFn = { "${it.a}__${it.b}__${it.c}" }, |
| 59 | + DefaultPythagTriple(3, 4, 5), |
| 60 | + DefaultPythagTriple(6, 8, 10), |
| 61 | + DefaultPythagTriple(8, 15, 17), |
| 62 | + DefaultPythagTriple(7, 24, 25) |
| 63 | + ) { (a, b, c) -> |
| 64 | + isPythagTriple(a, b, c) shouldBe true |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + context("each service should support all HTTP methods") { |
| 69 | + val services = listOf("http://internal.foo", "http://internal.bar", "http://public.baz") |
| 70 | + val methods = listOf("GET", "POST", "PUT") |
| 71 | + withData(services) { service -> |
| 72 | + withData(methods) { method -> |
| 73 | + println("$service $method") // test service against method |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | +}) |
| 79 | + |
| 80 | +data class DefaultPythagTriple(val a: Int, val b: Int, val c: Int) |
| 81 | + |
| 82 | +@IsStableType |
| 83 | +data class StablePythagTriple(val a: Int, val b: Int, val c: Int) |
| 84 | + |
| 85 | +data class NamedPythagTriple(val a: Int, val b: Int, val c: Int) : WithDataTestName { |
| 86 | + override fun dataTestName() = "Pythagorean Triple: $a, $b, $c" |
| 87 | +} |
0 commit comments