Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
twitch
live-coding-fr
Commits
91a88727
Commit
91a88727
authored
May 20, 2021
by
Colin DAMON
Browse files
Diamond kata in java
parent
6a3ab8f3
Changes
13
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
91a88727
...
...
@@ -37,3 +37,4 @@ include:
-
local
:
"
/try-monade/.gitlab-ci.yml"
-
local
:
"
/java-puzzles/.gitlab-ci.yml"
-
local
:
"
/java-monades/.gitlab-ci.yml"
-
local
:
"
/java-diamond/.gitlab-ci.yml"
java-diamond/.gitlab-ci.yml
0 → 100644
View file @
91a88727
package-java-diamond
:
variables
:
PROJECT_FOLDER
:
"
java-diamond"
extends
:
.java
only
:
refs
:
-
master
-
merge_requests
changes
:
-
"
.gitlab-common-ci.yml"
-
"
java-diamond/**/*"
java-diamond/pom.xml
0 → 100644
View file @
91a88727
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<version>
1.0.0
</version>
<groupId>
fr.ippon.kata
</groupId>
<artifactId>
java-parent
</artifactId>
<relativePath>
../java-parent
</relativePath>
</parent>
<version>
1.0.0-SNAPSHOT
</version>
<artifactId>
diamond
</artifactId>
<name>
Diamond
</name>
<developers>
<developer>
<name>
Sara TABHABIK
</name>
</developer>
<developer>
<email>
cdamon@ippon.fr
</email>
<name>
Colin DAMON
</name>
</developer>
</developers>
</project>
java-diamond/readme.md
0 → 100644
View file @
91a88727
# Diamond
Résolution en Java du kata
[
Diamond
](
https://codingdojo.org/kata/Diamond/
)
.
-
**Auteurs**
: Sara TABHABIK et Colin DAMON
-
**Date**
: 20/05/2021
-
**Langage**
: Java
-
**Niveau**
: Moyen
-
**Replay**
:
[
Twitch
](
https://www.twitch.tv/videos/1028994816
)
java-diamond/src/main/java/fr/craft/kata/Diamond.java
0 → 100644
View file @
91a88727
package
fr.craft.kata
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.function.IntFunction
;
import
java.util.stream.Collectors
;
import
java.util.stream.IntStream
;
public
class
Diamond
{
public
static
List
<
String
>
of
(
char
size
)
{
List
<
String
>
diamond
=
IntStream
.
range
((
int
)
'A'
,
((
int
)
size
)
+
1
)
.
mapToObj
(
toLine
(
size
))
.
collect
(
Collectors
.
toList
());
List
<
String
>
secondPart
=
new
ArrayList
<>(
diamond
);
Collections
.
reverse
(
secondPart
);
secondPart
.
remove
(
0
);
diamond
.
addAll
(
secondPart
);
return
diamond
;
}
private
static
IntFunction
<
String
>
toLine
(
char
size
)
{
return
current
->
Line
.
of
((
char
)
current
,
size
)
.
representation
();
}
}
java-diamond/src/main/java/fr/craft/kata/Line.java
0 → 100644
View file @
91a88727
package
fr.craft.kata
;
public
record
Line
(
String
representation
)
{
public
static
Line
of
(
char
character
,
char
size
)
{
String
outerSpaces
=
outerSpaces
(
character
,
size
);
if
(
character
==
'A'
)
{
return
new
Line
(
outerSpaces
+
"A"
+
outerSpaces
);
}
return
new
Line
(
outerSpaces
+
character
+
innerSpaces
(
character
)
+
character
+
outerSpaces
);
}
private
static
String
outerSpaces
(
char
character
,
char
size
)
{
return
" "
.
repeat
(
size
-
character
);
}
private
static
String
innerSpaces
(
char
character
)
{
return
" "
.
repeat
(((
character
-
'A'
)
-
1
)
*
2
+
1
);
}
}
java-diamond/src/test/java/fr/craft/kata/DiamondTest.java
0 → 100644
View file @
91a88727
package
fr.craft.kata
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.*;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.List
;
import
org.junit.jupiter.api.Test
;
class
DiamondTest
{
@Test
void
shouldDrawDiamondOfA
()
{
assertThat
(
Diamond
.
of
(
'A'
)).
isEqualTo
(
diamond
(
'A'
));
}
@Test
void
shouldDrawDiamondOfB
()
{
assertThat
(
Diamond
.
of
(
'B'
)).
isEqualTo
(
diamond
(
'B'
));
}
@Test
void
shouldDrawDiamondOfC
()
{
assertThat
(
Diamond
.
of
(
'C'
)).
isEqualTo
(
diamond
(
'C'
));
}
@Test
void
shouldDrawDiamondOfD
()
{
assertThat
(
Diamond
.
of
(
'D'
)).
isEqualTo
(
diamond
(
'D'
));
}
private
List
<
String
>
diamond
(
char
file
)
{
try
{
return
Files
.
readAllLines
(
Paths
.
get
(
"src/test/resources/"
+
String
.
valueOf
(
file
)
.
toLowerCase
()
+
".txt"
));
}
catch
(
IOException
e
)
{
throw
new
AssertionError
(
e
.
getMessage
(),
e
);
}
}
}
java-diamond/src/test/java/fr/craft/kata/LineTest.java
0 → 100644
View file @
91a88727
package
fr.craft.kata
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.*;
import
org.junit.jupiter.api.Test
;
class
LineTest
{
@Test
void
shouldGetLetterALineForSizeA
()
{
assertThat
(
Line
.
of
(
'A'
,
'A'
)
.
representation
()).
isEqualTo
(
"A"
);
}
@Test
void
shouldGetLetterALineForSizeB
()
{
assertThat
(
Line
.
of
(
'A'
,
'B'
)
.
representation
()).
isEqualTo
(
" A "
);
}
@Test
void
shouldGetLetterBLineForSizeB
()
{
assertThat
(
Line
.
of
(
'B'
,
'B'
)
.
representation
()).
isEqualTo
(
"B B"
);
}
@Test
void
shouldGetLetterBLineForSizeC
()
{
assertThat
(
Line
.
of
(
'B'
,
'C'
)
.
representation
()).
isEqualTo
(
" B B "
);
}
@Test
void
shouldGetLetterDLineForSizeD
()
{
assertThat
(
Line
.
of
(
'D'
,
'D'
)
.
representation
())
.
isEqualTo
(
"D"
+
" "
.
repeat
(
5
)
+
"D"
);
}
}
java-diamond/src/test/resources/a.txt
0 → 100644
View file @
91a88727
A
\ No newline at end of file
java-diamond/src/test/resources/b.txt
0 → 100644
View file @
91a88727
A
B B
A
\ No newline at end of file
java-diamond/src/test/resources/c.txt
0 → 100644
View file @
91a88727
A
B B
C C
B B
A
\ No newline at end of file
java-diamond/src/test/resources/d.txt
0 → 100644
View file @
91a88727
A
B B
C C
D D
C C
B B
A
\ No newline at end of file
readme.md
View file @
91a88727
...
...
@@ -43,6 +43,7 @@ Un kata de code est un petit exercice pensé pour s'entrainer jusqu'à maitriser
-
[
Bowling Game
](
/bowling-game
)
-
[
Tennis Refactoring kata
](
/tennis/refactoring
)
-
[
Puzzles
](
java-puzzles
)
-
[
Diamond
](
java-diamond
)
### Énervé
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment