feat: 新增Notion自动化综合案例示例代码
This commit is contained in:
18
projects/notion-automator/tests/basic.py
Normal file
18
projects/notion-automator/tests/basic.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from typing import TypeVar, Union
|
||||
|
||||
Number = TypeVar("Number", bound=Union[int, float])
|
||||
|
||||
|
||||
def divide(x: Number, y: Number) -> Number:
|
||||
result = x / y
|
||||
return result
|
||||
|
||||
|
||||
def main():
|
||||
print(divide(2, 1))
|
||||
print(divide(0, 1))
|
||||
print(divide(100, 10))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
34
projects/notion-automator/tests/test_with_testify.py
Normal file
34
projects/notion-automator/tests/test_with_testify.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from typing import TypeVar, Union
|
||||
|
||||
Number = TypeVar("Number", bound=Union[int, float])
|
||||
|
||||
|
||||
def divide(x: Number, y: Number) -> Number:
|
||||
result = x / y
|
||||
return result
|
||||
|
||||
|
||||
def testify(func, *, expected, **kwargs):
|
||||
template = f"testing for {func.__name__} with {kwargs}..."
|
||||
result = func(**kwargs)
|
||||
if result == expected:
|
||||
print(template + "ok.")
|
||||
return True
|
||||
|
||||
print(template + "failed.")
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
cases = [
|
||||
testify(divide, x=2, y=1, expected=2),
|
||||
testify(divide, x=0, y=1, expected=0),
|
||||
testify(divide, x=100, y=10, expected=10),
|
||||
testify(divide, x=1, y=2, expected=2),
|
||||
]
|
||||
is_passed = all(cases)
|
||||
print(is_passed)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
56
projects/notion-automator/tests/unittest_basic.py
Normal file
56
projects/notion-automator/tests/unittest_basic.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import unittest
|
||||
from tkinter.messagebox import NO
|
||||
|
||||
|
||||
class Vector:
|
||||
def __init__(self, x, y) -> None:
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"Vector<x={self.x}, y={self.y}>"
|
||||
|
||||
def __add__(self, other: "Vector"):
|
||||
return Vector(self.x + other.x, self.y + other.y)
|
||||
|
||||
def __sub__(self, other: "Vector"):
|
||||
return Vector(self.x - other.x, self.y - other.y)
|
||||
|
||||
@property
|
||||
def props(self):
|
||||
return self.x, self.y
|
||||
|
||||
def distance(self, other: "Vector"):
|
||||
result = (other.x**2 - self.x**2) + (other.y**2 - self.y**2)
|
||||
return abs(result)
|
||||
|
||||
|
||||
class TestVector(unittest.TestCase):
|
||||
|
||||
vec_a = None
|
||||
vec_b = None
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls) -> None:
|
||||
cls.vec_a = Vector(x=2, y=5)
|
||||
cls.vec_b = Vector(x=-1, y=2)
|
||||
|
||||
def test_props(self):
|
||||
vector = Vector(1, 2)
|
||||
self.assertEqual(vector.props, (1, 2))
|
||||
|
||||
def test_add(self):
|
||||
result = self.vec_a + self.vec_b
|
||||
self.assertTupleEqual(result.props, (1, 7))
|
||||
|
||||
def test_sub(self):
|
||||
result = self.vec_a - self.vec_b
|
||||
self.assertTupleEqual(result.props, (3, 3))
|
||||
|
||||
def test_distance(self):
|
||||
result = self.vec_a.distance(self.vec_b)
|
||||
self.assertEqual(result, 24)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(verbosity=2)
|
||||
Reference in New Issue
Block a user