-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5db11e
commit c39ed0f
Showing
2 changed files
with
77 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Cogniation is licensed under GPL-3.0. More info is found in ${basedir}/LICENSE. | ||
*/ | ||
package se.jesperolsson.cogniation; | ||
|
||
import java.util.Iterator; | ||
import org.takes.Request; | ||
import org.takes.Response; | ||
import org.takes.Take; | ||
import org.takes.rs.RsText; | ||
|
||
/** | ||
* Exercise for cognitive training or rehabilitation. | ||
* | ||
* An exercise is a series of association tasks that can be presented to the user. | ||
* | ||
* @since 0.1 | ||
*/ | ||
public final class Exercise implements Take { | ||
|
||
/** | ||
* The associations comprising the exercise. | ||
*/ | ||
private final Iterator<Association> associations; | ||
|
||
/** | ||
* Ctor. | ||
* | ||
* @param associations A series of association tasks. | ||
*/ | ||
public Exercise(final Iterator<Association> associations) { | ||
this.associations = associations; | ||
} | ||
|
||
@Override | ||
public Response act(final Request request) { | ||
return new RsText( | ||
this.associations.next().instructions() | ||
); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/test/java/se/jesperolsson/cogniation/ExerciseTest.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 @@ | ||
/* | ||
* Cogniation is licensed under GPL-3.0. More info is found in ${basedir}/LICENSE. | ||
*/ | ||
package se.jesperolsson.cogniation; | ||
|
||
import java.io.IOException; | ||
import org.cactoos.iterator.IteratorOf; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.takes.rq.RqFake; | ||
import org.takes.rs.RsPrint; | ||
|
||
/** | ||
* Tests for {@link Exercise}. | ||
* | ||
* @since 0.1 | ||
*/ | ||
public class ExerciseTest { | ||
|
||
@Test | ||
public void completeSeries() throws IOException { | ||
final String response = "Foo"; | ||
Assertions.assertEquals( | ||
response, | ||
new RsPrint( | ||
new Exercise( | ||
new IteratorOf( | ||
(Association) () -> response | ||
) | ||
).act( | ||
new RqFake("GET", "/") | ||
) | ||
).printBody() | ||
); | ||
} | ||
} |