# 프라이버시

{% tabs %}
{% tab title="테스트 목록" %}

* $5 + 10CHF = $10(환율이 2:1 일 경우) &#x20;
* ~~*$5 \** 2 = 10$~~&#x20;
* ***amount를 private으로 만들기*****&#x20;**&#x20;
* ~~Dollar 부작용(side effect)?~~&#x20;
* &#x20;Money 반올림?
* ~~equals()~~
* hashCode()
* Equal null
* Equal object
  {% endtab %}
  {% endtabs %}

이제 동치성 문제를 정의했으므로 이를 이용하여 테스트가 좀 더 많은 이야기를 해줄 수 있도록 만들 수 있을 것이다.&#x20;

```java
@Test
void testMultiplication() {
    Dollar five = new Dollar(5);
    Dollar ten = five.times(2);
    assertEquals(10, ten.amount);
    Dollar fifteen = five.times(3);
    assertEquals(15, fifteen.amount);

}
```

�개념적으로 Dollar.times() 연산은 현재 Dollar 객체 값에 multiplier 인자를 곱한 새로운 Dollar 객체를 반환해야 한다. 하지만 위 테스트에서는 Dollar 객체 간 동치성이 아닌, 상태 값을 비교하고 있다.

따라서, 테스트 대상을 다시 변경하여 시나리오를 아래와 같이 재작성할 수 있을 것이다.

```java
@Test
void testMultiplication() {
    Dollar five = new Dollar(5);
    Dollar ten = five.times(2);
    assertEquals(new Dollar(10), ten);
    Dollar fifteen = five.times(3);
    assertEquals(new Dollar(15), fifteen);
    
}
```

&#x20;이제 임시 변수는 필요가 없어 보이므로 제거하여 인라인 시켜보자.

```java
@Test
void testMultiplication() {
    Dollar five = new Dollar(5);
    assertEquals(new Dollar(10), five.times(2));
    assertEquals(new Dollar(15), five.times(3));

}
```

�아직까지 초록막대가 살아있는 것을 확인할 수 있다.

![](https://1360705058-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LZ0r85EEFTHmLyxK8ag%2F-LseiKKftj7mip-YDeqT%2F-Lseluy1Idt4HBxFN8IQ%2Fimage.png?alt=media\&token=dfd048a9-b062-48be-aa58-021e116c3cda)

결과적으로, 이 테스트는 **일련의 오퍼레이션**이 아니라 **참인 명제에 대한 단언들**이므로 **의도**를 보다 **명확하게 이야기**해준다.

또한, Dollar amount 인스턴스 변수를 사용하는 코드는 Dollar 자신밖에 없으므로, private 변수로 변경할 수 있게 된다.

```java
public class Dollar {
    private int amount;

    public Dollar(int amount) {
        this.amount = amount;

    }

    public Dollar times(int multiplier) {
        return new Dollar(amount * multiplier);

    }

    public boolean equals(Object object) {
        Dollar dollar = (Dollar) object;
        return amount == dollar.amount;

    }

}
```

{% tabs %}
{% tab title="테스트 목록" %}

* $5 + 10CHF = $10(환율이 2:1 일 경우) &#x20;
* ~~*$5 \** 2 = 10$~~&#x20;
* \~\~*amount를 private으로 만들기* \~\~&#x20;
* ~~Dollar 부작용(side effect)?~~&#x20;
* &#x20;Money 반올림?
* ~~equals()~~
* hashCode()
* Equal null
* Equal object
  {% endtab %}
  {% endtabs %}

여기서 위험한 상황을 만들었다는 점에 주목해야 된다.&#x20;

만약 동치성 테스트가 실패하게 된다면, 자연스럽게 곱하기 테스트 역시 실패하게 될 것이다.

켄트벡은 이 점에 대해 "TDD를 하면서 적극적으로 관리해야 할 요소" 라고 말하며, **실패한 추론을 통해 교훈을 얻고 다시 앞으로 나아가라**는 용기를 심어주고 있다..


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://koseungbin.gitbook.io/wiki/books/undefined-3/1/undefined-2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
