-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an Python example project and unit tests for pytest.
- Loading branch information
Showing
3 changed files
with
122 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from unittest import TestCase | ||
|
||
|
||
class A: | ||
_value: int | ||
|
||
def __init__(self, value: int = 0): | ||
self._value = value | ||
|
||
@property | ||
def Value(self) -> int: | ||
return self._value | ||
|
||
@Value.setter | ||
def Value(self, value: int): | ||
self._value = value | ||
|
||
|
||
class Instantiation(TestCase): | ||
def test_NoParameter(self): | ||
a = A() | ||
|
||
self.assertEqual(0, a.Value) | ||
|
||
def test_Parameter(self): | ||
a = A(5) | ||
|
||
self.assertEqual(5, a.Value) | ||
|
||
|
||
class Properties(TestCase): | ||
def test_Getter(self): | ||
a = A(10) | ||
|
||
self.assertEqual(10, a.Value) | ||
|
||
def test_Setter(self): | ||
a = A(15) | ||
self.assertEqual(15, a.Value) | ||
|
||
a.Value = 20 | ||
self.assertEqual(20, a.Value) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from unittest import TestCase | ||
|
||
|
||
class C: | ||
_value: int | ||
|
||
def __init__(self, value: int = 0): | ||
self._value = value | ||
|
||
def Add(self, value: int) -> int: | ||
self._value += value | ||
return self._value | ||
|
||
def Sub(self, value: int) -> int: | ||
self._value -= value | ||
return self._value | ||
|
||
@property | ||
def Value(self) -> int: | ||
return self._value | ||
|
||
@Value.setter | ||
def Value(self, value: int): | ||
self._value = value | ||
|
||
|
||
class Instantiation(TestCase): | ||
def test_NoParameter(self): | ||
a = C() | ||
|
||
self.assertEqual(0, a.Value) | ||
|
||
def test_Parameter(self): | ||
a = C(5) | ||
|
||
self.assertEqual(5, a.Value) | ||
|
||
|
||
class Operations(TestCase): | ||
def test_Add(self): | ||
a = C(10) | ||
|
||
self.assertEqual(10, a.Value) | ||
self.assertEqual(15, a.Add(5)) | ||
self.assertEqual(15, a.Value) | ||
|
||
def test_Sub(self): | ||
a = C(10) | ||
|
||
self.assertEqual(10, a.Value) | ||
self.assertEqual(8, a.Sub(2)) | ||
self.assertEqual(8, a.Value) |