Skip to content
Snippets Groups Projects
WriterSpec.scala 1.39 KiB
Newer Older
package readerwriter

import java.time.LocalDate

import org.scalatest._
import testutil.PendingIfUnimplemented

class WriterSpec extends FlatSpec with Matchers with AppendedClues with PendingIfUnimplemented {
  "collatzDepth" should "keep a log of the search" in {
    val (log, _) = Writers.collatzDepth(3).v
    log shouldBe List(
      "got 3, tripling plus one",
      "got 10, halving",
      "got 5, tripling plus one",
      "got 16, halving",
      "got 8, halving",
      "got 4, halving",
      "got 2, halving",
      "got 1, doing nothing",
    )
  }

  it should "return the right depth" in {
    val (_, depth) = Writers.collatzDepth(3).v
    depth shouldBe 7
  }

  "collatzSearch" should "keep a log, together with collatzDepth" in {
    val (log, _) = Writers.collatzSearch(1, 5).v
    log shouldBe List(
      "testing 1",
      "got 1, doing nothing",
      "depth was 0",
      "testing 2",
      "got 2, halving",
      "got 1, doing nothing",
      "depth was 1",
      "testing 3",
      "got 3, tripling plus one",
      "got 10, halving",
      "got 5, tripling plus one",
      "got 16, halving",
      "got 8, halving",
      "got 4, halving",
      "got 2, halving",
      "got 1, doing nothing",
      "depth was 7",
      "returning 3",
    )
  }

  it should "find the smallest number with at least given depth" in {
    val (_, res) = Writers.collatzSearch(1, 5).v
    res shouldBe 3
  }
}