![[Learn Go with Tests] 의존성 주입](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FYlGyc%2FbtsIKTDtq2o%2FckIKP2OTvkeuGFgYel9VKK%2Fimg.png)
해당 문서를 통해 우리는 아래의 항목이 가능한가에 대해 배울것이다프레임 워크가 필요하지 않다.디자인을 지나치게 복잡하게 하지 않는다테스트를 용이하게 한다범용적인 함수를 뛰어나게 작성할 것이다.func Greet(name string) { fmt.Printf("Hello, %s", name)}간단한 printf 함수가 있다. fmt.Printf를 호출하면 stdout으로 출력된다. 우리는 이제부터 print 하는 것을 의존성 주입(인자를 넘기는 것을 고급지게 표현했다- tdd 문서 표현)을 해보도록 한다우리의 함수는 어디에서 또는 어떻게 print가 발생하는 지를 신경 쓸 필요가 없다. 그래서 우리는 구체적인 type보다는 interface type을 허용해야 한다.⇒ 즉, 우리는 제어하는 어떤 것으..
![[Learn Go with Tests] 맵](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbFxsIp%2FbtsIKTjb3GK%2FYFERZeGey80JjuxnODXC3K%2Fimg.png)
이전의 배열과 슬라이스에서는 값을 순서대로 저장하는 방법에 대해 학습했다. 이번에는 항목을 key에 따라 저장하고, 저장한 key를 찾는 방법에 대해 알아보도록 하자.⇒ Key-Value가 있던 python의 Dictionary와 유사하다!테스트 코드 작성하기func TestSearch(t *testing.T) { dictionary := map[string]string{"test": "this is just a test!"} got := Search(dictionary, "test") want := "this is just a test!" if got != want { t.Errorf("got %q want %q given, %q", got, want, "test") }}맵을 선언할 때에는 map이라..
![[Learn Go with Tests] 포인터 & 에러](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FFqnYc%2FbtsILf0t4KE%2FTMc2Jh8e1VShqEMocxowkK%2Fimg.png)
해당 포스팅은 Learn Go with Tests Gitbook을 따라 실습한 내용을 정리한 문서입니다. 테스트 코드 작성하기func TestWallet(t *testing.T) { wallet := Wallet{} wallet.Deposit(10) got := wallet.Balance() want := 10 if got != want { t.Errorf("got %d want %d", got, want) }} ⇒ 메서드를 통해 코드를 제어할 수 있도록 한다.type Wallet struct { balance int}func (w Wallet) Deposit(amount int) { w.balance += amount}func (w Wallet) Balance() int { return w.balan..
![[Learn Go with Tests] 구조체, 메서드 & 인터페이스](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FzE6Gb%2FbtsIDOI0HaR%2FoCjRS7T2iAoOk36Qtqrpi1%2Fimg.png)
해당 포스팅은 Learn Go with Tests Gitbook을 따라 실습한 내용을 정리한 문서입니다. 사각형의 둘레를 계산하는 코드테스트 코드func TestPerimeter(t *testing.T){ got := Perimeter(10.0, 10.0) want := 40.0 if got != want{ t.Errorf("got %.2f want %.2f", got, want) }}⇒ 가로와 세로를 입력받고 둘레를 계산하는 프로그램의 테스트 코드이다.새로운 문자열 형식 → %.2ff는 float64이고, .2는 소수점 두자리 출력을 의미한다.실행 코드func Perimeter(width float64, height float64) float64 { return 2 * (width + height)}..