1
1
Fork 0

Added placeholders for new exercises added by Bruce

This commit is contained in:
Svetlana Isakova 2020-01-02 11:54:04 +01:00
parent 33714d5e9b
commit c2f47d3cee
87 changed files with 819 additions and 481 deletions

View File

@ -0,0 +1 @@
// type your solution here

View File

@ -1,35 +1,6 @@
type: edu
files:
- name: src/GameElements.kt
- name: src/Task.kt
visible: true
placeholders:
- offset: 380
length: 38
placeholder_text: |-
GameElement {
override val symbol = '#'
override val sharesCell = false
override fun play(maze: Maze) {
// Default implementation: do nothing
}
}
- offset: 433
length: 37
placeholder_text: |-
GameElement {
override val symbol = '.'
override val sharesCell = true
override fun play(maze: Maze) {
// Default implementation: do nothing
}
}
- name: test/Tests.kt
visible: false
feedback_link: |
https://docs.google.com/forms/d/e/1FAIpQLSdkaliSwYkjiV21bZl0yP-In2g5p17sAQCfaGjyHx_QYMWTiQ/viewform?usp=pp_url&entry.189755027=Object-Oriented+Programming+%2F+Base+Class+Initialization+%2F+Exercise1

View File

@ -1,14 +1,7 @@
## Base Class Initialization (#1)
This is the markdown document.
Change the implementations of `Wall` and `Food` classes, so that they extended
the `StaticElement` class instead of implementing `GameElement` interface
directly. Pass the corresponding values for `symbol` and `sharesCell`
properties as function arguments. Note that you no longer need to provide
implementation of `play()` function: the trivial implementation is
inherited from the base class.
Write your task text here
The `sharesCell` property specifies whether a mobile element like `Robot` or
`Monster` can step at the same cell. For instance, a robot can be on the same
cell with food or bomb (in this case food is eaten or bomb is exploded), but it
can't share the cell with the wall. The wall occupies the whole cell and
doesn't allow any movement to this cell.
<div class="hint">
Hints can be added anywhere in task text: type "hint" and press Tab.
</div>

View File

