官术网_书友最值得收藏!

Implementation

Now that we have a clear definition of when an exception should be thrown, the implementation should be straightforward:

package com.packtpublishing.tddjava.ch03tictactoe;

public class TicTacToe {
  public void play(int x, int y) {
    if (x < 1 || x > 3) {
      throw new RuntimeException("X is outside board");
    }
  }
}

As you can see, this code does not contain anything else, but the bare minimum required for the test to pass.

Some TDD practitioners tend to take minimum as a literal meaning. They would have the play method with only the throw new RuntimeException(); line. I tend to translate minimum to as little as possible within reason.

We're not adding numbers, nor are we returning anything. It's all about making small changes very fast. (Remember the game of ping pong?) For now, we're doing red-green steps. There's not much we can do to improve this code so we're skipping the refactoring.

Let's move on to the next test.

主站蜘蛛池模板: 缙云县| 即墨市| 三门峡市| 根河市| 泾川县| 离岛区| 博白县| 崇义县| 青海省| 高密市| 同仁县| 开化县| 印江| 舒城县| 玉屏| 吉水县| 和田市| 安泽县| 色达县| 高碑店市| 高要市| 陵水| 云霄县| 洱源县| 山阳县| 永济市| 潜江市| 巫山县| 仲巴县| 灵川县| 米泉市| 汉中市| 特克斯县| 江达县| 阿拉尔市| 喀什市| 吴忠市| 周至县| 竹溪县| 章丘市| 西和县|