Advent of Code 2022, Day six - Sanitizer
This image is generated using Dall-EPrompt: Generate an image of elves in a submarine scanning the ocean floor with sonar rays in a minimalistic flat design
Preface
The objective of the sixth day is available on the advent of code website, so it won’t be shared here. On this page only the steps of achieving a solution are given with a solution build in Kotlin.
Design
When reading through the assignment we see that the sanitizer isn’t very complex. We have an input-file with a single string as the input. So our sanitizer can just return that single line and trim the start and end of it.
Because this sanitizer is pretty basic, we’re not going to create a design.
Implementation
Sanitizer
Now we now that we want to get a string from the input-data, we create a getDatastreamBuffers()
method with the return type of String?
.
getStacks method
1
2
3
4
5
6
7
8
class Sanitizer(
private val resource: URL?
) {
fun getDatastreamBuffers(): String? =
resource
?.readText()
?.trim()
}
Test case
To validate that our sanitizer works as expected, we can validate that the output is a string of the test-data we’ve got from the assignment.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class SanitizerTest {
@Test
fun testGetItems() {
// Arrange
val input = {}::class.java.getResource("/input_part_two.txt")
val expectedData = "mjqjpqmgbljsphdztnvjfqwrcgsmlb"
val sut = Sanitizer(input)
// Act
val actualData = sut.getDatastreamBuffers()
// Assert
assertEquals(expectedData, actualData)
}
}
Categories
Related articles