Skip to content

Commit

Permalink
#11 Introduce Exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperolsson-se committed Sep 15, 2021
1 parent b5db11e commit c39ed0f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/main/java/se/jesperolsson/cogniation/Exercise.java
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 src/test/java/se/jesperolsson/cogniation/ExerciseTest.java
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()
);
}
}

0 comments on commit c39ed0f

Please sign in to comment.