@ -1,26 +1,9 @@
package baseClassInitializationExercise1
import org.junit.Assert
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runners.MethodSorters
import util.TIMEOUT
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class TestBaseClassInitializationExercise1 {
@Test(timeout = TIMEOUT)
fun test1Sample() {
val wall = Wall()
Assert.assertEquals("Wrong value for wall.symbol", '#', wall.symbol)
Assert.assertEquals("Wrong value for wall.sharesCell", false, wall.sharesCell)
val food = Food()
Assert.assertEquals("Wrong value for food.symbol", '.', food.symbol)
Assert.assertEquals("Wrong value for food.sharesCell", true, food.sharesCell)
val elements: List<Any> = listOf(wall, food)
Assert.assertTrue("Wall and Food should extend StaticElement", elements.all {
(it is StaticElement)
})
}
class Test {
@Test fun testSolution() {
//TODO: implement your test here
Assert.assertTrue("Tests not implemented for the task", false)
}
}

View File

@ -0,0 +1 @@
// type your solution here

View File

@ -0,0 +1,6 @@
type: edu
files:
- name: src/Task.kt
visible: true
- name: test/Tests.kt
visible: false

View File

@ -0,0 +1,7 @@
This is the markdown document.
Write your task text here
<div class="hint">
Hints can be added anywhere in task text: type "hint" and press Tab.
</div>

View File

@ -0,0 +1,9 @@
import org.junit.Assert
import org.junit.Test
class Test {
@Test fun testSolution() {
//TODO: implement your test here
Assert.assertTrue("Tests not implemented for the task", false)
}
}

View File

@ -0,0 +1 @@
// type your solution here

View File

@ -0,0 +1,6 @@
type: edu
files:
- name: src/Task.kt
visible: true
- name: test/Tests.kt
visible: false

View File

@ -0,0 +1,7 @@
This is the markdown document.
Write your task text here
<div class="hint">
Hints can be added anywhere in task text: type "hint" and press Tab.
</div>

View File

@ -0,0 +1,9 @@
import org.junit.Assert
import org.junit.Test
class Test {
@Test fun testSolution() {
//TODO: implement your test here
Assert.assertTrue("Tests not implemented for the task", false)
}
}

View File

@ -0,0 +1,35 @@
type: edu
files:
- name: src/GameElements.kt
visible: true
placeholders:
- offset: 380
length: 38
placeholder_text: |-
GameElement {
override val symbol = '#'
override val sharesCell = false
override fun play(maze: Maze) {
// Default implementation: do nothing
}
}
- offset: 433
length: 37
placeholder_text: |-
GameElement {
override val symbol = '.'
override val sharesCell = true
override fun play(maze: Maze) {
// Default implementation: do nothing
}
}
- name: test/Tests.kt
visible: false
feedback_link: |
https://docs.google.com/forms/d/e/1FAIpQLSdkaliSwYkjiV21bZl0yP-In2g5p17sAQCfaGjyHx_QYMWTiQ/viewform?usp=pp_url&entry.189755027=Object-Oriented+Programming+%2F+Base+Class+Initialization+%2F+Exercise1

View File

@ -0,0 +1,14 @@
## Base Class Initialization (#1)
Change the implementations of `Wall` and `Food` classes, so that they extended
the `StaticElement` class instead of implementing `GameElement` interface
directly. Pass the corresponding values for `symbol` and `sharesCell`
properties as function arguments. Note that you no longer need to provide
implementation of `play()` function: the trivial implementation is
inherited from the base class.
The `sharesCell` property specifies whether a mobile element like `Robot` or
`Monster` can step at the same cell. For instance, a robot can be on the same
cell with food or bomb (in this case food is eaten or bomb is exploded), but it
can't share the cell with the wall. The wall occupies the whole cell and
doesn't allow any movement to this cell.

View File

@ -0,0 +1,26 @@
package baseClassInitializationExercise1
import org.junit.Assert
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runners.MethodSorters
import util.TIMEOUT
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class TestBaseClassInitializationExercise1 {
@Test(timeout = TIMEOUT)
fun test1Sample() {
val wall = Wall()
Assert.assertEquals("Wrong value for wall.symbol", '#', wall.symbol)
Assert.assertEquals("Wrong value for wall.sharesCell", false, wall.sharesCell)
val food = Food()
Assert.assertEquals("Wrong value for food.symbol", '.', food.symbol)
Assert.assertEquals("Wrong value for food.sharesCell", true, food.sharesCell)
val elements: List<Any> = listOf(wall, food)
Assert.assertTrue("Wall and Food should extend StaticElement", elements.all {
(it is StaticElement)
})
}
}

View File

@ -1,3 +1,6 @@
content:
- Examples
- Exercise 1
- Exercise 2
- Exercise 3
- Exercise 4

View File

@ -0,0 +1 @@
// type your solution here

View File

@ -1,17 +1,6 @@
type: edu
files:
- name: src/GameElements.kt
- name: src/Task.kt
visible: true
- name: test/Tests.kt
visible: false
- name: src/Maze.kt
visible: true
placeholders:
- offset: 658
length: 38
placeholder_text: 0 // TODO
- offset: 789
length: 244
placeholder_text: // TODO
feedback_link: |
https://docs.google.com/forms/d/e/1FAIpQLSdkaliSwYkjiV21bZl0yP-In2g5p17sAQCfaGjyHx_QYMWTiQ/viewform?usp=pp_url&entry.189755027=Object-Oriented+Programming+%2F+Complex+Constructors+%2F+Exercise1

View File

@ -1,13 +1,7 @@
## Complex Constructors (#1)
This is the markdown document.
Modify the primary constructor of the `MazeImpl` class to
initialize a maze contents using only the maze representation in a string.
Calculate `width` and `height` properties based on the maze representation.
Use the auxiliary function `createGameElement()` (defined in `GameElements.kt`)
to create an element by using a given character.
Write your task text here
For a start, you can reuse the implementation given in the atom text.
Note, however, that only one element is stored in a cell there, and in a real
game several elements can be stored in one cell. Also, the maze representation
with empty cells at the end of lines isn't supported in the implementation
in the book. Fix this problem.
<div class="hint">
Hints can be added anywhere in task text: type "hint" and press Tab.
</div>

View File

@ -1,61 +1,9 @@
package complexConstructorsExercise1
import org.junit.Assert
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runners.MethodSorters
import util.TIMEOUT
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class TestComplexConstructorsExercise1 {
@Test(timeout = TIMEOUT)
fun test1Sample() {
val mazeRepresentation = """
###
#
#R #
####
""".trimIndent()
val matrix = MazeImpl(mazeRepresentation)
Assert.assertEquals("Wrong result for the sample:", mazeRepresentation,
matrix.toString().lines().joinToString("\n") { it.trimEnd() })
}
private fun checkMaze(width: Int, height: Int, maze: String) {
val matrix = MazeImpl(maze)
Assert.assertEquals("Wrong result for the maze:", maze,
matrix.toString().lines().joinToString("\n") { it.trimEnd() })
}
@Test(timeout = TIMEOUT)
fun test2() = checkMaze(4, 3, """
#
""".trimIndent())
@Test(timeout = TIMEOUT)
fun test3() = checkMaze(4, 3, """
####
#R.
##
""".trimIndent())
@Test(timeout = TIMEOUT)
fun test4() = checkMaze(4, 3, """
. ##
# R
""".trimIndent())
@Test(timeout = TIMEOUT)
fun test5() = checkMaze(5, 5, """
.
R
##
.#
""".trimIndent())
class Test {
@Test fun testSolution() {
//TODO: implement your test here
Assert.assertTrue("Tests not implemented for the task", false)
}
}

View File

@ -0,0 +1 @@
// type your solution here

View File

@ -0,0 +1,6 @@
type: edu
files:
- name: src/Task.kt
visible: true
- name: test/Tests.kt
visible: false

View File

@ -0,0 +1,7 @@
This is the markdown document.
Write your task text here
<div class="hint">
Hints can be added anywhere in task text: type "hint" and press Tab.
</div>

View File

@ -0,0 +1,9 @@
import org.junit.Assert
import org.junit.Test
class Test {
@Test fun testSolution() {
//TODO: implement your test here
Assert.assertTrue("Tests not implemented for the task", false)
}
}

View File

@ -0,0 +1 @@
// type your solution here

View File

@ -0,0 +1,6 @@
type: edu
files:
- name: src/Task.kt
visible: true
- name: test/Tests.kt
visible: false

View File

@ -0,0 +1,7 @@
This is the markdown document.
Write your task text here
<div class="hint">
Hints can be added anywhere in task text: type "hint" and press Tab.
</div>

View File

@ -0,0 +1,9 @@
import org.junit.Assert
import org.junit.Test
class Test {
@Test fun testSolution() {
//TODO: implement your test here
Assert.assertTrue("Tests not implemented for the task", false)
}
}

View File

@ -0,0 +1,17 @@
type: edu
files:
- name: src/GameElements.kt
visible: true
- name: test/Tests.kt
visible: false
- name: src/Maze.kt
visible: true
placeholders:
- offset: 658
length: 38
placeholder_text: 0 // TODO
- offset: 789
length: 244
placeholder_text: // TODO
feedback_link: |
https://docs.google.com/forms/d/e/1FAIpQLSdkaliSwYkjiV21bZl0yP-In2g5p17sAQCfaGjyHx_QYMWTiQ/viewform?usp=pp_url&entry.189755027=Object-Oriented+Programming+%2F+Complex+Constructors+%2F+Exercise1

View File

@ -0,0 +1,13 @@
## Complex Constructors (#1)
Modify the primary constructor of the `MazeImpl` class to
initialize a maze contents using only the maze representation in a string.
Calculate `width` and `height` properties based on the maze representation.
Use the auxiliary function `createGameElement()` (defined in `GameElements.kt`)
to create an element by using a given character.
For a start, you can reuse the implementation given in the atom text.
Note, however, that only one element is stored in a cell there, and in a real
game several elements can be stored in one cell. Also, the maze representation
with empty cells at the end of lines isn't supported in the implementation
in the book. Fix this problem.

View File

@ -0,0 +1,61 @@
package complexConstructorsExercise1
import org.junit.Assert
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runners.MethodSorters
import util.TIMEOUT
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class TestComplexConstructorsExercise1 {
@Test(timeout = TIMEOUT)
fun test1Sample() {
val mazeRepresentation = """
###
#
#R #
####
""".trimIndent()
val matrix = MazeImpl(mazeRepresentation)
Assert.assertEquals("Wrong result for the sample:", mazeRepresentation,
matrix.toString().lines().joinToString("\n") { it.trimEnd() })
}
private fun checkMaze(width: Int, height: Int, maze: String) {
val matrix = MazeImpl(maze)
Assert.assertEquals("Wrong result for the maze:", maze,
matrix.toString().lines().joinToString("\n") { it.trimEnd() })
}
@Test(timeout = TIMEOUT)
fun test2() = checkMaze(4, 3, """
#
""".trimIndent())
@Test(timeout = TIMEOUT)
fun test3() = checkMaze(4, 3, """
####
#R.
##
""".trimIndent())
@Test(timeout = TIMEOUT)
fun test4() = checkMaze(4, 3, """
. ##
# R
""".trimIndent())
@Test(timeout = TIMEOUT)
fun test5() = checkMaze(5, 5, """
.
R
##
.#
""".trimIndent())
}

View File

@ -1,3 +1,6 @@
content:
- Examples
- Exercise 1
- Exercise 2
- Exercise 3
- Exercise 4

View File

@ -0,0 +1 @@
// type your solution here

View File

@ -1,16 +1,6 @@
type: edu
files:
- name: src/Bomb.kt
visible: true
placeholders:
- offset: 245
length: 222
placeholder_text: TODO()
- name: src/GameElements.kt
visible: true
- name: src/Maze.kt
- name: src/Task.kt
visible: true
- name: test/Tests.kt
visible: false
feedback_link: |
https://docs.google.com/forms/d/e/1FAIpQLSdkaliSwYkjiV21bZl0yP-In2g5p17sAQCfaGjyHx_QYMWTiQ/viewform?usp=pp_url&entry.189755027=Object-Oriented+Programming+%2F+Inheritance+%2F+Exercise1

View File

@ -1,8 +1,7 @@
## Inheritance (#1)
This is the markdown document.
Implement a more powerful version of the bomb: the one with a diameter of
the explosion. All the cells that are close enough to the bomb must be destroyed.
The bomb should explode when any mobile element steps into the same cell.
Write your task text here
Use the provided auxiliary function `isCloseToBomb()` to check whether
an element is close enough to the bomb to be destroyed.
<div class="hint">
Hints can be added anywhere in task text: type "hint" and press Tab.
</div>

View File

@ -1,178 +1,9 @@
package inheritanceExercise1
import org.junit.Assert
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runners.MethodSorters
import util.TIMEOUT
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class TestInheritanceExercise1 {
private fun checkMaze(
bombCell: Cell,
mazeRepresentation: String,
afterDestroy: String,
prefixMessage: String? = null
) {
val maze = MazeImpl(mazeRepresentation)
val robot = Robot()
maze.add(robot, bombCell)
val bomb = maze.allIn(bombCell)
.filterIsInstance<Bomb>().single()
bomb.play(maze)
Assert.assertEquals("${prefixMessage ?: ""} " +
"Wrong result after exploding a bomb for the following maze:\n$mazeRepresentation",
afterDestroy,
maze.toString())
}
@Test(timeout = TIMEOUT)
fun test1Sample() = checkMaze(Cell(5, 4),
"""
###########
#.........#
#.........#
#.........#
#....4....#
#.........#
#.........#
#.........#
###########
""".trimIndent(),
"""
###########
#.........#
#.... ....#
#... ...#
#.. ..#
#... ...#
#.... ....#
#.........#
###########
""".trimIndent()
)
@Test(timeout = TIMEOUT)
fun test2() = checkMaze(Cell(5, 4),
"""
###########
#.........#
#.........#
#.........#
#....1....#
#.........#
#.........#
#.........#
###########
""".trimIndent(),
"""
###########
#.........#
#.........#
#.........#
#.... ....#
#.........#
#.........#
#.........#
###########
""".trimIndent()
)
@Test(timeout = TIMEOUT)
fun test3() = checkMaze(Cell(5, 4),
"""
###########
#.........#
#.........#
#.........#
#....2....#
#.........#
#.........#
#.........#
###########
""".trimIndent(),
"""
###########
#.........#
#.........#
#.... ....#
#... ...#
#.... ....#
#.........#
#.........#
###########
""".trimIndent()
)
@Test(timeout = TIMEOUT)
fun test4() = checkMaze(Cell(5, 4),
"""
###########
#.........#
#.........#
#.........#
#....3....#
#.........#
#.........#
#.........#
###########
""".trimIndent(),
"""
###########
#.........#
#.........#
#... ...#
#... ...#
#... ...#
#.........#
#.........#
###########
""".trimIndent()
)
@Test(timeout = TIMEOUT)
fun test5() = checkMaze(Cell(5, 4),
"""
###########
#.........#
#.........#
#.........#
#....5....#
#.........#
#.........#
#.........#
###########
""".trimIndent(),
"""
###########
#.........#
#... ...#
#.. ..#
#.. ..#
#.. ..#
#... ...#
#.........#
###########
""".trimIndent()
)
@Test(timeout = TIMEOUT)
fun test6() = checkMaze(Cell(2, 2),
"""
#####
#####
# 3##
#####
#####
""".trimIndent(),
"""
#####
# #
# #
# #
#####
""".trimIndent(),
"Walls should also be exploded"
)
class Test {
@Test fun testSolution() {
//TODO: implement your test here
Assert.assertTrue("Tests not implemented for the task", false)
}
}

View File

@ -0,0 +1 @@
// type your solution here

View File

@ -0,0 +1,6 @@
type: edu
files:
- name: src/Task.kt
visible: true
- name: test/Tests.kt
visible: false

View File

@ -0,0 +1,7 @@
This is the markdown document.
Write your task text here
<div class="hint">
Hints can be added anywhere in task text: type "hint" and press Tab.
</div>

View File

@ -0,0 +1,9 @@
import org.junit.Assert
import org.junit.Test
class Test {
@Test fun testSolution() {
//TODO: implement your test here
Assert.assertTrue("Tests not implemented for the task", false)
}
}

View File

@ -0,0 +1 @@
// type your solution here

View File

@ -0,0 +1,6 @@
type: edu
files:
- name: src/Task.kt
visible: true
- name: test/Tests.kt
visible: false

View File

@ -0,0 +1,7 @@
This is the markdown document.
Write your task text here
<div class="hint">
Hints can be added anywhere in task text: type "hint" and press Tab.
</div>

View File

@ -0,0 +1,9 @@
import org.junit.Assert
import org.junit.Test
class Test {
@Test fun testSolution() {
//TODO: implement your test here
Assert.assertTrue("Tests not implemented for the task", false)
}
}

View File

@ -0,0 +1,16 @@
type: edu
files:
- name: src/Bomb.kt
visible: true
placeholders:
- offset: 245
length: 222
placeholder_text: TODO()
- name: src/GameElements.kt
visible: true
- name: src/Maze.kt
visible: true
- name: test/Tests.kt
visible: false
feedback_link: |
https://docs.google.com/forms/d/e/1FAIpQLSdkaliSwYkjiV21bZl0yP-In2g5p17sAQCfaGjyHx_QYMWTiQ/viewform?usp=pp_url&entry.189755027=Object-Oriented+Programming+%2F+Inheritance+%2F+Exercise1

View File

@ -0,0 +1,8 @@
## Inheritance (#1)
Implement a more powerful version of the bomb: the one with a diameter of
the explosion. All the cells that are close enough to the bomb must be destroyed.
The bomb should explode when any mobile element steps into the same cell.
Use the provided auxiliary function `isCloseToBomb()` to check whether
an element is close enough to the bomb to be destroyed.

View File

@ -0,0 +1,178 @@
package inheritanceExercise1
import org.junit.Assert
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runners.MethodSorters
import util.TIMEOUT
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class TestInheritanceExercise1 {
private fun checkMaze(
bombCell: Cell,
mazeRepresentation: String,
afterDestroy: String,
prefixMessage: String? = null
) {
val maze = MazeImpl(mazeRepresentation)
val robot = Robot()
maze.add(robot, bombCell)
val bomb = maze.allIn(bombCell)
.filterIsInstance<Bomb>().single()
bomb.play(maze)
Assert.assertEquals("${prefixMessage ?: ""} " +
"Wrong result after exploding a bomb for the following maze:\n$mazeRepresentation",
afterDestroy,
maze.toString())
}
@Test(timeout = TIMEOUT)
fun test1Sample() = checkMaze(Cell(5, 4),
"""
###########
#.........#
#.........#
#.........#
#....4....#
#.........#
#.........#
#.........#
###########
""".trimIndent(),
"""
###########
#.........#
#.... ....#
#... ...#
#.. ..#
#... ...#
#.... ....#
#.........#
###########
""".trimIndent()
)
@Test(timeout = TIMEOUT)
fun test2() = checkMaze(Cell(5, 4),
"""
###########
#.........#
#.........#
#.........#
#....1....#
#.........#
#.........#
#.........#
###########
""".trimIndent(),
"""
###########
#.........#
#.........#
#.........#
#.... ....#
#.........#
#.........#
#.........#
###########
""".trimIndent()
)
@Test(timeout = TIMEOUT)
fun test3() = checkMaze(Cell(5, 4),
"""
###########
#.........#
#.........#
#.........#
#....2....#
#.........#
#.........#
#.........#
###########
""".trimIndent(),
"""
###########
#.........#
#.........#
#.... ....#
#... ...#
#.... ....#
#.........#
#.........#
###########
""".trimIndent()
)
@Test(timeout = TIMEOUT)
fun test4() = checkMaze(Cell(5, 4),
"""
###########
#.........#
#.........#
#.........#
#....3....#
#.........#
#.........#
#.........#
###########
""".trimIndent(),
"""
###########
#.........#
#.........#
#... ...#
#... ...#
#... ...#
#.........#
#.........#
###########
""".trimIndent()
)
@Test(timeout = TIMEOUT)
fun test5() = checkMaze(Cell(5, 4),
"""
###########
#.........#
#.........#
#.........#
#....5....#
#.........#
#.........#
#.........#
###########
""".trimIndent(),
"""
###########
#.........#
#... ...#
#.. ..#
#.. ..#
#.. ..#
#... ...#
#.........#
###########
""".trimIndent()
)
@Test(timeout = TIMEOUT)
fun test6() = checkMaze(Cell(2, 2),
"""
#####
#####
# 3##
#####
#####
""".trimIndent(),
"""
#####
# #
# #
# #
#####
""".trimIndent(),
"Walls should also be exploded"
)
}

View File

@ -1,3 +1,6 @@
content:
- Examples
- Exercise 1
- Exercise 2
- Exercise 3
- Exercise 4

View File

@ -0,0 +1 @@
// type your solution here

View File

@ -1,17 +1,6 @@
type: edu
files:
- name: src/GameMatrix.kt
visible: true
placeholders:
- offset: 986
length: 55
placeholder_text: TODO()
- offset: 1097
length: 94
placeholder_text: TODO()
- name: src/GameElements.kt
- name: src/Task.kt
visible: true
- name: test/Tests.kt
visible: false
feedback_link: |
https://docs.google.com/forms/d/e/1FAIpQLSdkaliSwYkjiV21bZl0yP-In2g5p17sAQCfaGjyHx_QYMWTiQ/viewform?usp=pp_url&entry.189755027=Object-Oriented+Programming+%2F+Interfaces+%2F+Exercise1

View File

@ -1,12 +1,7 @@
## Interfaces (#1)
This is the markdown document.
The `MazeImpl` class implements the `Maze` interface. It stores game elements
in a "table" of the size `height * width`, which is implemented as a `List` of
`List`s, where the outer `List` is of `height` size and each inner `List` is of
`width` size. Each cell holds a set of `GameElement`s. `MazeImpl` also keeps a
record of the `Cell`s of all the elements by storing a `cellMap` `Map`
which has `GameElement` keys and `Cell` values.
Write your task text here
Your task is to implement the `add(GameElement, Cell)` and
`remove(GameElement, Cell)` functions that add and remove `GameElement`s
at a given `Cell`.
<div class="hint">
Hints can be added anywhere in task text: type "hint" and press Tab.
</div>

View File

@ -1,92 +1,9 @@
package interfacesExercise1
import org.junit.Assert
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runners.MethodSorters
import util.TIMEOUT
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class TestInterfacesExercise1 {
@Test(timeout = TIMEOUT)
fun test1Sample() {
val matrix = MazeImpl(width = 4, height = 5)
matrix.add(Robot(), Cell(x = 1, y = 2))
matrix.add(Food(), Cell(x = 2, y = 3))
for (i in 0..4) {
matrix.add(Wall(), Cell(0, i))
matrix.add(Wall(), Cell(3, i))
class Test {
@Test fun testSolution() {
//TODO: implement your test here
Assert.assertTrue("Tests not implemented for the task", false)
}
for (i in 1..2) {
matrix.add(Wall(), Cell(i, 0))
matrix.add(Wall(), Cell(i, 4))
}
Assert.assertEquals("Wrong result for the sample:",
"""
####
# #
#R #
# .#
####
""".trimIndent(),
matrix.toString())
Assert.assertEquals("Wrong result for the sample. In Cell(1, 2) should be Robot",
'R', matrix.allIn(Cell(1, 2)).singleOrNull()?.symbol)
}
private fun createGameElement(char: Char): GameElement? = when (char) {
'#' -> Wall()
'.' -> Food()
'R' -> Robot()
else -> null
}
private fun checkMaze(maze: String) {
val lines = maze.lines().filter { it.isNotEmpty() }
val height = lines.size
val lengths = lines.map { it.length }
val width = lengths.first()
val matrix = MazeImpl(width, height)
for (y in 0 until height) {
for (x in 0 until width) {
val ch = lines[y][x]
val element = createGameElement(ch)
if (element != null) {
matrix.add(element, Cell(x, y))
}
}
}
Assert.assertEquals("Wrong result for the maze:",
maze,
matrix.toString())
}
@Test(timeout = TIMEOUT)
fun test2() = checkMaze("""
####
####
####
""".trimIndent())
@Test(timeout = TIMEOUT)
fun test3() = checkMaze("""
####
#R.#
####
""".trimIndent())
@Test(timeout = TIMEOUT)
fun test4() = checkMaze("""
. ##
#
# R
""".trimIndent())
@Test(timeout = TIMEOUT)
fun test5() = checkMaze("""
....
....
...R
""".trimIndent())
}

View File

@ -0,0 +1 @@
// type your solution here

View File

@ -0,0 +1,6 @@
type: edu
files:
- name: src/Task.kt
visible: true
- name: test/Tests.kt
visible: false

View File

@ -0,0 +1,7 @@
This is the markdown document.
Write your task text here
<div class="hint">
Hints can be added anywhere in task text: type "hint" and press Tab.
</div>

View File

@ -0,0 +1,9 @@
import org.junit.Assert
import org.junit.Test
class Test {
@Test fun testSolution() {
//TODO: implement your test here
Assert.assertTrue("Tests not implemented for the task", false)
}
}

View File

@ -0,0 +1 @@
// type your solution here

View File

@ -0,0 +1,6 @@
type: edu
files:
- name: src/Task.kt
visible: true
- name: test/Tests.kt
visible: false

View File

@ -0,0 +1,7 @@
This is the markdown document.
Write your task text here
<div class="hint">
Hints can be added anywhere in task text: type "hint" and press Tab.
</div>

View File

@ -0,0 +1,9 @@
import org.junit.Assert
import org.junit.Test
class Test {
@Test fun testSolution() {
//TODO: implement your test here
Assert.assertTrue("Tests not implemented for the task", false)
}
}

View File

@ -0,0 +1,17 @@
type: edu
files:
- name: src/GameMatrix.kt
visible: true
placeholders:
- offset: 986
length: 55
placeholder_text: TODO()
- offset: 1097
length: 94
placeholder_text: TODO()
- name: src/GameElements.kt
visible: true
- name: test/Tests.kt
visible: false
feedback_link: |
https://docs.google.com/forms/d/e/1FAIpQLSdkaliSwYkjiV21bZl0yP-In2g5p17sAQCfaGjyHx_QYMWTiQ/viewform?usp=pp_url&entry.189755027=Object-Oriented+Programming+%2F+Interfaces+%2F+Exercise1

View File

@ -0,0 +1,12 @@
## Interfaces (#1)
The `MazeImpl` class implements the `Maze` interface. It stores game elements
in a "table" of the size `height * width`, which is implemented as a `List` of
`List`s, where the outer `List` is of `height` size and each inner `List` is of
`width` size. Each cell holds a set of `GameElement`s. `MazeImpl` also keeps a
record of the `Cell`s of all the elements by storing a `cellMap` `Map`
which has `GameElement` keys and `Cell` values.
Your task is to implement the `add(GameElement, Cell)` and
`remove(GameElement, Cell)` functions that add and remove `GameElement`s
at a given `Cell`.

View File

@ -0,0 +1,92 @@
package interfacesExercise1
import org.junit.Assert
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runners.MethodSorters
import util.TIMEOUT
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class TestInterfacesExercise1 {
@Test(timeout = TIMEOUT)
fun test1Sample() {
val matrix = MazeImpl(width = 4, height = 5)
matrix.add(Robot(), Cell(x = 1, y = 2))
matrix.add(Food(), Cell(x = 2, y = 3))
for (i in 0..4) {
matrix.add(Wall(), Cell(0, i))
matrix.add(Wall(), Cell(3, i))
}
for (i in 1..2) {
matrix.add(Wall(), Cell(i, 0))
matrix.add(Wall(), Cell(i, 4))
}
Assert.assertEquals("Wrong result for the sample:",
"""
####
# #
#R #
# .#
####
""".trimIndent(),
matrix.toString())
Assert.assertEquals("Wrong result for the sample. In Cell(1, 2) should be Robot",
'R', matrix.allIn(Cell(1, 2)).singleOrNull()?.symbol)
}
private fun createGameElement(char: Char): GameElement? = when (char) {
'#' -> Wall()
'.' -> Food()
'R' -> Robot()
else -> null
}
private fun checkMaze(maze: String) {
val lines = maze.lines().filter { it.isNotEmpty() }
val height = lines.size
val lengths = lines.map { it.length }
val width = lengths.first()
val matrix = MazeImpl(width, height)
for (y in 0 until height) {
for (x in 0 until width) {
val ch = lines[y][x]
val element = createGameElement(ch)
if (element != null) {
matrix.add(element, Cell(x, y))
}
}
}
Assert.assertEquals("Wrong result for the maze:",
maze,
matrix.toString())
}
@Test(timeout = TIMEOUT)
fun test2() = checkMaze("""
####
####
####
""".trimIndent())
@Test(timeout = TIMEOUT)
fun test3() = checkMaze("""
####
#R.#
####
""".trimIndent())
@Test(timeout = TIMEOUT)
fun test4() = checkMaze("""
. ##
#
# R
""".trimIndent())
@Test(timeout = TIMEOUT)
fun test5() = checkMaze("""
....
....
...R
""".trimIndent())
}

View File

@ -1,3 +1,6 @@
content:
- Examples
- Exercise 1
- Exercise 2
- Exercise 3
- Exercise 4

View File

@ -0,0 +1 @@
// type your solution here

View File

@ -1,29 +1,6 @@
type: edu
files:
- name: src/GardenItem.kt
- name: src/Task.kt
visible: true
placeholders:
- offset: 162
length: 142
placeholder_text: |-
class GardenItem(
val name: String
) {
var material: Material = Plastic
constructor(
name: String, material: Material
) : this(name) {
this.material = material
}
constructor(
material: Material
) : this("Strange Thing", material)
override fun toString() = "$material $name"
}
- name: test/Tests.kt
visible: false
feedback_link: |
https://docs.google.com/forms/d/e/1FAIpQLSdkaliSwYkjiV21bZl0yP-In2g5p17sAQCfaGjyHx_QYMWTiQ/viewform?usp=pp_url&entry.189755027=Object-Oriented+Programming+%2F+Secondary+Constructors+%2F+Exercise1

View File

@ -1,4 +1,7 @@
## Secondary Constructors (#1)
This is the markdown document.
Replace all the constructors in the `GardenItem` class with one primary
constructor using default arguments.
Write your task text here
<div class="hint">
Hints can be added anywhere in task text: type "hint" and press Tab.
</div>

View File

@ -1,14 +1,9 @@
package secondaryConstructorsExercise1
import org.junit.Assert
import org.junit.Test
import util.TIMEOUT
class TestSecondaryConstructorsExercise1 {
@Test(timeout = TIMEOUT)
fun test() {
Assert.assertEquals("GardenItem class should define only one constructor",
1,
GardenItem::class.constructors.size)
}
class Test {
@Test fun testSolution() {
//TODO: implement your test here
Assert.assertTrue("Tests not implemented for the task", false)
}
}

View File

@ -0,0 +1 @@
// type your solution here

View File

@ -0,0 +1,6 @@
type: edu
files:
- name: src/Task.kt
visible: true
- name: test/Tests.kt
visible: false

View File

@ -0,0 +1,7 @@
This is the markdown document.
Write your task text here
<div class="hint">
Hints can be added anywhere in task text: type "hint" and press Tab.
</div>

View File

@ -0,0 +1,9 @@
import org.junit.Assert
import org.junit.Test
class Test {
@Test fun testSolution() {
//TODO: implement your test here
Assert.assertTrue("Tests not implemented for the task", false)
}
}

View File

@ -0,0 +1,29 @@
type: edu
files:
- name: src/GardenItem.kt
visible: true
placeholders:
- offset: 162
length: 142
placeholder_text: |-
class GardenItem(
val name: String
) {
var material: Material = Plastic
constructor(
name: String, material: Material
) : this(name) {
this.material = material
}
constructor(
material: Material
) : this("Strange Thing", material)
override fun toString() = "$material $name"
}
- name: test/Tests.kt
visible: false
feedback_link: |
https://docs.google.com/forms/d/e/1FAIpQLSdkaliSwYkjiV21bZl0yP-In2g5p17sAQCfaGjyHx_QYMWTiQ/viewform?usp=pp_url&entry.189755027=Object-Oriented+Programming+%2F+Secondary+Constructors+%2F+Exercise1

View File

@ -0,0 +1,4 @@
## Secondary Constructors (#1)
Replace all the constructors in the `GardenItem` class with one primary
constructor using default arguments.

View File

@ -0,0 +1,14 @@
package secondaryConstructorsExercise1
import org.junit.Assert
import org.junit.Test
import util.TIMEOUT
class TestSecondaryConstructorsExercise1 {
@Test(timeout = TIMEOUT)
fun test() {
Assert.assertEquals("GardenItem class should define only one constructor",
1,
GardenItem::class.constructors.size)
}
}

View File

@ -1,3 +1,5 @@
content:
- Examples
- Exercise 1
- Exercise 2
- Exercise 3

View File

@ -1,4 +1,5 @@
content:
- Object-Oriented Design
- Interfaces
- Complex Constructors
- Secondary Constructors