diff --git a/.gitignore b/.gitignore index 0a03f29..65d08ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ \.vscode/ rust/test/target/ + diff --git a/kotlin/diamond/README.md b/kotlin/diamond/README.md new file mode 100644 index 0000000..21b4c10 --- /dev/null +++ b/kotlin/diamond/README.md @@ -0,0 +1,62 @@ +# Diamond + +The diamond kata takes as its input a letter, and outputs it in a diamond +shape. Given a letter, it prints a diamond starting with 'A', with the +supplied letter at the widest point. + +## Requirements + +* The first row contains one 'A'. +* The last row contains one 'A'. +* All rows, except the first and last, have exactly two identical letters. +* All rows have as many trailing spaces as leading spaces. (This might be 0). +* The diamond is horizontally symmetric. +* The diamond is vertically symmetric. +* The diamond has a square shape (width equals height). +* The letters form a diamond shape. +* The top half has the letters in ascending order. +* The bottom half has the letters in descending order. +* The four corners (containing the spaces) are triangles. + +## Examples + +In the following examples, spaces are indicated by `·` characters. + +Diamond for letter 'A': + +```plain +A +``` + +Diamond for letter 'C': + +```plain +··A·· +·B·B· +C···C +·B·B· +··A·· +``` + +Diamond for letter 'E': + +```plain +····A···· +···B·B··· +··C···C·· +·D·····D· +E·······E +·D·····D· +··C···C·· +···B·B··· +····A···· +``` + + + +## Source + +Seb Rose [http://claysnow.co.uk/recycling-tests-in-tdd/](http://claysnow.co.uk/recycling-tests-in-tdd/) + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/kotlin/diamond/build.gradle b/kotlin/diamond/build.gradle new file mode 100644 index 0000000..0e6528d --- /dev/null +++ b/kotlin/diamond/build.gradle @@ -0,0 +1,28 @@ +buildscript { + ext.kotlin_version = '1.1.1' + repositories { + mavenCentral() + } + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +apply plugin: 'kotlin' + +repositories { + mavenCentral() +} + +dependencies { + compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + + testCompile 'junit:junit:4.12' + testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" +} +test { + testLogging { + exceptionFormat = 'full' + events = ["passed", "failed", "skipped"] + } +} diff --git a/kotlin/diamond/src/main/kotlin/DiamondPrinter.kt b/kotlin/diamond/src/main/kotlin/DiamondPrinter.kt new file mode 100644 index 0000000..cff7e89 --- /dev/null +++ b/kotlin/diamond/src/main/kotlin/DiamondPrinter.kt @@ -0,0 +1,5 @@ +class DiamondPrinter { + + + +} diff --git a/kotlin/diamond/src/test/kotlin/DiamondPrinterTest.kt b/kotlin/diamond/src/test/kotlin/DiamondPrinterTest.kt new file mode 100644 index 0000000..2a563b6 --- /dev/null +++ b/kotlin/diamond/src/test/kotlin/DiamondPrinterTest.kt @@ -0,0 +1,121 @@ +import org.hamcrest.CoreMatchers.`is` +import org.junit.Assert.assertThat +import org.junit.Before +import org.junit.Ignore +import org.junit.Test + +/* + * version: 1.0.0 + */ +class DiamondPrinterTest { + + private lateinit var diamondPrinter: DiamondPrinter + + @Before + fun setUp() { + diamondPrinter = DiamondPrinter() + } + + @Test + fun testOneByOneDiamond() { + val output = diamondPrinter.printToList('A') + assertThat(output, `is`(listOf("A"))) + } + + @Ignore + @Test + fun testTwoByTwoDiamond() { + val output = diamondPrinter.printToList('B') + assertThat(output, `is`(listOf( + " A ", + "B B", + " A "))) + } + + @Ignore + @Test + fun testThreeByThreeDiamond() { + val output = diamondPrinter.printToList('C') + assertThat(output, `is`(listOf( + " A ", + " B B ", + "C C", + " B B ", + " A "))) + } + + @Ignore + @Test + fun testFiveByFiveDiamond() { + val output = diamondPrinter.printToList('E') + assertThat(output, `is`(listOf( + " A ", + " B B ", + " C C ", + " D D ", + "E E", + " D D ", + " C C ", + " B B ", + " A "))) + } + + @Ignore + @Test + fun testFullDiamond() { + val output = diamondPrinter.printToList('Z') + assertThat(output, `is`(listOf( + " A ", + " B B ", + " C C ", + " D D ", + " E E ", + " F F ", + " G G ", + " H H ", + " I I ", + " J J ", + " K K ", + " L L ", + " M M ", + " N N ", + " O O ", + " P P ", + " Q Q ", + " R R ", + " S S ", + " T T ", + " U U ", + " V V ", + " W W ", + " X X ", + " Y Y ", + "Z Z", + " Y Y ", + " X X ", + " W W ", + " V V ", + " U U ", + " T T ", + " S S ", + " R R ", + " Q Q ", + " P P ", + " O O ", + " N N ", + " M M ", + " L L ", + " K K ", + " J J ", + " I I ", + " H H ", + " G G ", + " F F ", + " E E ", + " D D ", + " C C ", + " B B ", + " A "))) + } + +} diff --git a/kotlin/saddle-points/.idea/workspace.xml b/kotlin/saddle-points/.idea/workspace.xml index 909db75..12a9d57 100644 --- a/kotlin/saddle-points/.idea/workspace.xml +++ b/kotlin/saddle-points/.idea/workspace.xml @@ -18,7 +18,7 @@ - + @@ -32,8 +32,8 @@ - - + + @@ -42,8 +42,8 @@ - - + + @@ -71,6 +71,11 @@ + + + @Ignore\n + + @@ -413,7 +420,7 @@ @@ -432,7 +439,6 @@ - @@ -475,6 +481,7 @@