-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'increase-coverage' into main
- Loading branch information
Showing
12 changed files
with
693 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
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
83 changes: 83 additions & 0 deletions
83
ktvn/src/test/kotlin/com/github/benpollarduk/ktvn/characters/NarratorTest.kt
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,83 @@ | ||
package com.github.benpollarduk.ktvn.characters | ||
|
||
import com.github.benpollarduk.ktvn.logic.Answer | ||
import com.github.benpollarduk.ktvn.logic.Answer.Companion.answer | ||
import com.github.benpollarduk.ktvn.logic.Question | ||
import com.github.benpollarduk.ktvn.logic.Question.Companion.question | ||
import com.github.benpollarduk.ktvn.logic.listeners.Acknowledges | ||
import com.github.benpollarduk.ktvn.logic.listeners.Answers | ||
import com.github.benpollarduk.ktvn.logic.listeners.Asks | ||
import com.github.benpollarduk.ktvn.logic.listeners.Narrates | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
|
||
class NarratorTest { | ||
private val narrates = object : Narrates { | ||
override fun invoke(line: String, acknowledgement: Acknowledges) { | ||
// nothing | ||
} | ||
} | ||
|
||
private val asks = object : Asks { | ||
override fun invoke(character: Character, question: Question, answers: Answers): Answer { | ||
return question.answers.first() | ||
} | ||
|
||
override fun invoke(narrator: Narrator, question: Question, answers: Answers): Answer { | ||
return question.answers.first() | ||
} | ||
} | ||
|
||
private val acknowledges = object : Acknowledges { | ||
override fun waitFor() { | ||
// nothing | ||
} | ||
} | ||
|
||
private val answers = object : Answers { | ||
override fun waitFor(question: Question): Answer { | ||
return question.answers.first() | ||
} | ||
} | ||
|
||
@Test | ||
fun `given a narrator when narrate then narrates is called`() { | ||
// Given | ||
var called = false | ||
val narrates = object : Narrates { | ||
override fun invoke(line: String, acknowledgement: Acknowledges) { | ||
called = true | ||
} | ||
} | ||
val narrator = Narrator(narrates, asks, acknowledges, answers) | ||
|
||
// When | ||
narrator.narrates("") | ||
|
||
// Then | ||
Assertions.assertTrue(called) | ||
} | ||
|
||
@Test | ||
fun `given a narrator when ask then asks is called`() { | ||
// Given | ||
var called = false | ||
val asks = object : Asks { | ||
override fun invoke(character: Character, question: Question, answers: Answers): Answer { | ||
return answer { } | ||
} | ||
|
||
override fun invoke(narrator: Narrator, question: Question, answers: Answers): Answer { | ||
called = true | ||
return answer { } | ||
} | ||
} | ||
val narrator = Narrator(narrates, asks, acknowledges, answers) | ||
|
||
// When | ||
narrator.asks(question { }) | ||
|
||
// Then | ||
Assertions.assertTrue(called) | ||
} | ||
} |
143 changes: 143 additions & 0 deletions
143
ktvn/src/test/kotlin/com/github/benpollarduk/ktvn/layout/LayoutTest.kt
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,143 @@ | ||
package com.github.benpollarduk.ktvn.layout | ||
|
||
import com.github.benpollarduk.ktvn.characters.Character | ||
import com.github.benpollarduk.ktvn.characters.Emotion | ||
import com.github.benpollarduk.ktvn.characters.Narrator | ||
import com.github.benpollarduk.ktvn.layout.Positions.left | ||
import com.github.benpollarduk.ktvn.layout.Positions.right | ||
import com.github.benpollarduk.ktvn.logic.Answer | ||
import com.github.benpollarduk.ktvn.logic.Question | ||
import com.github.benpollarduk.ktvn.logic.listeners.Acknowledges | ||
import com.github.benpollarduk.ktvn.logic.listeners.Answers | ||
import com.github.benpollarduk.ktvn.logic.listeners.Asks | ||
import com.github.benpollarduk.ktvn.logic.listeners.Emotes | ||
import com.github.benpollarduk.ktvn.logic.listeners.Moves | ||
import com.github.benpollarduk.ktvn.logic.listeners.Speaks | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
|
||
class LayoutTest { | ||
private val speaks = object : Speaks { | ||
override fun invoke(character: Character, line: String, acknowledgement: Acknowledges) { | ||
// nothing | ||
} | ||
} | ||
|
||
private val emotes = object : Emotes { | ||
override fun invoke(character: Character, emotion: Emotion, acknowledgement: Acknowledges) { | ||
// nothing | ||
} | ||
} | ||
|
||
private val asks = object : Asks { | ||
override fun invoke(character: Character, question: Question, answers: Answers): Answer { | ||
return question.answers.first() | ||
} | ||
|
||
override fun invoke(narrator: Narrator, question: Question, answers: Answers): Answer { | ||
return question.answers.first() | ||
} | ||
} | ||
|
||
private val acknowledges = object : Acknowledges { | ||
override fun waitFor() { | ||
// nothing | ||
} | ||
} | ||
|
||
private val answers = object : Answers { | ||
override fun waitFor(question: Question): Answer { | ||
return question.answers.first() | ||
} | ||
} | ||
|
||
@Test | ||
fun `given layout when add character then one character`() { | ||
// Given | ||
val layout = Layout.createLayout { } | ||
val character = Character("", speaks, emotes, asks, acknowledges, acknowledges, answers) | ||
|
||
// When | ||
layout.add(character, left) | ||
|
||
// Then | ||
Assertions.assertEquals(1, layout.characters) | ||
} | ||
|
||
@Test | ||
fun `given layout when add left of then one character`() { | ||
// Given | ||
val layout = Layout.createLayout { } | ||
val character = Character("", speaks, emotes, asks, acknowledges, acknowledges, answers) | ||
|
||
// When | ||
layout.addLeftOf(character) | ||
|
||
// Then | ||
Assertions.assertEquals(1, layout.characters) | ||
} | ||
|
||
@Test | ||
fun `given layout when add right of then one character`() { | ||
// Given | ||
val layout = Layout.createLayout { } | ||
val character = Character("", speaks, emotes, asks, acknowledges, acknowledges, answers) | ||
|
||
// When | ||
layout.addRightOf(character) | ||
|
||
// Then | ||
Assertions.assertEquals(1, layout.characters) | ||
} | ||
|
||
@Test | ||
fun `given layout when add above then one character`() { | ||
// Given | ||
val layout = Layout.createLayout { } | ||
val character = Character("", speaks, emotes, asks, acknowledges, acknowledges, answers) | ||
|
||
// When | ||
layout.addAbove(character) | ||
|
||
// Then | ||
Assertions.assertEquals(1, layout.characters) | ||
} | ||
|
||
@Test | ||
fun `given layout when add below then one character`() { | ||
// Given | ||
val layout = Layout.createLayout { } | ||
val character = Character("", speaks, emotes, asks, acknowledges, acknowledges, answers) | ||
|
||
// When | ||
layout.addBelow(character) | ||
|
||
// Then | ||
Assertions.assertEquals(1, layout.characters) | ||
} | ||
|
||
@Test | ||
fun `given layout when move character then moves is called`() { | ||
// Given | ||
var called = false | ||
val moves = object : Moves { | ||
override fun invoke( | ||
character: Character, | ||
fromPosition: Position, | ||
toPosition: Position, | ||
acknowledgement: Acknowledges | ||
) { | ||
called = true | ||
} | ||
} | ||
val layout = Layout.createLayout { it setMoves moves } | ||
val character = Character("", speaks, emotes, asks, acknowledges, acknowledges, answers) | ||
layout.add(character, left) | ||
|
||
// When | ||
layout.move(character, right) | ||
|
||
// Then | ||
Assertions.assertTrue(called) | ||
} | ||
} |
Oops, something went wrong.