Skip to content

Commit 0902405

Browse files
authored
Create test_algorithms.py
1 parent 9576888 commit 0902405

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

test_algorithms.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# 假設您有一個名為 'my_algorithms.py' 的檔案,其中有一個函數
2+
# def add_numbers(a, b):
3+
# return a + b
4+
5+
# 您的測試檔案 test_algorithms.py
6+
import sys
7+
import os
8+
9+
# 假設您的演算法程式碼在 'your_project_name/' 下
10+
# 為了讓測試能找到您的演算法模組,可能需要調整 PYTHONPATH 或相對路徑導入
11+
# 一個常見的解決方案是確保 pytest 在專案根目錄運行
12+
# 如果您的演算法程式碼在子目錄中,您可能需要這樣導入:
13+
# from your_module_name.your_algorithm_file import your_function
14+
15+
# 簡單的測試函數範例
16+
def test_addition():
17+
result = 2 + 3
18+
assert result == 5
19+
20+
def test_multiplication():
21+
result = 2 * 3
22+
assert result == 6
23+
24+
# 如果您有實際的演算法函數,例如在 algorithms/sort.py 中有一個 quick_sort 函數
25+
# 並且您的 CI 運行目錄在專案根目錄
26+
# from algorithms.sort import quick_sort # 假設有這個路徑
27+
# def test_quick_sort():
28+
# arr = [3, 1, 4, 1, 5, 9, 2, 6]
29+
# quick_sort(arr)
30+
# assert arr == [1, 1, 2, 3, 4, 5, 6, 9]

0 commit comments

Comments
 (0)