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

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.

主站蜘蛛池模板: 大悟县| 天祝| 通城县| 辛集市| 贺兰县| 潢川县| 梅河口市| 永年县| 疏勒县| 南漳县| 石楼县| 色达县| 三都| 信阳市| 花垣县| 阿拉善右旗| 惠水县| 太谷县| 瑞丽市| 唐海县| 威海市| 义马市| 吉木萨尔县| 庄河市| 来凤县| 光泽县| 延津县| 苍山县| 衡山县| 即墨市| 上饶市| 东兰县| 巨野县| 海安县| 西丰县| 霸州市| 萝北县| 乌审旗| 曲阳县| 社会| 合作市|