1
1
Fork 0
AtomicKotlinCourse/Functional Programming/Manipulating Lists/Exercise 3/test/Tests.kt

82 lines
3.0 KiB
Kotlin
Raw Normal View History

package manipulatingListsExercise3
import org.junit.Assert
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runners.MethodSorters
2019-07-25 16:56:52 +03:00
import util.TIMEOUT
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
2019-10-16 17:16:07 +03:00
class TestManipulatingListsExercise3 {
2019-07-25 16:56:52 +03:00
@Test(timeout = TIMEOUT)
fun test2SimpleOneBookOneAuthor() {
val book = Book("Book", listOf(Author("Author")))
val list = listOf(book)
Assert.assertEquals("Wrong result for $list:",
2019-10-23 14:25:48 +03:00
mapOf(Author("Author") to listOf(book)),
authorBooksMap(list))
2019-07-25 16:56:52 +03:00
}
2019-07-25 16:56:52 +03:00
@Test(timeout = TIMEOUT)
fun test2SimpleOneBookTwoAuthors() {
val book = Book("Book", listOf(Author("first author"), Author("second author")))
val list = listOf(book)
Assert.assertEquals("Wrong result for $list:",
2019-10-23 14:25:48 +03:00
mapOf(Author("first author") to listOf(book),
Author("second author") to listOf(book)),
authorBooksMap(list))
2019-07-25 16:56:52 +03:00
}
2019-07-25 16:56:52 +03:00
@Test(timeout = TIMEOUT)
fun test2SimpleOneAuthorTwoBook() {
val list = listOf(Book("first Book", listOf(Author("Author"))),
2019-10-23 14:25:48 +03:00
Book("second Book", listOf(Author("Author"))))
2019-07-25 16:56:52 +03:00
Assert.assertEquals("Wrong result for $list:",
2019-10-23 14:25:48 +03:00
mapOf(Author("Author") to list),
authorBooksMap(list))
2019-07-25 16:56:52 +03:00
}
2019-07-25 16:56:52 +03:00
@Test(timeout = TIMEOUT)
fun test1Sample() {
val bruce = Author("Bruce Eckel")
val chuck = Author("Chuck Allison")
val dianne = Author("Dianne Marsh")
val dmitry = Author("Dmitry Jemerov")
val svetlana = Author("Svetlana Isakova")
2019-07-25 16:56:52 +03:00
val first = Book("Computer Interfacing with Pascal & C", listOf(bruce))
val second = Book("Using C++", listOf(bruce))
val third = Book("C++ Inside & Out", listOf(bruce))
val fourth = Book("Blackbelt C++: The Masters Collection", listOf(bruce))
val thinkingInCPlusPlus = Book("Thinking in C++: Introduction to Standard C++", listOf(bruce))
val thinkingInCPlusPlusVolume2 = Book("Thinking in C++, Vol. 2: Practical Programming", listOf(bruce, chuck))
val thinkingInJava = Book("Thinking in Java", listOf(bruce))
val flex = Book("First Steps in Flex", listOf(bruce))
val atomicScala = Book("Atomic Scala", listOf(bruce, dianne))
val onJava8 = Book("On Java 8", listOf(bruce))
val kotlinInAction = Book("Kotlin in Action", listOf(dmitry, svetlana))
val atomicKotlin = Book("Atomic Kotlin", listOf(bruce, svetlana))
val books = listOf(
2019-10-23 14:25:48 +03:00
first, second, third, fourth,
thinkingInCPlusPlus,
thinkingInCPlusPlusVolume2,
thinkingInJava,
flex,
atomicScala,
onJava8,
kotlinInAction,
atomicKotlin
2019-07-25 16:56:52 +03:00
)
val expected = mapOf(
2019-10-23 14:25:48 +03:00
bruce to listOf(first, second, third, fourth,
thinkingInCPlusPlus, thinkingInCPlusPlusVolume2,
thinkingInJava, flex, atomicScala, onJava8, atomicKotlin),
chuck to listOf(thinkingInCPlusPlusVolume2),
dianne to listOf(atomicScala),
dmitry to listOf(kotlinInAction),
svetlana to listOf(kotlinInAction, atomicKotlin)
2019-07-25 16:56:52 +03:00
)
val actual = authorBooksMap(books)
2019-07-25 16:56:52 +03:00
Assert.assertEquals("Wrong result for sample:", expected, actual)
}
}