-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Programming exercises: Add blackbox tests as another Java project type (
- Loading branch information
1 parent
9567be4
commit 12772a4
Showing
38 changed files
with
1,472 additions
and
50 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
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
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
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
Empty file.
31 changes: 31 additions & 0 deletions
31
src/main/resources/templates/java/maven_blackbox/exercise/pom.xml
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,31 @@ | ||
<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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>${packageName}</groupId> | ||
<artifactId>${exerciseNamePomXml}</artifactId> | ||
<packaging>jar</packaging> | ||
<version>1.0</version> | ||
<name>${exerciseNamePomXml}</name> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<build> | ||
<sourceDirectory>${project.basedir}/src</sourceDirectory> | ||
<resources> | ||
<resource> | ||
<directory>${project.basedir}/resources</directory> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.11.0</version> | ||
<configuration> | ||
<release>20</release> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
5 changes: 5 additions & 0 deletions
5
...ain/resources/templates/java/maven_blackbox/exercise/src/${packageNameFolder}/Client.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,5 @@ | ||
package ${packageName}; | ||
|
||
public class Client { | ||
// TODO: Create and implement interactive command line handling | ||
} |
134 changes: 134 additions & 0 deletions
134
src/main/resources/templates/java/maven_blackbox/readme
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,134 @@ | ||
# Sorting with the Strategy Pattern | ||
|
||
In this exercise, we want to implement sorting algorithms and control the program interactively via user input on the console. | ||
|
||
**Note:** This project is using `Maven`! You have to import the project as Maven project (not as Eclipse project) as otherwise, errors will occur and you won't be able to work on this exercise. | ||
|
||
### Part 1: User Input | ||
|
||
First, there has to be a way for the user to communicate with the program. | ||
The `Client` class should handle the user input. The following commands need to be supported by your implementation: | ||
|
||
`add date1 date2 ...`<br> | ||
Adds at least one date, but should also support multiple dates.<br> | ||
|
||
`sort`<br> | ||
Sorts the previously entered dates.<br> | ||
|
||
`clear`<br> | ||
Clears the list of dates.<br> | ||
|
||
`help`<br> | ||
Prints a dialog to the console that briefly explains the supported commands.<br> | ||
|
||
`print`<br> | ||
Prints the current list of dates to the console.<br> | ||
|
||
`quit`<br> | ||
Terminates the program.<br> | ||
|
||
Using a `BufferedReader` might be a good starting point. | ||
|
||
|
||
|
||
### Part 2: Sorting | ||
|
||
We need to implement two sorting algorithms, in this case `MergeSort` and `BubbleSort`. | ||
|
||
**You have the following tasks:** | ||
|
||
1. **Implement Bubble Sort**<br> | ||
Implement the method `performSort(List<Date>)` in the class `BubbleSort`. Make sure to follow the Bubble Sort algorithm exactly. | ||
|
||
2. **Implement Merge Sort**<br> | ||
Implement the method `performSort(List<Date>)` in the class `MergeSort`. Make sure to follow the Merge Sort algorithm exactly. | ||
|
||
### Part 3: Strategy Pattern | ||
|
||
We want the application to apply different algorithms for sorting a `List` of `Date` objects. | ||
Use the strategy pattern to select the right sorting algorithm at runtime. | ||
|
||
**You have the following tasks:** | ||
|
||
1. **SortStrategy Interface**<br> | ||
Create a `SortStrategy` interface and adjust the sorting algorithms so that they implement this interface. | ||
|
||
2. **Context Class**<br> | ||
Create and implement a `Context` class following the below class diagram | ||
|
||
3. **Context Policy**<br> | ||
Create and implement a `Policy` class following the below class diagram with a simple configuration mechanism: | ||
|
||
1. **Select MergeSort**<br> | ||
Select `MergeSort` when the List has more than 10 dates. | ||
|
||
2. **Select BubbleSort**<br> | ||
Select `BubbleSort` when the List has less or equal 10 dates. | ||
|
||
4. Complete the `Client` class which demonstrates switching between two strategies at runtime. | ||
|
||
@startuml | ||
|
||
class Client { | ||
} | ||
|
||
class Policy { | ||
+configure() | ||
} | ||
|
||
class Context { | ||
-dates: List<Date> | ||
+sort() | ||
} | ||
|
||
interface SortStrategy { | ||
+performSort(List<Date>) | ||
} | ||
|
||
class BubbleSort { | ||
+performSort(List<Date>) | ||
} | ||
|
||
class MergeSort { | ||
+performSort(List<Date>) | ||
} | ||
|
||
MergeSort -up-|> SortStrategy | ||
BubbleSort -up-|> SortStrategy | ||
Policy -right-> Context: context | ||
Context -right-> SortStrategy: sortAlgorithm | ||
Client .down.> Policy | ||
Client .down.> Context | ||
|
||
hide empty fields | ||
hide empty methods | ||
|
||
@enduml | ||
|
||
### Part 4: Tests | ||
|
||
This section shows you which tests are passed by your implementation. | ||
|
||
1. [task][Main method exists](MainMethodChecker) | ||
|
||
2. [task][All lines have <= 80 characters](LineLengthChecker) | ||
|
||
3. [task][Tests.txt exists and is not empty](FileExistsChecker) | ||
|
||
4. [task][Public Tests](dejagnu[public]) | ||
|
||
5. [task][Advanced Tests](dejagnu[advanced]) | ||
|
||
6. [task][Secret Tests](dejagnu[secret]) | ||
|
||
|
||
### Part 5: Optional Challenges | ||
|
||
(These are not tested) | ||
|
||
1. Create a new class `QuickSort` that implements `SortStrategy` and implement the Quick Sort algorithm. | ||
|
||
2. Make the method `performSort(List<Dates>)` generic, so that other objects can also be sorted by the same method. | ||
**Hint:** Have a look at Java Generics and the interface `Comparable`. | ||
|
||
3. Think about a useful decision in `Policy` when to use the new `QuickSort` algorithm. |
35 changes: 35 additions & 0 deletions
35
src/main/resources/templates/java/maven_blackbox/solution/Tests.txt
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,35 @@ | ||
sort> help | ||
add: adds the given Dates to the list (format: YYYY-MM-DD) | ||
clear: empties the list | ||
help: prints this text | ||
print: prints the list | ||
sort: sorts the list | ||
quit: quits the program | ||
sort> | ||
Unknown command. Use 'help' to show available commands. | ||
sort> help | ||
add: adds the given Dates to the list (format: YYYY-MM-DD) | ||
clear: empties the list | ||
help: prints this text | ||
print: prints the list | ||
sort: sorts the list | ||
quit: quits the program | ||
sort> 2015-04-01 | ||
Unknown command. Use 'help' to show available commands. | ||
sort> add 2015-04-01 | ||
sort> print | ||
[Wed Apr 01 02:00:00 CEST 2015] | ||
sort> add 2016-04-01 | ||
sort> add 2014-04-01 | ||
sort> add 2015-05-01 2015-04-30 | ||
sort> prinr | ||
Unknown command. Use 'help' to show available commands. | ||
sort> print | ||
[Wed Apr 01 02:00:00 CEST 2015, Fri Apr 01 02:00:00 CEST 2016, Tue Apr 01 02:00:00 CEST 2014, Fri May 01 02:00:00 CEST 2015, Thu Apr 30 02:00:00 CEST 2015] | ||
sort> sort | ||
sort> print | ||
[Tue Apr 01 02:00:00 CEST 2014, Wed Apr 01 02:00:00 CEST 2015, Thu Apr 30 02:00:00 CEST 2015, Fri May 01 02:00:00 CEST 2015, Fri Apr 01 02:00:00 CEST 2016] | ||
sort> clear | ||
sort> print | ||
[] | ||
sort> quit |
31 changes: 31 additions & 0 deletions
31
src/main/resources/templates/java/maven_blackbox/solution/pom.xml
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,31 @@ | ||
<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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>${packageName}</groupId> | ||
<artifactId>${exerciseNamePomXml}-Solution</artifactId> | ||
<packaging>jar</packaging> | ||
<version>1.0</version> | ||
<name>${exerciseNamePomXml} Solution</name> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<build> | ||
<sourceDirectory>${project.basedir}/src</sourceDirectory> | ||
<resources> | ||
<resource> | ||
<directory>${project.basedir}/resources</directory> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.11.0</version> | ||
<configuration> | ||
<release>20</release> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Oops, something went wrong.