Last active
February 15, 2020 08:19
-
-
Save PET-HAL/100b67acb33a5b19c9b1ee3ec5777521 to your computer and use it in GitHub Desktop.
TDD Boot Camp in 愛媛 #1 TDD&ペアプログラミング 実習
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- [] 整数閉区間を示すクラス(あるいは構造体)をつくる。 | |
- [✕] 1つの整数を入力すると文字列が返ってくる | |
- [] 整数閉区間オブジェクトは下端点と上端点を持つ。 | |
- [] 文字列表現も返せる。 | |
(例: 下端点 3, 上端点 8 の整数閉区間の文字列表記は "[3,8]")。 | |
- [✕] 1と2を入力すると括弧付きの文字列が返ってくる | |
- [✕] 上端点より下端点が大きい閉区間を作ることはできない。 | |
- [✕] 2と1を入力すると例外をスローする | |
- [] 整数の閉区間は指定した整数を含むかどうかを判定できる。 | |
- [] 別の閉区間と等価かを判定できる。 | |
- [✕] 1と2の閉区間と、1と2の閉区間が等価であることを判定する | |
- [✕] 1と2の閉区間と、2と3の閉区間が等価ではないことを判定する | |
- [✕] 1と2の閉区間と、0と1の閉区間が等価ではないことを判定する | |
- [✕] 1と2の閉区間と、3と4の閉区間が等価ではないことを判定する | |
- [] 完全に含まれるかどうかを判定できる。(両方の) | |
- [✕] 1と2の閉区間と、1と2の閉区間が完全に含まれることを判定する | |
- [✕] 1と2の閉区間と、0と3の閉区間が完全に含まれることを判定する | |
- [✕] 1と2の閉区間と、3と4の閉区間が完全に含まれないことを判定する |
ClosedRange.php
<?php
/**
* Created by IntelliJ IDEA.
* User: gachakra
* Date: 2020/02/15
* Time: 13:56
*/
declare(strict_types=1);
namespace Src;
class ClosedRange {
private $lower;
private $upper;
/**
* ClosedRange constructor.
* @param int $lower
* @param int $upper
*/
public function __construct(int $lower, int $upper) {
if ($lower > $upper) {
throw new \OutOfRangeException();
}
$this->lower = $lower;
$this->upper = $upper;
}
public function stringify() {
return "[$this->lower,$this->upper]";
}
public function equals(ClosedRange $closedRange2) {
return $this == $closedRange2;
}
public function contains(ClosedRange $closedRange2) {
return $this->lower <= $closedRange2->lower && $this->upper >= $closedRange2-> upper;
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ClosedRangeTest.php