Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
674 changes: 674 additions & 0 deletions go/study/second_tour_of_go-ch01_first_test_01/LICENSE

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions go/study/second_tour_of_go-ch01_first_test_01/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Second Tour of Go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 第1章 初めてのテスト

## セットアップ

1. https://go.dev/doc/install の指示に従って Go 1.19 をインストール
[asdf](https://asdf-vm.com/)の[golangプラグイン](https://github.com/kennyp/asdf-golang) あるいは [goenv](https://github.com/syndbg/goenv) などを使うことを推奨
1. `go` コマンドのバージョンを確認
1. `ターミナル` (Mac/Linux) or `コマンドプロンプト` (Windows) を新たに開く
1. `go version` を実行
1. インストールしたGoのバージョンが表示されることを確認
1. https://github.com/akm/second_tour_of_go/releases/tag/ch01_first_test_01 からソースコードをダウンロード
1. ダウンロードしたコードを解凍
1. ターミナル上でディレクトリ `ch01_first_test` に移動
`cd path/to/second_tour_of_go-ch01_first_test_01/ch01_first_test`
(`path/to` は解凍して作られたディレクトリに置き換えて実行してください )
1. `go test` を実行し、以下のような出力が表示されることを確認
```
PASS
ok github.com/akm/second_tour_of_go/ch01_first_test 0.341s
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

func Add(x, y int) int {
return x + y
}

func Subtract(x, y int) int {
return x - y
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/tecyokomichi/WebAppLearning/go/study/ch01_first_test

go 1.19
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"testing"
)

func TestAdd(t *testing.T) {
s := Add(1, 2)
if s != 3 {
t.FailNow()
}
}

func TestSubtract(t *testing.T) {
s := Subtract(1, 2)
if s != -1 {
t.FailNow()
}
s = Subtract(2, 1)
if s != 1 {
t.FailNow()
}
}