Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haloweentrickortreatkata
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nordine AZZA
haloweentrickortreatkata
Commits
0fcef7e8
Commit
0fcef7e8
authored
Mar 11, 2020
by
Nordine AZZA
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wip kata
parents
Pipeline
#25117
failed with stages
in 44 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
166 additions
and
0 deletions
+166
-0
.gitignore
.gitignore
+3
-0
pom.xml
pom.xml
+46
-0
src/main/java/kata/HalloweenKata.java
src/main/java/kata/HalloweenKata.java
+45
-0
src/main/java/kata/TrickOrTreatException.java
src/main/java/kata/TrickOrTreatException.java
+4
-0
src/test/java/kata/HalloweenKataTest.java
src/test/java/kata/HalloweenKataTest.java
+68
-0
No files found.
.gitignore
0 → 100644
View file @
0fcef7e8
.idea
target
*.iml
pom.xml
0 → 100644
View file @
0fcef7e8
<?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>
<groupId>
org.example
</groupId>
<artifactId>
HalloweenTrickOrTreat
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<build>
<plugins>
<plugin>
<artifactId>
maven-compiler-plugin
</artifactId>
<configuration>
<encoding>
UTF-8
</encoding>
<source>
11
</source>
<target>
11
</target>
</configuration>
</plugin>
<plugin>
<artifactId>
maven-surefire-plugin
</artifactId>
<version>
2.22.1
</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter-engine
</artifactId>
<version>
5.3.1
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.assertj
</groupId>
<artifactId>
assertj-core
</artifactId>
<version>
3.11.1
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
</project>
src/main/java/kata/HalloweenKata.java
0 → 100644
View file @
0fcef7e8
package
kata
;
import
java.util.List
;
public
class
HalloweenKata
{
public
static
final
String
CANDY
=
"candy"
;
public
static
final
String
TRICK_OR_TREAT
=
"Trick or treat!"
;
public
static
final
String
THANK_YOU_STRANGE_UNCLE
=
"Thank you, strange uncle!"
;
public
static
final
String
BOMB
=
"bomb"
;
public
String
trickOrTreat
(
int
nbChildren
,
List
<
List
<
String
>>
packets
)
{
if
(
nbChildren
>
packets
.
size
())
{
return
TRICK_OR_TREAT
;
}
try
{
areValid
(
packets
);
}
catch
(
TrickOrTreatException
e
)
{
return
TRICK_OR_TREAT
;
}
return
THANK_YOU_STRANGE_UNCLE
;
}
private
void
areValid
(
List
<
List
<
String
>>
packets
)
throws
TrickOrTreatException
{
int
firstCandiesAmount
=
-
1
;
for
(
List
<
String
>
packet
:
packets
)
{
int
candiesNumber
=
0
;
for
(
String
item
:
packet
)
{
if
(
BOMB
.
equals
(
item
))
{
throw
new
TrickOrTreatException
();
}
else
if
(
CANDY
.
equals
(
item
))
{
candiesNumber
++;
}
}
if
(
candiesNumber
<
2
)
{
throw
new
TrickOrTreatException
();
}
if
(
firstCandiesAmount
<
0
)
{
firstCandiesAmount
=
candiesNumber
;
}
else
if
(
firstCandiesAmount
!=
candiesNumber
)
{
throw
new
TrickOrTreatException
();
}
}
}
}
src/main/java/kata/TrickOrTreatException.java
0 → 100644
View file @
0fcef7e8
package
kata
;
public
class
TrickOrTreatException
extends
Exception
{
}
src/test/java/kata/HalloweenKataTest.java
0 → 100644
View file @
0fcef7e8
package
kata
;
import
org.junit.jupiter.api.DisplayName
;
import
org.junit.jupiter.api.Test
;
import
java.util.List
;
import
static
java
.
util
.
Arrays
.
asList
;
import
static
java
.
util
.
Collections
.
emptyList
;
import
static
java
.
util
.
Collections
.
singletonList
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
class
HalloweenKataTest
{
@Test
@DisplayName
(
"Children should say 'Trick or treat!' when there are no packets"
)
void
noPackets
()
{
assertThat
(
new
HalloweenKata
().
trickOrTreat
(
2
,
emptyList
())).
isEqualTo
(
"Trick or treat!"
);
}
@Test
@DisplayName
(
"Children should say 'Trick or treat!' when there are no enough packets"
)
void
noEnoughPackets
()
{
List
<
String
>
packet
=
asList
(
"candy"
,
"candy"
);
assertThat
(
new
HalloweenKata
().
trickOrTreat
(
2
,
singletonList
(
packet
))).
isEqualTo
(
"Trick or treat!"
);
}
@Test
@DisplayName
(
"Children should say 'Trick or treat!' when there are enough packets but candies are insufficient"
)
void
enoughPacketsInsufficientCandies
()
{
List
<
String
>
packet1
=
asList
(
"candy"
,
"apple"
);
List
<
String
>
packet2
=
asList
(
"candy"
,
"apple"
);
assertThat
(
new
HalloweenKata
().
trickOrTreat
(
2
,
asList
(
packet1
,
packet2
))).
isEqualTo
(
"Trick or treat!"
);
}
@Test
@DisplayName
(
"Children should say 'Trick or treat!' when one of them was given a bomb"
)
void
bomb
()
{
List
<
String
>
packet1
=
asList
(
"candy"
,
"candy"
,
"bomb"
);
List
<
String
>
packet2
=
asList
(
"candy"
,
"candy"
);
assertThat
(
new
HalloweenKata
().
trickOrTreat
(
2
,
asList
(
packet1
,
packet2
))).
isEqualTo
(
"Trick or treat!"
);
}
@Test
@DisplayName
(
"Children should say 'Thank you, strange uncle!' when there are enough candies"
)
void
onlyCandiesEnoughCandies
()
{
List
<
String
>
packet1
=
asList
(
"candy"
,
"candy"
);
List
<
String
>
packet2
=
asList
(
"candy"
,
"candy"
);
assertThat
(
new
HalloweenKata
().
trickOrTreat
(
2
,
asList
(
packet1
,
packet2
))).
isEqualTo
(
"Thank you, strange uncle!"
);
}
@Test
@DisplayName
(
"Children should say 'Thank you, strange uncle!' when enough packets, no bomb and same amount of candies"
)
void
enoughCandiesNoBomb
()
{
List
<
String
>
packet1
=
asList
(
"candy"
,
"candy"
,
"apple"
);
List
<
String
>
packet2
=
asList
(
"candy"
,
"candy"
);
assertThat
(
new
HalloweenKata
().
trickOrTreat
(
2
,
asList
(
packet1
,
packet2
))).
isEqualTo
(
"Thank you, strange uncle!"
);
}
@Test
@DisplayName
(
"Children should say 'Trick or treat!' when enough packets and not same amount of candies"
)
void
enoughCandiesButNotSameAmount
()
{
List
<
String
>
packet1
=
asList
(
"candy"
,
"candy"
,
"candy"
);
List
<
String
>
packet2
=
asList
(
"candy"
,
"candy"
,
"apple"
);
assertThat
(
new
HalloweenKata
().
trickOrTreat
(
2
,
asList
(
packet1
,
packet2
))).
isEqualTo
(
"Trick or treat!"
);
}
}
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