-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(6-kyu): kata/if-you-can-read-this-dot-dot-dot (#619)
- Loading branch information
1 parent
b210e2f
commit e0974c0
Showing
6 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# [If you can read this...](https://www.codewars.com/kata/if-you-can-read-this-dot-dot-dot "https://www.codewars.com/kata/586538146b56991861000293") | ||
|
||
[![The lyrics to \"Never gonna give you up\" by Rick Astley encoded in the NATO phonetic alphabet](https://9gag.com/photo/amrb4r9_700b.jpg)](http://9gag.com/gag/amrb4r9) | ||
|
||
## Task | ||
|
||
You'll have to translate a string to Pilot's | ||
alphabet ([NATO phonetic alphabet](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet)). | ||
|
||
**Input:** | ||
|
||
`If, you can read?` | ||
|
||
**Output:** | ||
|
||
`India Foxtrot , Yankee Oscar Uniform Charlie Alfa November Romeo Echo Alfa Delta ?` | ||
|
||
**Note:** | ||
|
||
- There is a preloaded dictionary that you can use, named `NATO`. It uses uppercase keys, e.g. `NATO['A']` is `"Alfa"`. | ||
See comments in the initial code to see how to access it in your language. | ||
- The set of used punctuation is `,.!?`. | ||
- Punctuation should be kept in your return string, but spaces should not. | ||
- __Xray__ should not have a dash within. | ||
- Every word and punctuation mark should be seperated by a space ' '. | ||
- There should be no trailing whitespace |
36 changes: 36 additions & 0 deletions
36
kata/6-kyu/if-you-can-read-this-dot-dot-dot/main/Helper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import static java.util.Map.entry; | ||
|
||
import java.util.Map; | ||
|
||
final class Helper { | ||
static final Map<Character, String> NATO = Map.ofEntries( | ||
entry('A', "Alfa"), | ||
entry('B', "Bravo"), | ||
entry('C', "Charlie"), | ||
entry('D', "Delta"), | ||
entry('E', "Echo"), | ||
entry('F', "Foxtrot"), | ||
entry('G', "Golf"), | ||
entry('H', "Hotel"), | ||
entry('I', "India"), | ||
entry('J', "Juliett"), | ||
entry('K', "Kilo"), | ||
entry('L', "Lima"), | ||
entry('M', "Mike"), | ||
entry('N', "November"), | ||
entry('O', "Oscar"), | ||
entry('P', "Papa"), | ||
entry('Q', "Quebec"), | ||
entry('R', "Romeo"), | ||
entry('S', "Sierra"), | ||
entry('T', "Tango"), | ||
entry('U', "Uniform"), | ||
entry('V', "Victor"), | ||
entry('W', "Whiskey"), | ||
entry('X', "Xray"), | ||
entry('Y', "Yankee"), | ||
entry('Z', "Zulu") | ||
); | ||
|
||
private Helper() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import static java.util.stream.Collectors.joining; | ||
|
||
interface Kata { | ||
static String toNATO(String string) { | ||
return string.replace(" ", "").toUpperCase().chars() | ||
.mapToObj(c -> Helper.NATO.getOrDefault((char) c, (char) c + "")).collect(joining(" ")); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
kata/6-kyu/if-you-can-read-this-dot-dot-dot/test/SolutionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
class SolutionTest { | ||
@ParameterizedTest | ||
@CsvSource(delimiter = '|', textBlock = """ | ||
If you can read | India Foxtrot Yankee Oscar Uniform Charlie Alfa November Romeo Echo Alfa Delta | ||
Did not see that coming | Delta India Delta November Oscar Tango Sierra Echo Echo Tango Hotel Alfa Tango Charlie Oscar Mike India November Golf | ||
go for it! | Golf Oscar Foxtrot Oscar Romeo India Tango ! | ||
the five boxing wizards jump quickly. | Tango Hotel Echo Foxtrot India Victor Echo Bravo Oscar Xray India November Golf Whiskey India Zulu Alfa Romeo Delta Sierra Juliett Uniform Mike Papa Quebec Uniform India Charlie Kilo Lima Yankee . | ||
PACK MY BOX WITH FIVE DOZEN LIQUOR JUGS? | Papa Alfa Charlie Kilo Mike Yankee Bravo Oscar Xray Whiskey India Tango Hotel Foxtrot India Victor Echo Delta Oscar Zulu Echo November Lima India Quebec Uniform Oscar Romeo Juliett Uniform Golf Sierra ? | ||
p ? u . n c t u , a t i o n ! | Papa ? Uniform . November Charlie Tango Uniform , Alfa Tango India Oscar November ! | ||
""") | ||
void sample(String input, String expected) { | ||
assertEquals(expected, Kata.toNATO(input)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters