|
| 1 | +package de.ronny_h.aoc.extensions.threedim |
| 2 | + |
| 3 | +import de.ronny_h.aoc.extensions.threedim.Vector.Companion.ZERO |
| 4 | +import io.kotest.core.spec.style.StringSpec |
| 5 | +import io.kotest.data.forAll |
| 6 | +import io.kotest.data.row |
| 7 | +import io.kotest.matchers.shouldBe |
| 8 | + |
| 9 | +class VectorTest : StringSpec({ |
| 10 | + "vectors can be added" { |
| 11 | + forAll( |
| 12 | + row(Vector(0, 0, 0), Vector(0, 0, 0), Vector(0, 0, 0)), |
| 13 | + row(Vector(10, 20, 30), Vector(1, 2, 3), Vector(11, 22, 33)), |
| 14 | + row(Vector(10, 20, 30), Vector(-1, -2, -3), Vector(9, 18, 27)), |
| 15 | + ) { a, b, sum -> |
| 16 | + a + b shouldBe sum |
| 17 | + } |
| 18 | + } |
| 19 | + |
| 20 | + "vectors can be subtracted" { |
| 21 | + forAll( |
| 22 | + row(Vector(0, 0, 0), Vector(0, 0, 0), Vector(0, 0, 0)), |
| 23 | + row(Vector(10, 20, 30), Vector(1, 2, 3), Vector(9, 18, 27)), |
| 24 | + row(Vector(10, 20, 30), Vector(-1, -2, -3), Vector(11, 22, 33)), |
| 25 | + ) { a, b, difference -> |
| 26 | + a - b shouldBe difference |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + "the taxi distance of vectors" { |
| 31 | + forAll( |
| 32 | + row(Vector(0, 0, 0), Vector(0, 0, 0), 0), |
| 33 | + row(Vector(10, 20, 30), Vector(11, 22, 33), 6), |
| 34 | + row(Vector(10, 20, 30), Vector(9, 18, 27), 6), |
| 35 | + ) { a, b, distance -> |
| 36 | + a taxiDistanceTo b shouldBe distance |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + "the absolute of a vector" { |
| 41 | + forAll( |
| 42 | + row(Vector(0, 0, 0), 0.0), |
| 43 | + row(Vector(3, 3, 3), 3.0), |
| 44 | + ) { v, absolute -> |
| 45 | + v.abs() shouldBe absolute |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + "scalar multiplication with an Int" { |
| 50 | + forAll( |
| 51 | + row(0, Vector(1, 2, 3), ZERO), |
| 52 | + row(1, Vector(1, 2, 3), Vector(1, 2, 3)), |
| 53 | + row(10, Vector(1, 2, 3), Vector(10, 20, 30)), |
| 54 | + ) { a, v, product -> |
| 55 | + a * v shouldBe product |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + "scalar multiplication with a Long" { |
| 60 | + forAll( |
| 61 | + row(0L, Vector(1, 2, 3), ZERO), |
| 62 | + row(1L, Vector(1, 2, 3), Vector(1, 2, 3)), |
| 63 | + row(10L, Vector(1, 2, 3), Vector(10, 20, 30)), |
| 64 | + ) { a, v, product -> |
| 65 | + a * v shouldBe product |
| 66 | + } |
| 67 | + } |
| 68 | +}) |
0 commit comments