Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Step1] 모듈 분리 #5

Merged
merged 2 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Domain/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
17 changes: 17 additions & 0 deletions Domain/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
id 'java-library'
id 'kotlin'
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.7.1' // junit4 지원
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.1'
Comment on lines +13 to +14
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

junit5를 사용하려면 아래 코드도 설정해주셔야 합니다.

test {
    useJUnitPlatform()
}

testImplementation 'junit:junit:4.13.2'
testImplementation 'com.google.truth:truth:1.1.2'
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package edu.nextstep.camp.calculator.domain
package edu.nextstep.camp.domain

class Calculator {
fun calculate(rawExpression: String): Int? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package edu.nextstep.camp.calculator.domain
package edu.nextstep.camp.domain

data class Expression(
private val values: List<Any> = emptyList()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package edu.nextstep.camp.calculator.domain
package edu.nextstep.camp.domain

enum class Operator(
val sign: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

class CalculatorTest {
private lateinit var calculator: Calculator
private lateinit var calculator: edu.nextstep.camp.domain.Calculator

@BeforeEach
fun setUp() {
calculator = Calculator()
calculator = edu.nextstep.camp.domain.Calculator()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ExpressionTest {
@Test
fun `빈 수식일 때, 피연산자를 추가할 수 있어야한다`() {
// given
val expression = Expression.EMPTY
val expression = edu.nextstep.camp.domain.Expression.EMPTY

// when
val actual = expression + 1
Expand All @@ -19,7 +19,7 @@ class ExpressionTest {
@Test
fun `'8' 수식이 있을 때, 9를 입력하면 89로 바뀌어야 한다`() {
// given
val expression = Expression(listOf(8))
val expression = edu.nextstep.camp.domain.Expression(listOf(8))

// when
val actual = expression + 9
Expand All @@ -31,10 +31,10 @@ class ExpressionTest {
@Test
fun `빈 수식일 때, + 연산자를 추가할 수 없어야 한다`() {
// given
val expression = Expression.EMPTY
val expression = edu.nextstep.camp.domain.Expression.EMPTY

// when
val actual = expression + Operator.Plus
val actual = expression + edu.nextstep.camp.domain.Operator.Plus

// then
assertThat(actual.toString()).isEqualTo("")
Expand All @@ -43,10 +43,10 @@ class ExpressionTest {
@Test
fun `'1' 수식이 있을 때, + 연산자를 추가할 수 있어야 한다`() {
// given
val expression = Expression(listOf(1))
val expression = edu.nextstep.camp.domain.Expression(listOf(1))

// when
val actual = expression + Operator.Plus
val actual = expression + edu.nextstep.camp.domain.Operator.Plus

// then
assertThat(actual.toString()).isEqualTo("1 +")
Expand All @@ -55,10 +55,11 @@ class ExpressionTest {
@Test
fun `'8 +' 수식이 있을 때, + 연산자를 - 연산자로 변경할 수 있어야 한다`() {
// given
val expression = Expression(listOf(8, Operator.Plus))
val expression =
edu.nextstep.camp.domain.Expression(listOf(8, edu.nextstep.camp.domain.Operator.Plus))

// when
val actual = expression + Operator.Minus
val actual = expression + edu.nextstep.camp.domain.Operator.Minus

// then
assertThat(actual.toString()).isEqualTo("8 -")
Expand All @@ -67,7 +68,13 @@ class ExpressionTest {
@Test
fun `'32 + 1' 수식이 있을 때, 마지막 1을 제거할 수 있어야 한다`() {
// given
val expression = Expression(listOf(32, Operator.Plus, 1))
val expression = edu.nextstep.camp.domain.Expression(
listOf(
32,
edu.nextstep.camp.domain.Operator.Plus,
1
)
)

// when
val actual = expression.removeLast()
Expand All @@ -79,7 +86,8 @@ class ExpressionTest {
@Test
fun `'32 +' 수식이 있을 때, 마지막 +를 제거할 수 있어야 한다`() {
// given
val expression = Expression(listOf(32, Operator.Plus))
val expression =
edu.nextstep.camp.domain.Expression(listOf(32, edu.nextstep.camp.domain.Operator.Plus))

// when
val actual = expression.removeLast()
Expand All @@ -91,7 +99,7 @@ class ExpressionTest {
@Test
fun `'32' 수식이 있을 때, 마지막 2를 제거할 수 있어야 한다`() {
// given
val expression = Expression(listOf(32))
val expression = edu.nextstep.camp.domain.Expression(listOf(32))

// when
val actual = expression.removeLast()
Expand All @@ -103,7 +111,7 @@ class ExpressionTest {
@Test
fun `'3' 수식이 있을 때, 마지막 3을 제거할 수 있어야 한다`() {
// given
val expression = Expression(listOf(3))
val expression = edu.nextstep.camp.domain.Expression(listOf(3))

// when
val actual = expression.removeLast()
Expand All @@ -115,7 +123,7 @@ class ExpressionTest {
@Test
fun `빈 수식일 때, 마지막을 제거해도 빈 수식이어야 한다`() {
// given
val expression = Expression.EMPTY
val expression = edu.nextstep.camp.domain.Expression.EMPTY

// when
val actual = expression.removeLast()
Expand Down
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ dependencies {
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'

implementation project(':Domain')

testImplementation 'org.junit.jupiter:junit-jupiter:5.7.1'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.7.1' // junit4 지원
testImplementation 'junit:junit:4.13.2'
Expand Down
13 changes: 6 additions & 7 deletions app/src/main/java/edu/nextstep/camp/calculator/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import edu.nextstep.camp.calculator.databinding.ActivityMainBinding
import edu.nextstep.camp.calculator.domain.Calculator
import edu.nextstep.camp.calculator.domain.Expression
import edu.nextstep.camp.calculator.domain.Operator
import edu.nextstep.camp.domain.Calculator
import edu.nextstep.camp.domain.Expression

class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
Expand Down Expand Up @@ -59,19 +58,19 @@ class MainActivity : AppCompatActivity() {
binding.textView.text = expression.toString()
}
binding.buttonPlus.setOnClickListener {
expression += Operator.Plus
expression += edu.nextstep.camp.domain.Operator.Plus
binding.textView.text = expression.toString()
}
binding.buttonMinus.setOnClickListener {
expression += Operator.Minus
expression += edu.nextstep.camp.domain.Operator.Minus
binding.textView.text = expression.toString()
}
binding.buttonMultiply.setOnClickListener {
expression += Operator.Multiply
expression += edu.nextstep.camp.domain.Operator.Multiply
binding.textView.text = expression.toString()
}
binding.buttonDivide.setOnClickListener {
expression += Operator.Divide
expression += edu.nextstep.camp.domain.Operator.Divide
binding.textView.text = expression.toString()
}
binding.buttonDelete.setOnClickListener {
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include ':app'
rootProject.name = "AndroidCalculator"
include ':Domain'