forked from SurvivalCodingCampus/winter_kotlin_study
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWizardTest.kt
72 lines (59 loc) · 2.17 KB
/
WizardTest.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package day05
import org.hyunjung.day05.Wand
import org.hyunjung.day05.Wizard
import org.junit.Assert.*
import org.junit.Test
class WizardTest {
private val validWand = Wand(name = "불의 지팡이", power = 10.0)
@Test
fun `정상적인 Wizard 생성`() {
val wizard = Wizard(name = "간달프", hp = 100, wand = validWand)
assertEquals("간달프", wizard.name)
assertEquals(100, wizard.hp)
assertEquals(validWand, wizard.wand)
}
@Test(expected = IllegalArgumentException::class)
fun `이름이 3문자 미만이면 예외 발생`() {
Wizard(name = "간달", hp = 100, wand = validWand)
}
@Test(expected = IllegalArgumentException::class)
fun `HP가 음수일 때 자동으로 0으로 설정`() {
val wizard = Wizard(name = "간달프", hp = -10, wand = validWand)
assertEquals(0, wizard.hp)
}
@Test(expected = IllegalArgumentException::class)
fun `wand가 null이면 예외 발생`() {
Wizard(name = "간달프", hp = 100, wand = null)
}
@Test
fun `이름 변경 테스트`() {
val wizard = Wizard(name = "간달프", hp = 100, wand = validWand)
wizard.name = "해리포터"
assertEquals("해리포터", wizard.name)
}
@Test
fun `HP 변경 테스트`() {
val wizard = Wizard(name = "간달프", hp = 100, wand = validWand)
wizard.hp = 50
assertEquals(50, wizard.hp)
wizard.hp = -20
assertEquals(0, wizard.hp)
}
@Test
fun `wand 변경 테스트`() {
val wizard = Wizard(name = "간달프", hp = 100, wand = validWand)
val newWand = Wand(name = "새로운 지팡이", power = 20.0)
wizard.wand = newWand
assertEquals(newWand, wizard.wand)
}
@Test(expected = IllegalArgumentException::class)
fun `wand를 null로 설정 시 예외 발생`() {
val wizard = Wizard(name = "간달프", hp = 100, wand = validWand)
wizard.wand = null
}
@Test(expected = IllegalArgumentException::class)
fun `MP가 0미만인 경우`() {
val wizard = Wizard(name = "간달프", hp = 100, wand = validWand)
wizard.mp = -1
}
}