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

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.

主站蜘蛛池模板: 惠水县| 甘谷县| 七台河市| 车险| 右玉县| 石城县| 凤翔县| 松滋市| 神农架林区| 综艺| 南昌县| 垫江县| 扶绥县| 修武县| 朔州市| 南和县| 渭源县| 台江县| 八宿县| 古蔺县| 平潭县| 宣武区| 冕宁县| 西和县| 宁乡县| 富蕴县| 兰考县| 丰镇市| 峨眉山市| 吕梁市| 镇康县| 黄山市| 盐津县| 乐清市| 萨嘎县| 太仓市| 宜宾市| 金寨县| 营口市| 洪雅县| 和田市|