Skip to content

Instantly share code, notes, and snippets.

Avatar

Jarosław rozkminiacz

View GitHub Profile
View FibonacciParametrizedTest.kt
@RunWith(Parameterized::class)
class FibonacciTest(private val fInput: Int, private val fExpected: Int) {
@Test
fun test() {
assertEquals(fExpected, Fibonacci.compute(fInput))
}
companion object {
@JvmStatic
View distance-table.md
value [m] displayed string
753 753 m
1337 1.34 km
15888 15.9 km
31270 31 km
51000 >50 km
View distance-converter-full-parametrized-specification.kt
class DistanceConverterSpecificiation : Spek({
describe("distance converter") {
val testCases = mapOf(
61888.123 to ">50 km",
38777.23 to "38.8 km",
16984.44 to "17.0 km",
987.98 to "988 m"
)
val converter = DistanceConverter()
testCases.forEach { value, expectedValue ->
View testcases-distance-foreach.kt
testCases.forEach { value, expectedValue ->
on("$value"){
it("should print $expectedValue"){}
}
}
View distance-converter-mapof-test-cases.kt
val testCases = mapOf(
61888.123 to ">50 km",
38777.23 to "38.8 km",
16984.44 to "17.0 km",
987.98 to "988 m"
)
View spek-not-parametrized-distance.kt
class DistanceConverterSpecificiation : Spek({
describe("distance converter") {
val distanceConverter: DistanceConverter by memoized {
DistanceConverter()
}
on("distance 61888.123m") {
val testDistance = 61888.123
it("should return >50km") {
val convert = distanceConverter.convert(testDistance)
assertTrue(convert.contentEquals(">50km"))
View junit4-parameters.java
@Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
{ 0, 0 }, { 1, 1 }, { 2, 1 }
});
}
View SpekExtensions#extensions.kt
given("no people in repository"){
val view: PeopleListContract.View = mock()
val repository : Repository<Person> = mock {
on { getAll() } doReturn Single.error(Error("no data"))
}
val presenter = PeopleListPresenter(repository)
on("presenter attach"){
presenter.attach(view)
presenterAttachStandardFlow(view, presenter){
it("should not add anything to view"){
View SpekExtensions#detach.kt
fun SpecBody.detachPresenterAction(presenter: PeopleListPresenter) {
on("presenter detach") {
presenter.detach()
it("should detach view") {
Assert.assertNull(presenter.view)
}
}
}
View PeopleListTest#nopeople.kt
given("no people in repository"){
val view: PeopleListContract.View = mock()
val repository : Repository<Person> = mock {
on { getAll() } doReturn Single.error(Error("no data"))
}
val presenter = PeopleListPresenter(repository)
on("presenter attach"){
presenter.attach(view)
presenterAttachStandardFlow(view, presenter){
it("should not add anything to view"){