# テストファイルの作成

現在の三目並べプロジェクトのフォルダ構成を修正しテストファイルを作成します。

## 修正1 tic\_tac\_toe.rbの作成

main.rb内にある基本ロジックを全て、tic\_tac\_toe.rbに移します。

tic\_tac\_toeフォルダ内にtic\_tac\_toe.rbを作成してください。

```
ruby-practice/
　├ docker-compose.yml
　├ code/
　│　└ Dockerfile
　│　└ main.rb
　│　└ tic_tac_toe/
　│　   └ tic_tac_toe.rb
```

この時に、ゲームのメイン部分に関しては以下のようなメソッドを実装してtic\_tac\_toe.rbに移植してください。

```ruby
# 説明: ゲームのmain部分
#       このメソッドをコールするとゲームが始まる
# 引数: なし
# 戻り値: なし
def start
  player = 1
  board = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

  while continue?(player, board)
    row, col = gets_position()

    place_piece(board, player, row, col)

    put_board(board)

    player = get_opponent_player(player)
  end

  put_result(board)
end
```

## 修正2 main.rbの修正

新しく定義したstartメソッドを`main.rb`でコールするように修正を加えます。

```ruby
require "./tic_tac_toe/tic_tac_toe"

start()
```

## 修正3 テストファイルの作成

テストを記載していくtic\_tac\_toe\_test.rbファイルを作成します。

```
ruby-practice/
　├ docker-compose.yml
　├ code/
　│　└ Dockerfile
　│　└ main.rb
　│　└ tic_tac_toe/
　│　   └ tic_tac_toe.rb
　│　└ test/
　│　   └ tic_tac_toe_test.rb
```

以上でフォルダの修正は完了となります。

## テストを動作させる

作成した`tic_tac_toe_test.rb`に以下の内容を追加してください。

```ruby
require "minitest/autorun"
require "../tic_tac_toe/tic_tac_toe"

class TicTacToeTest < Minitest::Test
end
```

一度テストを動かしてみましょう（何も書かれておりませんが）

```
ruby tic_tac_toe_test.rb 
```

下のようなログが出てたらテストが実行できています。

```
Run options: --seed 6237

# Running:



Finished in 0.001210s, 0.0000 runs/s, 0.0000 assertions/s.

0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
```

テストを実装する準備は整いました！

次のセクションでメソッドをテストしていきましょう！


---

# 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://kashiwara.gitbook.io/rubydesurufurusukuratchibe/tesutokdo/tesutofairuno.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.
