Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
}
}