From a70d03b3660a12a11cbc99613eff7855b94c6734 Mon Sep 17 00:00:00 2001 From: Y_SAKAI Date: Thu, 4 Aug 2022 19:40:13 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20couter=5Fobject.py=E3=81=AE?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=B3=E3=83=BC=E3=83=89=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/util/test_counter_object.py | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 ecs/crm-datafetch/tests/util/test_counter_object.py diff --git a/ecs/crm-datafetch/tests/util/test_counter_object.py b/ecs/crm-datafetch/tests/util/test_counter_object.py new file mode 100644 index 00000000..47b9928a --- /dev/null +++ b/ecs/crm-datafetch/tests/util/test_counter_object.py @@ -0,0 +1,114 @@ +import pytest +from src.util.counter_object import CounterObject + + +class TestCounterObject: + + def test_describe(self) -> int: + """ + Cases: + カウンターオブジェクトにて保持した値を返すこと + Arranges: + なし + Expects: + 問い合わせた値が期待値と一致する + """ + + # Act + sut = CounterObject(5) + actual = sut.describe() + + # Expects + assert actual == 5 + + def test_raise_describe(self) -> int: + """ + Cases: + カウンターオブジェクトにて保持した値を返すこと + Arranges: + なし + Expects: + 問い合わせた値が期待値と一致する + """ + + # Act + with pytest.raises(Exception) as e: + sut = CounterObject("aaa") + sut.describe() + + # Expects + assert str(e.value) == '例外' + + def test_increment(self, num=1) -> int: + """ + Cases: + カウンターオブジェクトにて保持した値がインクリメントされていること + Arranges: + なし + Expects: + 戻り値が期待値と一致する + """ + + # Act + sut = CounterObject(5) + sut.increment() + actual = sut.increment() + + # Expects + assert actual == 7 + + def test_raise_increment(self, num=1) -> int: + """ + Cases: + 文字列を引数で渡すことで、例外が発生すること + Arranges: + なし + Expects: + 発生した例外が期待値と一致する + """ + + # Act + with pytest.raises(Exception) as e: + sut = CounterObject(5) + sut.increment('aaa') + sut.increment('aaa') + + # Expects + assert str(e.value) == "unsupported operand type(s) for +=: 'int' and 'str'" + + def test_decrement(self, num=1) -> int: + """ + Cases: + カウンターオブジェクトにて保持した値がデクリメントされていること + Arranges: + なし + Expects: + 戻り値が期待値と一致する + """ + + # Act + sut = CounterObject(5) + sut.decrement(2) + actual = sut.decrement(2) + + # Expects + assert actual == 1 + + def test_raise_decrement(self, num=1) -> int: + """ + Cases: + 文字列を引数で渡すことで、例外が発生すること + Arranges: + なし + Expects: + 発生した例外が期待値と一致する + """ + + # Act + with pytest.raises(Exception) as e: + sut = CounterObject(5) + sut.decrement('aaa') + sut.decrement('aaa') + + # Expects + assert str(e.value) == "unsupported operand type(s) for -=: 'int' and 'str'" From 36fb6105621e4a5c33cea956f3e63e6777ac19c3 Mon Sep 17 00:00:00 2001 From: Y_SAKAI Date: Fri, 5 Aug 2022 09:41:36 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E6=AD=A3=E5=B8=B8=E7=B3=BB=E3=80=81?= =?UTF-8?q?=E7=95=B0=E5=B8=B8=E7=B3=BB=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/util/test_counter_object.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ecs/crm-datafetch/tests/util/test_counter_object.py b/ecs/crm-datafetch/tests/util/test_counter_object.py index 47b9928a..8bf677a0 100644 --- a/ecs/crm-datafetch/tests/util/test_counter_object.py +++ b/ecs/crm-datafetch/tests/util/test_counter_object.py @@ -15,16 +15,16 @@ class TestCounterObject: """ # Act - sut = CounterObject(5) + sut = CounterObject() actual = sut.describe() # Expects - assert actual == 5 + assert actual == 1 def test_raise_describe(self) -> int: """ Cases: - カウンターオブジェクトにて保持した値を返すこと + カウンターオブジェクトの保持した値を問い合わせる際、引数を渡すと例外が発生すること Arranges: なし Expects: @@ -33,13 +33,13 @@ class TestCounterObject: # Act with pytest.raises(Exception) as e: - sut = CounterObject("aaa") - sut.describe() + sut = CounterObject() + sut.describe(1) # Expects - assert str(e.value) == '例外' + assert str(e.value) == 'describe() takes 1 positional argument but 2 were given' - def test_increment(self, num=1) -> int: + def test_increment(self) -> int: """ Cases: カウンターオブジェクトにて保持した値がインクリメントされていること @@ -57,7 +57,7 @@ class TestCounterObject: # Expects assert actual == 7 - def test_raise_increment(self, num=1) -> int: + def test_raise_increment(self) -> int: """ Cases: 文字列を引数で渡すことで、例外が発生すること @@ -76,7 +76,7 @@ class TestCounterObject: # Expects assert str(e.value) == "unsupported operand type(s) for +=: 'int' and 'str'" - def test_decrement(self, num=1) -> int: + def test_decrement(self) -> int: """ Cases: カウンターオブジェクトにて保持した値がデクリメントされていること @@ -94,7 +94,7 @@ class TestCounterObject: # Expects assert actual == 1 - def test_raise_decrement(self, num=1) -> int: + def test_raise_decrement(self) -> int: """ Cases: 文字列を引数で渡すことで、例外が発生すること From e3240e71796b348c69bf344f18af6c7a059bde5a Mon Sep 17 00:00:00 2001 From: Y_SAKAI Date: Wed, 10 Aug 2022 10:08:49 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E3=82=A4=E3=83=B3=E3=82=B9=E3=82=BF?= =?UTF-8?q?=E3=83=B3=E3=82=B9=E7=94=9F=E6=88=90=E6=99=82=E3=81=AB=E6=96=87?= =?UTF-8?q?=E5=AD=97=E5=88=97=E3=82=92=E6=B8=A1=E3=81=99=E3=81=A8=E4=BE=8B?= =?UTF-8?q?=E5=A4=96=E3=81=8C=E7=99=BA=E7=94=9F=E3=81=99=E3=82=8B=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=92=E8=BF=BD=E5=8A=A0=E3=80=82=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=B3=E3=83=BC=E3=83=89=E3=81=AE=E3=83=AC=E3=83=93?= =?UTF-8?q?=E3=83=A5=E3=83=BC=E6=8C=87=E6=91=98=E5=86=85=E5=AE=B9=E3=81=AE?= =?UTF-8?q?=E5=8F=8D=E6=98=A0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecs/crm-datafetch/src/util/counter_object.py | 2 +- .../tests/util/test_counter_object.py | 111 +++++++++++++++++- 2 files changed, 106 insertions(+), 7 deletions(-) diff --git a/ecs/crm-datafetch/src/util/counter_object.py b/ecs/crm-datafetch/src/util/counter_object.py index 23da4f82..6cf6b7c2 100644 --- a/ecs/crm-datafetch/src/util/counter_object.py +++ b/ecs/crm-datafetch/src/util/counter_object.py @@ -1,6 +1,6 @@ class CounterObject: def __init__(self, base_num=1) -> None: - self.__counter = base_num + self.__counter = int(base_num) def describe(self) -> int: return self.__counter diff --git a/ecs/crm-datafetch/tests/util/test_counter_object.py b/ecs/crm-datafetch/tests/util/test_counter_object.py index 8bf677a0..787099ba 100644 --- a/ecs/crm-datafetch/tests/util/test_counter_object.py +++ b/ecs/crm-datafetch/tests/util/test_counter_object.py @@ -4,10 +4,56 @@ from src.util.counter_object import CounterObject class TestCounterObject: + def test_constructor(self) -> int: + """ + Cases: + カウンターオブジェクト生成時に、数値を渡すと例外が発生しないこと + Arranges: + なし + Expects: + 例外が発生しないこと + """ + # Act + CounterObject(1) + + # Expects + pass + + def test_constructor_string_number(self) -> int: + """ + Cases: + カウンターオブジェクト生成時に、文字列型の数値を渡すと例外が発生しないこと + Arranges: + なし + Expects: + 例外が発生しないこと + """ + # Act + CounterObject("1") + + # Expects + pass + + def test_raise_constructor_string(self) -> int: + """ + Cases: + カウンターオブジェクト生成時に、文字列を渡すと例外が発生すること + Arranges: + なし + Expects: + 発生した例外が期待値と一致すること + """ + # Act + with pytest.raises(Exception) as e: + CounterObject("test1") + + # Expects + assert "invalid literal for int() with base 10:" in str(e.value) + def test_describe(self) -> int: """ Cases: - カウンターオブジェクトにて保持した値を返すこと + カウンターオブジェクトにて保持した値を返すこと(インスタンス生成時引数なし) Arranges: なし Expects: @@ -21,6 +67,23 @@ class TestCounterObject: # Expects assert actual == 1 + def test_describe_argument(self) -> int: + """ + Cases: + カウンターオブジェクトにて保持した値を返すこと(インスタンス生成時引数あり) + Arranges: + なし + Expects: + 問い合わせた値が期待値と一致する + """ + + # Act + sut = CounterObject(3) + actual = sut.describe() + + # Expects + assert actual == 3 + def test_raise_describe(self) -> int: """ Cases: @@ -42,7 +105,25 @@ class TestCounterObject: def test_increment(self) -> int: """ Cases: - カウンターオブジェクトにて保持した値がインクリメントされていること + カウンターオブジェクトにて保持した値がインクリメントされていること(引数なし) + Arranges: + なし + Expects: + 戻り値が期待値と一致する + """ + + # Act + sut = CounterObject() + sut.increment() + actual = sut.increment() + + # Expects + assert actual == 3 + + def test_increment_argument(self) -> int: + """ + Cases: + カウンターオブジェクトにて保持した値がインクリメントされていること(引数あり) Arranges: なし Expects: @@ -51,11 +132,11 @@ class TestCounterObject: # Act sut = CounterObject(5) - sut.increment() - actual = sut.increment() + sut.increment(2) + actual = sut.increment(2) # Expects - assert actual == 7 + assert actual == 9 def test_raise_increment(self) -> int: """ @@ -79,7 +160,25 @@ class TestCounterObject: def test_decrement(self) -> int: """ Cases: - カウンターオブジェクトにて保持した値がデクリメントされていること + カウンターオブジェクトにて保持した値がデクリメントされていること(引数なし) + Arranges: + なし + Expects: + 戻り値が期待値と一致する + """ + + # Act + sut = CounterObject() + sut.decrement() + actual = sut.decrement() + + # Expects + assert actual == -1 + + def test_decrement_argument(self) -> int: + """ + Cases: + カウンターオブジェクトにて保持した値がデクリメントされていること(引数あり) Arranges: なし Expects: