This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Node(val data: Int, var next: Node? = null) | |
fun reverseList(head: Node?): Node? = ... //implement this |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun firstIndexOfNthMostFrequentChar(str: String, n: Int): Int { | |
val countsMap = createCountsMap(str) | |
if (countsMap.size < n) { | |
return -1 | |
} | |
val sortedKeyValuePairs = sortKeyValuePairs(countsMap) | |
val ch = sortedKeyValuePairs[n-1].first | |
return str.indexOf(ch, 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Given a string return the index of the first apperance of the n-th most frequent letter | |
* If two letters are equally frequent return the matching index of any of the the two | |
* Examples: "aabbbc" , 3 will return 5 , "aabbbbc", 1 will return 2 | |
*/ | |
fun firstIndexOfNthMostFrequentChar(str: String, n: Int): Int { | |
val countsMap = createCountsMap(str) | |
if (countsMap.size < n) { | |
return -1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum class Beverage { MILK, SODA, WATER, JUICE } | |
enum class Main { NUGGETS, HOT_DOG, HAMBURGER } | |
enum class Side { FRIES, APPLE_SLICES } | |
enum class Size { SMALL, MEDIUM, LARGE } | |
@JvmOverloads | |
fun makeMealOrder(drink: Beverage = Beverage.MILK, mainPart: Main = Main.HAMBURGER, size: Size = Size.MEDIUM , side: Side = Side.FRIES) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* DDB Enhanced client mapper annotations can be applied only to methods. | |
* This is why we cannot use a data class here. | |
*/ | |
@DynamoDbBean | |
class Person(personId: String, name: String, familyName: String) { | |
@get:DynamoDbPartitionKey | |
var personId = personId; | |
@get:DynamoDbSecondaryPartitionKey(indexNames = ["familyName-index"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@DynamoDBTable(tableName = "Person") | |
data class Person( | |
@DynamoDBHashKey(attributeName = "personId") | |
var personId: String = "", | |
@DynamoDBAttribute(attributeName = "name") | |
var name: String = "", | |
@DynamoDBIndexHashKey(globalSecondaryIndexName = "familyName-index", attributeName = "familyName") | |
var familyName: String = "", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package blog.post.blms.proxy | |
import blog.post.Item | |
import blog.post.ItemsManager | |
import blog.post.PaginatedList | |
import blog.post.blms.Book | |
import blog.post.blms.Library | |
import io.mockk.* | |
import org.junit.jupiter.api.Assertions.assertEquals | |
import org.junit.jupiter.api.BeforeEach |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@TestFactory | |
fun `successful call to listBooks`(): List<DynamicTest> = | |
listOf( | |
ListBooksTestCase( | |
"Getting list of items", | |
testLibrary.identifier, | |
itemsList(book1.toItem(), book2.toItem()), | |
booksList(book1, book2) | |
), | |
ListBooksTestCase( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun ListBooksTestCase.`successful call to listBooks`(): DynamicTest { | |
return DynamicTest.dynamicTest(description) { | |
// Arrange | |
every { | |
itemsManager.getItems(testLibrary.identifier, ofNullable(maxResults), ofNullable(nextToken)) | |
} returns (returnedItems) | |
//Act | |
val actualBooks = booksDataProvider.listBooks(testLibrary.identifier, maxResults, nextToken) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val testLibrary = Library(randomUUID(), "Town library", "1200 Oak St") | |
private val book1 = Book(randomUUID(), "Foundation and earth", "Sci-Fi") | |
private val book2 = Book(randomUUID(), "Lord of the rings", "Fantasy") |