1
exercism fetch kotlin robot-name

src/test/kotlin/RobotTest.kt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import org.junit.Test
import org.junit.Ignore
import kotlin.test.assertNotEquals
import kotlin.test.assertTrue

class RobotTest {

    companion object {
        val EXPECTED_ROBOT_NAME_PATTERN = Regex("[A-Z]{2}\\d{3}")
        private fun isValidName(name: String) = EXPECTED_ROBOT_NAME_PATTERN.matches(name)
    }

    val robot = Robot()


    @Test
    fun hasName() {
        assertTrue(isValidName(robot.name), "Robot name ${robot.name} didn't match expected pattern.")
    }

    @Ignore
    @Test
    fun differentRobotsHaveDifferentNames() {
        assertNotEquals(robot.name, Robot().name)
    }

    @Ignore
    @Test
    fun resetName() {
        val name = robot.name
        robot.reset()

        val name2 = robot.name
        assertNotEquals(name, name2)
        assertTrue(isValidName(name2), "Robot name $name2 didn't match expected pattern.")
    }

}