Just a commit

This commit is contained in:
2016-08-15 14:08:39 -05:00
parent 0ef5df860d
commit ec4ec16ac2
50 changed files with 1972 additions and 7 deletions

View File

@@ -0,0 +1,31 @@
/**
* Simple HelloWorld singleton class as defined by the `Kotlin object keyword`.
* See: https://kotlinlang.org/docs/reference/object-declarations.html#object-declarations
*
* As an alternative one could create a class such as:
* ```
* class HelloWorld(name: String? = "Default Value") {
* fun hello(): String {
*
* }
* }
* ```
* Resulting in a call such as: `HelloWorld("Bob").hello()`
* See: https://kotlinlang.org/docs/reference/classes.html#constructors
*
* In Kotlin we make objects defined as nullable via the trailing `?`, if you try
* to assign a null value to any value that isn't nullable a compilation error is thrown.
* Kotlin makes sure you are accessing nullable values safely and provides null safe calls
* and the use of the elvis operator. See: https://kotlinlang.org/docs/reference/null-safety.html
*
* You may provide default values on methods, so if an argument is omitted the default is used.
* See: https://kotlinlang.org/docs/reference/functions.html#default-arguments
*
* Kotlin provides String interpolation to make String formatting simple.
* See: https://kotlinlang.org/docs/reference/idioms.html#string-interpolation
*/
object HelloWorld {
fun hello(name: String? = "Default Argument"): String {
}
}

View File

@@ -0,0 +1,32 @@
import kotlin.test.assertEquals
import org.junit.Test
class HelloWorldTest {
@Test
fun helloNoName() {
assertEquals("Hello, World!", HelloWorld.hello())
}
@Test
fun helloBlankName() {
assertEquals("Hello, World!", HelloWorld.hello(""))
assertEquals("Hello, World!", HelloWorld.hello(" "))
}
@Test
fun helloNullName() {
//This isn't advised in Kotlin but demonstrates the null safety in Kotlin
assertEquals("Hello, World!", HelloWorld.hello(null))
}
@Test
fun helloSampleName() {
assertEquals("Hello, Alice!", HelloWorld.hello("Alice"))
}
@Test
fun helloAnotherSampleName() {
assertEquals("Hello, Bob!", HelloWorld.hello("Bob"))
}
}