Skip to content

Instantly share code, notes, and snippets.

@npryce
npryce / property-based-testing-tools.md
Last active Jun 7, 2021
Property-Based Testing Tools
View property-based-testing-tools.md

If you're coming to the Property-Based TDD As If You Meant It Workshop, you will need to bring a laptop with your favourite programming environment, a property-based testing library and, depending on the language, a test framework to run the property-based-tests.

Any other languages or suggestions? Comment below.

.NET (C#, F#, VB)

Python:

@npryce
npryce / string-char-to-int-pitfall.md
Created Jan 26, 2019
string-char-to-int-pitfall
View string-char-to-int-pitfall.md

In Kotlin String.toInt() and Char.toInt() do very different things.

>>> "9".toInt()
9
>>> '9'.toInt()
57
>>> 
@npryce
npryce / layout.kt
Created Dec 6, 2016
kotlin-layout-hack
View layout.kt
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
View wrapping-with-after-before.kt
fun TestContext<*>.withTestTiming() {
var start: Long? = null
before {
start = System.currentTimeMillis()
}
after {
start?.let {
val timeTaken = System.currentTimeMillis() - it
@npryce
npryce / fixture-with-descriptor.kt
Created Oct 31, 2018
Minutest Fixtures with Descriptors
View fixture-with-descriptor.kt
class Fixture {
val tempFile: File
}
fixture { testDescriptor ->
Fixture(System.createTempFile(testDescriptor.fullName.joinToString("/"), ".json"))
}
test {
doSomethingThatWritesTo(tempFile)
@npryce
npryce / merge-to-subdir
Last active Feb 13, 2018
Merge history from one Git repository as the history of a subdirectory of another Git repository
View merge-to-subdir
#!/bin/bash
# Usage: merge-to-subdir source-repo destination-repo subdir
#
# Merges the history of source-repo into destination-repo as the
# history of the subdirectory subdir.
#
# source-repo can be local or remote.
# destination-repo must be local to the machine.
# subdir can be a relative path, in which case intermediate
@npryce
npryce / reference-to-extension-method-of-nullable-type-via-nonnullable-type-pitfall.md
Created Jan 31, 2018
Taking a reference to an extension of a nullable type is possible through the non-nullable type, but probably not what you want!
View reference-to-extension-method-of-nullable-type-via-nonnullable-type-pitfall.md

E.g. the stdlib defines the following function:

fun CharSequence?.isNullOrBlank(): Boolean

You can take a reference to this extension function like this:

val isNullOrBlankFn = CharSequence?::isNullOrBlank
@npryce
npryce / speech_synthesis.kt
Created Dec 12, 2017
Kotlin definitions for the browser speech synthesis API
View speech_synthesis.kt
package browser
import org.w3c.dom.events.Event
import org.w3c.dom.events.EventTarget
typealias EventHandler<E> = (E) -> Unit
external val speechSynthesis: SpeechSynthesis
external class SpeechSynthesis : EventTarget {
@npryce
npryce / touch.kt
Created Dec 12, 2017
Kotlin definitions for browser touch API
View touch.kt
package browser
import org.w3c.dom.Element
import org.w3c.dom.events.UIEvent
typealias TouchId = Int
external interface Touch {
val identifier: TouchId
val target: Element
@npryce
npryce / kotlin-java-interop-overloading-pitfall.md
Last active Jul 30, 2017
Kotlin/Java interop method overloading pitfall
View kotlin-java-interop-overloading-pitfall.md

Given a Java library that defines overloaded methods for primitive and boxed types:

class X {
    public void m(int value) { ... }
    public void m(Integer value) { ... }
    ...
}