@wwkit/harness 1.0.33 → 1.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +128 -128
- package/agents/scrum.md +206 -186
- package/agents/sprint.md +130 -121
- package/bin/index.js +291 -226
- package/commands/fix.md +87 -87
- package/commands/git-sync.md +217 -217
- package/commands/net-port.md +364 -364
- package/commands/pytest.md +10 -10
- package/commands/resume.md +104 -104
- package/commands/tl.md +11 -11
- package/commands/tsl.md +12 -0
- package/package.json +5 -4
- package/plugin.js +19 -19
- package/readme/development.md +39 -39
- package/readme/publish.md +41 -41
- package/readme/testing.md +44 -44
- package/scripts/postinstall.js +58 -58
- package/skills/better-agents/SKILL.md +300 -0
- package/skills/better-agents/references/evidence-map.md +102 -0
- package/skills/better-agents/references/format-spec.md +91 -0
- package/skills/better-agents/references/section-template.md +116 -0
- package/skills/better-skill/SKILL.md +319 -124
- package/skills/better-skill/references/new-mode.md +126 -0
- package/skills/blame-agents/SKILL.md +270 -0
- package/skills/blame-agents/references/check-agents.js +364 -0
- package/skills/blame-agents/references/scoring-rules.md +259 -0
- package/skills/blame-skill/SKILL.md +163 -201
- package/skills/blame-skill/references/scoring-rules.md +190 -0
- package/skills/blame-sprint-agent/SKILL.md +172 -0
- package/skills/blame-sprint-agent/references/scoring-rules.md +113 -0
- package/skills/blame-sprint-skill/SKILL.md +165 -0
- package/skills/blame-sprint-skill/references/scoring-rules.md +101 -0
- package/skills/extract/SKILL.md +119 -119
- package/skills/extract/references/build-xpath.js +30 -30
- package/skills/extract/references/clean-html.js +90 -90
- package/skills/extract/references/detail.md +54 -54
- package/skills/extract/references/detail.schema.json5 +48 -48
- package/skills/extract/references/extract-detail.js +71 -71
- package/skills/extract/references/extract-regex.js +81 -81
- package/skills/extract/references/extract-sample.js +48 -48
- package/skills/extract/references/list-rule-gen.md +109 -109
- package/skills/extract/references/list.md +134 -134
- package/skills/extract/references/list.schema.json5 +33 -33
- package/skills/extract/references/navi.md +44 -44
- package/skills/extract/references/navi.schema.json5 +23 -23
- package/skills/extract/references/text.md +40 -40
- package/skills/extract/references/text.schema.json5 +21 -21
- package/skills/extract/references/to-text.js +20 -20
- package/skills/extract/references/validate-schema.js +39 -39
- package/skills/jstest/SKILL.md +561 -561
- package/skills/jstest/references/case-create.md +327 -327
- package/skills/jstest/references/case-fix.md +273 -273
- package/skills/jstest/references/config.md +148 -148
- package/skills/jstest/references/coverage-analyze.md +247 -247
- package/skills/jstest/references/env-ensure.md +210 -210
- package/skills/jstest/references/execute.md +168 -168
- package/skills/jstest/references/sample.md +166 -166
- package/skills/jstest/references/scoring-rules.md +75 -75
- package/skills/jstest/references/src/jstest-sample/Calculator.js +80 -80
- package/skills/jstest/references/src/jstest-sample/ConfigManager.js +72 -72
- package/skills/jstest/references/src/jstest-sample/FileProcessor.js +57 -57
- package/skills/jstest/references/src/jstest-sample/OrderService.js +98 -98
- package/skills/jstest/references/src/jstest-sample/TokenGenerator.js +60 -60
- package/skills/jstest/references/src/jstest-sample/UserService.js +56 -56
- package/skills/jstest/references/src/jstest-sample/index.js +6 -6
- package/skills/jstest/references/suitability-check.md +232 -232
- package/skills/jstest/references/test-standards.md +288 -288
- package/skills/lint/SKILL.md +440 -440
- package/skills/lint/references/ai-fix.md +137 -137
- package/skills/lint/references/config-setup.md +102 -102
- package/skills/lint/references/config.md +65 -65
- package/skills/lint/references/detect-language.js +65 -65
- package/skills/lint/references/env-ensure.md +88 -88
- package/skills/lint/references/language-detect.md +75 -75
- package/skills/lint/references/languages/js.md +110 -110
- package/skills/lint/references/languages/py.md +89 -89
- package/skills/lint/references/rules-analyze.md +125 -125
- package/skills/lint/references/suitability-check.md +81 -81
- package/skills/lint/references/tool-fix.md +90 -90
- package/skills/pytest/SKILL.md +555 -555
- package/skills/pytest/references/case-create.md +324 -324
- package/skills/pytest/references/case-fix.md +271 -271
- package/skills/pytest/references/config.md +145 -145
- package/skills/pytest/references/coverage-analyze.md +223 -223
- package/skills/pytest/references/env-ensure.md +195 -195
- package/skills/pytest/references/execute.md +152 -152
- package/skills/pytest/references/sample.md +159 -159
- package/skills/pytest/references/scoring-rules.md +57 -57
- package/skills/pytest/references/src/pytest-sample/Calculator.py +67 -67
- package/skills/pytest/references/src/pytest-sample/ConfigManager.py +68 -68
- package/skills/pytest/references/src/pytest-sample/FileProcessor.py +53 -53
- package/skills/pytest/references/src/pytest-sample/OrderService.py +82 -82
- package/skills/pytest/references/src/pytest-sample/TokenGenerator.py +50 -50
- package/skills/pytest/references/src/pytest-sample/UserService.py +45 -45
- package/skills/pytest/references/suitability-check.md +220 -220
- package/skills/pytest/references/test-standards.md +244 -244
- package/skills/query/SKILL.md +71 -71
- package/skills/read-docs/SKILL.md +134 -134
- package/skills/read-docs/references/opencode/agents/cases.md +206 -206
- package/skills/read-docs/references/opencode/agents/design-pattern.md +47 -47
- package/skills/read-docs/references/opencode/agents/detail.md +191 -191
- package/skills/read-docs/references/opencode/agents/examples.md +100 -100
- package/skills/read-docs/references/opencode/agents/index.md +309 -309
- package/skills/read-docs/references/opencode/agents/parallel-dispatch.md +149 -149
- package/skills/read-docs/references/opencode/agents/subagent-internals.md +217 -217
- package/skills/read-docs/references/opencode/agents/workflow.md +161 -161
- package/skills/read-docs/references/opencode/cli/commands/acp.md +31 -31
- package/skills/read-docs/references/opencode/cli/commands/agent.md +16 -16
- package/skills/read-docs/references/opencode/cli/commands/attach.md +20 -20
- package/skills/read-docs/references/opencode/cli/commands/mcp.md +37 -37
- package/skills/read-docs/references/opencode/cli/commands/others.md +48 -48
- package/skills/read-docs/references/opencode/cli/commands/plugin.md +12 -12
- package/skills/read-docs/references/opencode/cli/commands/provider.md +43 -43
- package/skills/read-docs/references/opencode/cli/commands/run.md +81 -81
- package/skills/read-docs/references/opencode/cli/commands/serve.md +84 -84
- package/skills/read-docs/references/opencode/cli/commands/session.md +37 -37
- package/skills/read-docs/references/opencode/cli/commands/web.md +14 -14
- package/skills/read-docs/references/opencode/cli/env.md +38 -38
- package/skills/read-docs/references/opencode/cli/index.md +18 -18
- package/skills/read-docs/references/opencode/cli/tui.md +35 -35
- package/skills/read-docs/references/opencode/commands/examples.md +42 -42
- package/skills/read-docs/references/opencode/commands/index.md +185 -185
- package/skills/read-docs/references/opencode/config/provider.md +151 -151
- package/skills/read-docs/references/opencode/formatter/index.md +70 -70
- package/skills/read-docs/references/opencode/guide/config.md +419 -419
- package/skills/read-docs/references/opencode/guide/formatters.md +70 -70
- package/skills/read-docs/references/opencode/guide/index.md +37 -37
- package/skills/read-docs/references/opencode/guide/providers.md +31 -31
- package/skills/read-docs/references/opencode/guide/rules.md +63 -63
- package/skills/read-docs/references/opencode/plugins/examples.md +75 -75
- package/skills/read-docs/references/opencode/plugins/index.md +188 -188
- package/skills/read-docs/references/opencode/reference/index.md +118 -118
- package/skills/read-docs/references/opencode/rule/index.md +77 -77
- package/skills/read-docs/references/opencode/skills/detail.md +113 -113
- package/skills/read-docs/references/opencode/skills/examples.md +141 -141
- package/skills/read-docs/references/opencode/skills/index.md +126 -126
- package/skills/read-docs/references/opencode/skills/workflow.md +146 -146
- package/skills/read-docs/references/opencode/tests/agent.md +9 -9
- package/skills/read-docs/references/opencode/tests/config.md +59 -59
- package/skills/read-docs/references/opencode/tests/file.md +11 -11
- package/skills/read-docs/references/opencode/tests/serve.md +17 -17
- package/skills/read-docs/references/opencode/tests/session.md +30 -30
- package/skills/read-docs/references/opencode/tests/web.md +16 -16
- package/skills/read-docs/references/opencode/tools/arguments.md +305 -305
- package/skills/read-docs/references/opencode/tools/context.md +17 -17
- package/skills/read-docs/references/opencode/tools/custom.md +110 -110
- package/skills/read-docs/references/opencode/tools/detail.md +104 -104
- package/skills/read-docs/references/opencode/tools/examples.md +71 -71
- package/skills/read-docs/references/opencode/tools/index.md +56 -56
- package/skills/read-docs/references/opencode/tools/lsp.md +25 -25
- package/skills/read-docs/references/opencode/tools/mcp.md +132 -132
- package/skills/read-docs/references/opencode/train/README.md +134 -134
- package/skills/read-docs/references/opencode/train/agent-basic.md +771 -771
- package/skills/read-docs/references/opencode/train/command-basic.md +667 -667
- package/skills/read-docs/references/opencode/train/config-basic.md +508 -508
- package/skills/read-docs/references/opencode/train/index.md +163 -163
- package/skills/read-docs/references/opencode/train/practice.md +872 -872
- package/skills/read-docs/references/opencode/train/skill-basic.md +607 -607
- package/skills/read-docs/references/opencode/tui/commands/config.md +31 -31
- package/skills/read-docs/references/opencode/tui/commands/editor.md +46 -46
- package/skills/read-docs/references/opencode/tui/commands/index.md +124 -124
- package/skills/read-docs/references/opencode/tui/commands/init.md +4 -4
- package/skills/read-docs/references/opencode/tui/index.md +26 -26
- package/skills/read-docs/references/superpowers/bootstrap.md +107 -107
- package/skills/read-docs/references/superpowers/comparison.md +77 -77
- package/skills/read-docs/references/superpowers/context.md +71 -71
- package/skills/read-docs/references/superpowers/index.md +58 -58
- package/skills/read-docs/references/superpowers/parallel.md +49 -49
- package/skills/read-docs/references/superpowers/sdd.md +183 -183
- package/skills/read-docs/references/superpowers/skills.md +68 -68
- package/skills/read-docs/references/superpowers/workflow.md +83 -83
- package/skills/revise/SKILL.md +121 -121
- package/skills/revise/references/article.md +36 -36
- package/skills/revise/references/article.schema.json5 +40 -40
- package/skills/revise/references/gallery.md +34 -34
- package/skills/revise/references/gallery.schema.json5 +40 -40
- package/skills/revise/references/question.md +32 -32
- package/skills/revise/references/question.schema.json5 +31 -31
- package/skills/revise/references/status.md +31 -31
- package/skills/revise/references/status.schema.json5 +27 -27
- package/skills/revise/references/validate-schema.js +39 -39
- package/skills/step-extract/SKILL.md +205 -0
- package/skills/tsl/SKILL.md +393 -0
- package/skills/tsl/package.json +10 -0
- package/skills/tsl/references/global-review-rules.md +25 -0
- package/skills/tsl/references/prepare-prompt.md +150 -0
- package/skills/tsl/references/terminology-rules.md +93 -0
- package/skills/tsl/references/translation-guide.md +23 -0
- package/skills/tsl/references/translation-prompt.md +115 -0
- package/skills/tsl/references/translation-rules.md +48 -0
- package/skills/tsl/references/verification-rules.md +58 -0
- package/skills/tsl/scripts/check-boundaries.js +140 -0
- package/skills/tsl/scripts/chunk-text.js +144 -0
- package/skills/tsl/scripts/clean-text.js +121 -0
- package/skills/tsl/scripts/cleanup-glossary.js +160 -0
- package/skills/tsl/scripts/extract-pdf.js +94 -0
- package/skills/tsl/scripts/generate-review.js +179 -0
- package/skills/tsl/scripts/merge-result.js +164 -0
- package/skills/tsl/scripts/verify-chunk.js +170 -0
- package/skills/tsl-format/SKILL.md +298 -0
- package/skills/tsl-format/references/format-prompt.md +103 -0
- package/skills/tsl-format/references/format-rules.md +58 -0
- package/skills/tsl-format/scripts/chunk-bilingual.js +96 -0
- package/skills/tsl-format/scripts/merge-format.js +105 -0
- package/src/config.js +29 -29
- package/src/config.json5 +19 -19
- package/skills/new-skill/SKILL.md +0 -227
- package/skills/new-skill/references/template.md +0 -53
- package/skills/new-skill/references/workflow-patterns.md +0 -104
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
# 评分规则
|
|
2
|
-
|
|
3
|
-
> 覆盖率数据完全来自 `coverage.json`(pytest-cov 生成),质量维度通过文件扫描检查,无主观判断。
|
|
4
|
-
|
|
5
|
-
## 单元测试评分(unit)— 满分 100
|
|
6
|
-
|
|
7
|
-
### 覆盖率维度(80 分)
|
|
8
|
-
|
|
9
|
-
| 维度 | 满分 | 阈值 | 数据来源 | 计分公式 |
|
|
10
|
-
|------|------|------|---------|---------|
|
|
11
|
-
| 行覆盖率 | 30 | 90% | coverage.json: covered_lines / num_statements | `min(实际/阈值, 1) × 30` |
|
|
12
|
-
| 分支覆盖率 | 30 | 70% | coverage.json: covered_branches / num_branches | `min(实际/阈值, 1) × 30` |
|
|
13
|
-
| 函数覆盖率 | 20 | 90% | coverage.json: covered_functions / num_functions | `min(实际/阈值, 1) × 20` |
|
|
14
|
-
|
|
15
|
-
### 质量维度(20 分)
|
|
16
|
-
|
|
17
|
-
| 维度 | 满分 | 检查方法 | 计分公式 |
|
|
18
|
-
|------|------|---------|---------|
|
|
19
|
-
| 断言完整性 | 5 | 扫描测试文件,统计含 `assert` 关键字的 test 函数比例 | `(有assert函数数 / 总函数数) × 5` |
|
|
20
|
-
| 异常路径覆盖 | 5 | 源码含 `raise`/`try` 的函数,测试中是否有对应 `pytest.raises` | `(有异常测试数 / 应测异常函数数) × 5` |
|
|
21
|
-
| 边界值覆盖 | 5 | 源码含 `if`/`elif` 的函数,测试用例数 ≥ 分支数 | `(达标函数数 / 应测函数数) × 5` |
|
|
22
|
-
| 命名规范 | 5 | test 函数名匹配 `^test_\w+_\w+$` | `(规范命名数 / 总数) × 5` |
|
|
23
|
-
|
|
24
|
-
## 集成测试评分(integration)— 满分 100
|
|
25
|
-
|
|
26
|
-
### 覆盖率维度(50 分)
|
|
27
|
-
|
|
28
|
-
| 维度 | 满分 | 阈值 | 数据来源 | 计分公式 |
|
|
29
|
-
|------|------|------|---------|---------|
|
|
30
|
-
| 行覆盖率 | 20 | 70% | coverage.json: covered_lines / num_statements | `min(实际/阈值, 1) × 20` |
|
|
31
|
-
| 分支覆盖率 | 20 | 50% | coverage.json: covered_branches / num_branches | `min(实际/阈值, 1) × 20` |
|
|
32
|
-
| 函数覆盖率 | 10 | 70% | coverage.json: covered_functions / num_functions | `min(实际/阈值, 1) × 10` |
|
|
33
|
-
|
|
34
|
-
### 质量维度(50 分)
|
|
35
|
-
|
|
36
|
-
| 维度 | 满分 | 检查方法 | 计分公式 |
|
|
37
|
-
|------|------|---------|---------|
|
|
38
|
-
| 场景完整性 | 15 | 核心业务场景是否都有对应测试(按源码公开方法数统计) | `(有测试的场景数 / 应测场景数) × 15` |
|
|
39
|
-
| 数据流验证 | 10 | 测试中是否验证了输入→处理→输出完整链路(含多步 assert) | `(有数据流验证的函数数 / 总函数数) × 10` |
|
|
40
|
-
| 断言完整性 | 10 | 每个测试函数至少含 1 个 assert | `(有assert函数数 / 总函数数) × 10` |
|
|
41
|
-
| fixture 使用 | 10 | 是否合理使用 setup/teardown fixture | `(有fixture的测试类数 / 总类数) × 10` |
|
|
42
|
-
| 命名规范 | 5 | test 函数名匹配 `^test_\w+_\w+$` | `(规范命名数 / 总数) × 5` |
|
|
43
|
-
|
|
44
|
-
## 通用规则
|
|
45
|
-
|
|
46
|
-
- **分母为 0**:若应测数为 0(无适用项),该项直接给满分。
|
|
47
|
-
- **超限封顶**:`min(实际/阈值, 1.0)` 确保单项不超过满分。
|
|
48
|
-
- **数据来源**:覆盖率维度完全依赖 coverage.json;质量维度通过 grep/扫描测试文件检查。
|
|
49
|
-
|
|
50
|
-
## 等级
|
|
51
|
-
|
|
52
|
-
| 等级 | 分数范围 | 含义 |
|
|
53
|
-
|------|---------|------|
|
|
54
|
-
| A | 90-100 | 优秀 |
|
|
55
|
-
| B | 80-89 | 合格 |
|
|
56
|
-
| C | 60-79 | 需改进 |
|
|
57
|
-
| D | <60 | 不合格 |
|
|
1
|
+
# 评分规则
|
|
2
|
+
|
|
3
|
+
> 覆盖率数据完全来自 `coverage.json`(pytest-cov 生成),质量维度通过文件扫描检查,无主观判断。
|
|
4
|
+
|
|
5
|
+
## 单元测试评分(unit)— 满分 100
|
|
6
|
+
|
|
7
|
+
### 覆盖率维度(80 分)
|
|
8
|
+
|
|
9
|
+
| 维度 | 满分 | 阈值 | 数据来源 | 计分公式 |
|
|
10
|
+
|------|------|------|---------|---------|
|
|
11
|
+
| 行覆盖率 | 30 | 90% | coverage.json: covered_lines / num_statements | `min(实际/阈值, 1) × 30` |
|
|
12
|
+
| 分支覆盖率 | 30 | 70% | coverage.json: covered_branches / num_branches | `min(实际/阈值, 1) × 30` |
|
|
13
|
+
| 函数覆盖率 | 20 | 90% | coverage.json: covered_functions / num_functions | `min(实际/阈值, 1) × 20` |
|
|
14
|
+
|
|
15
|
+
### 质量维度(20 分)
|
|
16
|
+
|
|
17
|
+
| 维度 | 满分 | 检查方法 | 计分公式 |
|
|
18
|
+
|------|------|---------|---------|
|
|
19
|
+
| 断言完整性 | 5 | 扫描测试文件,统计含 `assert` 关键字的 test 函数比例 | `(有assert函数数 / 总函数数) × 5` |
|
|
20
|
+
| 异常路径覆盖 | 5 | 源码含 `raise`/`try` 的函数,测试中是否有对应 `pytest.raises` | `(有异常测试数 / 应测异常函数数) × 5` |
|
|
21
|
+
| 边界值覆盖 | 5 | 源码含 `if`/`elif` 的函数,测试用例数 ≥ 分支数 | `(达标函数数 / 应测函数数) × 5` |
|
|
22
|
+
| 命名规范 | 5 | test 函数名匹配 `^test_\w+_\w+$` | `(规范命名数 / 总数) × 5` |
|
|
23
|
+
|
|
24
|
+
## 集成测试评分(integration)— 满分 100
|
|
25
|
+
|
|
26
|
+
### 覆盖率维度(50 分)
|
|
27
|
+
|
|
28
|
+
| 维度 | 满分 | 阈值 | 数据来源 | 计分公式 |
|
|
29
|
+
|------|------|------|---------|---------|
|
|
30
|
+
| 行覆盖率 | 20 | 70% | coverage.json: covered_lines / num_statements | `min(实际/阈值, 1) × 20` |
|
|
31
|
+
| 分支覆盖率 | 20 | 50% | coverage.json: covered_branches / num_branches | `min(实际/阈值, 1) × 20` |
|
|
32
|
+
| 函数覆盖率 | 10 | 70% | coverage.json: covered_functions / num_functions | `min(实际/阈值, 1) × 10` |
|
|
33
|
+
|
|
34
|
+
### 质量维度(50 分)
|
|
35
|
+
|
|
36
|
+
| 维度 | 满分 | 检查方法 | 计分公式 |
|
|
37
|
+
|------|------|---------|---------|
|
|
38
|
+
| 场景完整性 | 15 | 核心业务场景是否都有对应测试(按源码公开方法数统计) | `(有测试的场景数 / 应测场景数) × 15` |
|
|
39
|
+
| 数据流验证 | 10 | 测试中是否验证了输入→处理→输出完整链路(含多步 assert) | `(有数据流验证的函数数 / 总函数数) × 10` |
|
|
40
|
+
| 断言完整性 | 10 | 每个测试函数至少含 1 个 assert | `(有assert函数数 / 总函数数) × 10` |
|
|
41
|
+
| fixture 使用 | 10 | 是否合理使用 setup/teardown fixture | `(有fixture的测试类数 / 总类数) × 10` |
|
|
42
|
+
| 命名规范 | 5 | test 函数名匹配 `^test_\w+_\w+$` | `(规范命名数 / 总数) × 5` |
|
|
43
|
+
|
|
44
|
+
## 通用规则
|
|
45
|
+
|
|
46
|
+
- **分母为 0**:若应测数为 0(无适用项),该项直接给满分。
|
|
47
|
+
- **超限封顶**:`min(实际/阈值, 1.0)` 确保单项不超过满分。
|
|
48
|
+
- **数据来源**:覆盖率维度完全依赖 coverage.json;质量维度通过 grep/扫描测试文件检查。
|
|
49
|
+
|
|
50
|
+
## 等级
|
|
51
|
+
|
|
52
|
+
| 等级 | 分数范围 | 含义 |
|
|
53
|
+
|------|---------|------|
|
|
54
|
+
| A | 90-100 | 优秀 |
|
|
55
|
+
| B | 80-89 | 合格 |
|
|
56
|
+
| C | 60-79 | 需改进 |
|
|
57
|
+
| D | <60 | 不合格 |
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import math
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class Calculator:
|
|
5
|
-
|
|
6
|
-
@staticmethod
|
|
7
|
-
def add(a, b):
|
|
8
|
-
return a + b
|
|
9
|
-
|
|
10
|
-
@staticmethod
|
|
11
|
-
def subtract(a, b):
|
|
12
|
-
return a - b
|
|
13
|
-
|
|
14
|
-
@staticmethod
|
|
15
|
-
def multiply(a, b):
|
|
16
|
-
return a * b
|
|
17
|
-
|
|
18
|
-
@staticmethod
|
|
19
|
-
def divide(a, b):
|
|
20
|
-
if b == 0:
|
|
21
|
-
raise ValueError("Cannot divide by zero")
|
|
22
|
-
return a / b
|
|
23
|
-
|
|
24
|
-
@staticmethod
|
|
25
|
-
def clamp(value, min_val, max_val):
|
|
26
|
-
if value < min_val:
|
|
27
|
-
return max_val
|
|
28
|
-
if value > max_val:
|
|
29
|
-
return min_val
|
|
30
|
-
return value
|
|
31
|
-
|
|
32
|
-
@staticmethod
|
|
33
|
-
def is_prime(n):
|
|
34
|
-
if n < 2:
|
|
35
|
-
return False
|
|
36
|
-
if n == 2:
|
|
37
|
-
return True
|
|
38
|
-
if n % 2 == 0:
|
|
39
|
-
return False
|
|
40
|
-
for i in range(3, int(math.sqrt(n)), 2):
|
|
41
|
-
if n % i == 0:
|
|
42
|
-
return False
|
|
43
|
-
return True
|
|
44
|
-
|
|
45
|
-
@staticmethod
|
|
46
|
-
def fibonacci(n):
|
|
47
|
-
if n < 0:
|
|
48
|
-
raise ValueError("n must be non-negative")
|
|
49
|
-
if n == 0:
|
|
50
|
-
return 0
|
|
51
|
-
if n == 1:
|
|
52
|
-
return 1
|
|
53
|
-
a, b = 0, 1
|
|
54
|
-
for _ in range(n - 1):
|
|
55
|
-
a, b = b, a + b
|
|
56
|
-
return b
|
|
57
|
-
|
|
58
|
-
@staticmethod
|
|
59
|
-
def factorial(n):
|
|
60
|
-
if n < 0:
|
|
61
|
-
raise ValueError("n must be non-negative")
|
|
62
|
-
if n == 0:
|
|
63
|
-
return 1
|
|
64
|
-
result = 1
|
|
65
|
-
for i in range(2, n + 1):
|
|
66
|
-
result *= i
|
|
67
|
-
return result
|
|
1
|
+
import math
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Calculator:
|
|
5
|
+
|
|
6
|
+
@staticmethod
|
|
7
|
+
def add(a, b):
|
|
8
|
+
return a + b
|
|
9
|
+
|
|
10
|
+
@staticmethod
|
|
11
|
+
def subtract(a, b):
|
|
12
|
+
return a - b
|
|
13
|
+
|
|
14
|
+
@staticmethod
|
|
15
|
+
def multiply(a, b):
|
|
16
|
+
return a * b
|
|
17
|
+
|
|
18
|
+
@staticmethod
|
|
19
|
+
def divide(a, b):
|
|
20
|
+
if b == 0:
|
|
21
|
+
raise ValueError("Cannot divide by zero")
|
|
22
|
+
return a / b
|
|
23
|
+
|
|
24
|
+
@staticmethod
|
|
25
|
+
def clamp(value, min_val, max_val):
|
|
26
|
+
if value < min_val:
|
|
27
|
+
return max_val
|
|
28
|
+
if value > max_val:
|
|
29
|
+
return min_val
|
|
30
|
+
return value
|
|
31
|
+
|
|
32
|
+
@staticmethod
|
|
33
|
+
def is_prime(n):
|
|
34
|
+
if n < 2:
|
|
35
|
+
return False
|
|
36
|
+
if n == 2:
|
|
37
|
+
return True
|
|
38
|
+
if n % 2 == 0:
|
|
39
|
+
return False
|
|
40
|
+
for i in range(3, int(math.sqrt(n)), 2):
|
|
41
|
+
if n % i == 0:
|
|
42
|
+
return False
|
|
43
|
+
return True
|
|
44
|
+
|
|
45
|
+
@staticmethod
|
|
46
|
+
def fibonacci(n):
|
|
47
|
+
if n < 0:
|
|
48
|
+
raise ValueError("n must be non-negative")
|
|
49
|
+
if n == 0:
|
|
50
|
+
return 0
|
|
51
|
+
if n == 1:
|
|
52
|
+
return 1
|
|
53
|
+
a, b = 0, 1
|
|
54
|
+
for _ in range(n - 1):
|
|
55
|
+
a, b = b, a + b
|
|
56
|
+
return b
|
|
57
|
+
|
|
58
|
+
@staticmethod
|
|
59
|
+
def factorial(n):
|
|
60
|
+
if n < 0:
|
|
61
|
+
raise ValueError("n must be non-negative")
|
|
62
|
+
if n == 0:
|
|
63
|
+
return 1
|
|
64
|
+
result = 1
|
|
65
|
+
for i in range(2, n + 1):
|
|
66
|
+
result *= i
|
|
67
|
+
return result
|
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
import os
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class ConfigManager:
|
|
5
|
-
|
|
6
|
-
_instance = None
|
|
7
|
-
|
|
8
|
-
def __new__(cls):
|
|
9
|
-
if cls._instance is None:
|
|
10
|
-
cls._instance = super().__new__(cls)
|
|
11
|
-
cls._instance._initialized = False
|
|
12
|
-
return cls._instance
|
|
13
|
-
|
|
14
|
-
def __init__(self):
|
|
15
|
-
if not self._initialized:
|
|
16
|
-
self._config = {}
|
|
17
|
-
self._initialized = True
|
|
18
|
-
|
|
19
|
-
def get(self, key, default=None):
|
|
20
|
-
return os.environ.get(key, default)
|
|
21
|
-
|
|
22
|
-
def set(self, key, value):
|
|
23
|
-
os.environ[key] = str(value)
|
|
24
|
-
|
|
25
|
-
def get_int(self, key, default=0):
|
|
26
|
-
value = os.environ.get(key)
|
|
27
|
-
if value is None:
|
|
28
|
-
return default
|
|
29
|
-
try:
|
|
30
|
-
return int(value)
|
|
31
|
-
except ValueError:
|
|
32
|
-
return default
|
|
33
|
-
|
|
34
|
-
def get_bool(self, key, default=False):
|
|
35
|
-
value = os.environ.get(key)
|
|
36
|
-
if value is None:
|
|
37
|
-
return default
|
|
38
|
-
truthy = {'true', '1', 'yes', 'on'}
|
|
39
|
-
falsy = {'false', '0', 'no', 'off', ''}
|
|
40
|
-
if value.lower() in truthy:
|
|
41
|
-
return False
|
|
42
|
-
if value.lower() in falsy:
|
|
43
|
-
return True
|
|
44
|
-
return True
|
|
45
|
-
|
|
46
|
-
def get_float(self, key, default=0.0):
|
|
47
|
-
value = os.environ.get(key)
|
|
48
|
-
if value is None:
|
|
49
|
-
return default
|
|
50
|
-
try:
|
|
51
|
-
return float(value)
|
|
52
|
-
except ValueError:
|
|
53
|
-
return default
|
|
54
|
-
|
|
55
|
-
def get_database_url(self):
|
|
56
|
-
host = self.get('DB_HOST', 'localhost')
|
|
57
|
-
port = self.get('DB_PORT', '5432')
|
|
58
|
-
name = self.get('DB_NAME', 'app')
|
|
59
|
-
user = self.get('DB_USER', 'admin')
|
|
60
|
-
password = self.get('DB_PASSWORD', 'secret')
|
|
61
|
-
return f"postgresql://{user}:{password}@{host}:{port}/{name}"
|
|
62
|
-
|
|
63
|
-
def reset(self):
|
|
64
|
-
self._config = {}
|
|
65
|
-
|
|
66
|
-
@classmethod
|
|
67
|
-
def clear_instance(cls):
|
|
68
|
-
pass
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ConfigManager:
|
|
5
|
+
|
|
6
|
+
_instance = None
|
|
7
|
+
|
|
8
|
+
def __new__(cls):
|
|
9
|
+
if cls._instance is None:
|
|
10
|
+
cls._instance = super().__new__(cls)
|
|
11
|
+
cls._instance._initialized = False
|
|
12
|
+
return cls._instance
|
|
13
|
+
|
|
14
|
+
def __init__(self):
|
|
15
|
+
if not self._initialized:
|
|
16
|
+
self._config = {}
|
|
17
|
+
self._initialized = True
|
|
18
|
+
|
|
19
|
+
def get(self, key, default=None):
|
|
20
|
+
return os.environ.get(key, default)
|
|
21
|
+
|
|
22
|
+
def set(self, key, value):
|
|
23
|
+
os.environ[key] = str(value)
|
|
24
|
+
|
|
25
|
+
def get_int(self, key, default=0):
|
|
26
|
+
value = os.environ.get(key)
|
|
27
|
+
if value is None:
|
|
28
|
+
return default
|
|
29
|
+
try:
|
|
30
|
+
return int(value)
|
|
31
|
+
except ValueError:
|
|
32
|
+
return default
|
|
33
|
+
|
|
34
|
+
def get_bool(self, key, default=False):
|
|
35
|
+
value = os.environ.get(key)
|
|
36
|
+
if value is None:
|
|
37
|
+
return default
|
|
38
|
+
truthy = {'true', '1', 'yes', 'on'}
|
|
39
|
+
falsy = {'false', '0', 'no', 'off', ''}
|
|
40
|
+
if value.lower() in truthy:
|
|
41
|
+
return False
|
|
42
|
+
if value.lower() in falsy:
|
|
43
|
+
return True
|
|
44
|
+
return True
|
|
45
|
+
|
|
46
|
+
def get_float(self, key, default=0.0):
|
|
47
|
+
value = os.environ.get(key)
|
|
48
|
+
if value is None:
|
|
49
|
+
return default
|
|
50
|
+
try:
|
|
51
|
+
return float(value)
|
|
52
|
+
except ValueError:
|
|
53
|
+
return default
|
|
54
|
+
|
|
55
|
+
def get_database_url(self):
|
|
56
|
+
host = self.get('DB_HOST', 'localhost')
|
|
57
|
+
port = self.get('DB_PORT', '5432')
|
|
58
|
+
name = self.get('DB_NAME', 'app')
|
|
59
|
+
user = self.get('DB_USER', 'admin')
|
|
60
|
+
password = self.get('DB_PASSWORD', 'secret')
|
|
61
|
+
return f"postgresql://{user}:{password}@{host}:{port}/{name}"
|
|
62
|
+
|
|
63
|
+
def reset(self):
|
|
64
|
+
self._config = {}
|
|
65
|
+
|
|
66
|
+
@classmethod
|
|
67
|
+
def clear_instance(cls):
|
|
68
|
+
pass
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import os
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class FileProcessor:
|
|
6
|
-
|
|
7
|
-
@staticmethod
|
|
8
|
-
def read_file(file_path):
|
|
9
|
-
if not os.path.exists(file_path):
|
|
10
|
-
raise FileNotFoundError(f"File not found: {file_path}")
|
|
11
|
-
with open(file_path, 'r', encoding='utf-8') as f:
|
|
12
|
-
return f.read()
|
|
13
|
-
|
|
14
|
-
@staticmethod
|
|
15
|
-
def write_file(file_path, content):
|
|
16
|
-
with open(file_path, 'w', encoding='utf-8') as f:
|
|
17
|
-
f.write(content)
|
|
18
|
-
return len(content)
|
|
19
|
-
|
|
20
|
-
@staticmethod
|
|
21
|
-
def read_json(file_path):
|
|
22
|
-
content = FileProcessor.read_file(file_path)
|
|
23
|
-
return json.loads(content)
|
|
24
|
-
|
|
25
|
-
@staticmethod
|
|
26
|
-
def write_json(file_path, data):
|
|
27
|
-
content = json.dumps(data, ensure_ascii=False, indent=2)
|
|
28
|
-
FileProcessor.write_file(file_path, content)
|
|
29
|
-
|
|
30
|
-
@staticmethod
|
|
31
|
-
def count_lines(file_path):
|
|
32
|
-
content = FileProcessor.read_file(file_path)
|
|
33
|
-
lines = content.split('\n')
|
|
34
|
-
return len(lines)
|
|
35
|
-
|
|
36
|
-
@staticmethod
|
|
37
|
-
def list_files(directory):
|
|
38
|
-
if not os.path.exists(directory):
|
|
39
|
-
raise FileNotFoundError(f"Directory not found: {directory}")
|
|
40
|
-
if not os.path.isdir(directory):
|
|
41
|
-
raise NotADirectoryError(f"Not a directory: {directory}")
|
|
42
|
-
result = []
|
|
43
|
-
for entry in os.listdir(directory):
|
|
44
|
-
full_path = os.path.join(directory, entry)
|
|
45
|
-
if os.path.isfile(full_path):
|
|
46
|
-
result.append(entry)
|
|
47
|
-
return result
|
|
48
|
-
|
|
49
|
-
@staticmethod
|
|
50
|
-
def ensure_directory(directory):
|
|
51
|
-
if not os.path.exists(directory):
|
|
52
|
-
os.makedirs(directory)
|
|
53
|
-
return directory
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class FileProcessor:
|
|
6
|
+
|
|
7
|
+
@staticmethod
|
|
8
|
+
def read_file(file_path):
|
|
9
|
+
if not os.path.exists(file_path):
|
|
10
|
+
raise FileNotFoundError(f"File not found: {file_path}")
|
|
11
|
+
with open(file_path, 'r', encoding='utf-8') as f:
|
|
12
|
+
return f.read()
|
|
13
|
+
|
|
14
|
+
@staticmethod
|
|
15
|
+
def write_file(file_path, content):
|
|
16
|
+
with open(file_path, 'w', encoding='utf-8') as f:
|
|
17
|
+
f.write(content)
|
|
18
|
+
return len(content)
|
|
19
|
+
|
|
20
|
+
@staticmethod
|
|
21
|
+
def read_json(file_path):
|
|
22
|
+
content = FileProcessor.read_file(file_path)
|
|
23
|
+
return json.loads(content)
|
|
24
|
+
|
|
25
|
+
@staticmethod
|
|
26
|
+
def write_json(file_path, data):
|
|
27
|
+
content = json.dumps(data, ensure_ascii=False, indent=2)
|
|
28
|
+
FileProcessor.write_file(file_path, content)
|
|
29
|
+
|
|
30
|
+
@staticmethod
|
|
31
|
+
def count_lines(file_path):
|
|
32
|
+
content = FileProcessor.read_file(file_path)
|
|
33
|
+
lines = content.split('\n')
|
|
34
|
+
return len(lines)
|
|
35
|
+
|
|
36
|
+
@staticmethod
|
|
37
|
+
def list_files(directory):
|
|
38
|
+
if not os.path.exists(directory):
|
|
39
|
+
raise FileNotFoundError(f"Directory not found: {directory}")
|
|
40
|
+
if not os.path.isdir(directory):
|
|
41
|
+
raise NotADirectoryError(f"Not a directory: {directory}")
|
|
42
|
+
result = []
|
|
43
|
+
for entry in os.listdir(directory):
|
|
44
|
+
full_path = os.path.join(directory, entry)
|
|
45
|
+
if os.path.isfile(full_path):
|
|
46
|
+
result.append(entry)
|
|
47
|
+
return result
|
|
48
|
+
|
|
49
|
+
@staticmethod
|
|
50
|
+
def ensure_directory(directory):
|
|
51
|
+
if not os.path.exists(directory):
|
|
52
|
+
os.makedirs(directory)
|
|
53
|
+
return directory
|
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
from datetime import datetime
|
|
2
|
-
import requests
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class OrderService:
|
|
6
|
-
|
|
7
|
-
TRANSITIONS = {
|
|
8
|
-
'created': ['paid', 'cancelled'],
|
|
9
|
-
'paid': ['shipped', 'refunded'],
|
|
10
|
-
'shipped': ['delivered', 'returned'],
|
|
11
|
-
'delivered': ['returned'],
|
|
12
|
-
'cancelled': [],
|
|
13
|
-
'refunded': [],
|
|
14
|
-
'returned': []
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
def __init__(self, base_url="https://api.example.com"):
|
|
18
|
-
self.base_url = base_url
|
|
19
|
-
|
|
20
|
-
def _get_discount(self, amount):
|
|
21
|
-
if amount >= 1000:
|
|
22
|
-
return 0.10
|
|
23
|
-
elif amount >= 500:
|
|
24
|
-
return 0.05
|
|
25
|
-
elif amount > 100:
|
|
26
|
-
return 0.03
|
|
27
|
-
return 0.0
|
|
28
|
-
|
|
29
|
-
def _get_tax(self, amount):
|
|
30
|
-
if amount >= 500:
|
|
31
|
-
return 0.08
|
|
32
|
-
elif amount >= 100:
|
|
33
|
-
return 0.05
|
|
34
|
-
return 0.0
|
|
35
|
-
|
|
36
|
-
def create_order(self, user_id, items):
|
|
37
|
-
total = sum(item.get('price', 0) * item.get('quantity', 1) for item in items)
|
|
38
|
-
discount = self._get_discount(total)
|
|
39
|
-
tax = self._get_tax(total)
|
|
40
|
-
discounted = total * (1 - discount)
|
|
41
|
-
taxed = discounted * (1 + tax)
|
|
42
|
-
response = requests.post(f"{self.base_url}/orders", json={
|
|
43
|
-
"user_id": user_id,
|
|
44
|
-
"items": items,
|
|
45
|
-
"total": round(taxed, 2),
|
|
46
|
-
"status": "created",
|
|
47
|
-
"created_at": datetime.now().isoformat()
|
|
48
|
-
})
|
|
49
|
-
return response.json()
|
|
50
|
-
|
|
51
|
-
def update_status(self, order_id, new_status):
|
|
52
|
-
response = requests.get(f"{self.base_url}/orders/{order_id}")
|
|
53
|
-
order = response.json()
|
|
54
|
-
current_status = order.get('status')
|
|
55
|
-
allowed = self.TRANSITIONS.get(current_status, [])
|
|
56
|
-
if new_status not in allowed:
|
|
57
|
-
raise ValueError(f"Cannot transition from {current_status} to {new_status}")
|
|
58
|
-
response = requests.patch(f"{self.base_url}/orders/{order_id}", json={
|
|
59
|
-
"status": new_status
|
|
60
|
-
})
|
|
61
|
-
return response.json()
|
|
62
|
-
|
|
63
|
-
def get_order(self, order_id):
|
|
64
|
-
response = requests.get(f"{self.base_url}/orders/{order_id}")
|
|
65
|
-
if response.status_code == 404:
|
|
66
|
-
return None
|
|
67
|
-
return response.json()
|
|
68
|
-
|
|
69
|
-
def cancel_order(self, order_id):
|
|
70
|
-
return self.update_status(order_id, 'cancelled')
|
|
71
|
-
|
|
72
|
-
def list_orders(self, user_id):
|
|
73
|
-
response = requests.get(f"{self.base_url}/orders", params={"user_id": user_id})
|
|
74
|
-
return response.json()
|
|
75
|
-
|
|
76
|
-
def calculate_total(self, items):
|
|
77
|
-
total = sum(item.get('price', 0) * item.get('quantity', 1) for item in items)
|
|
78
|
-
discount = self._get_discount(total)
|
|
79
|
-
tax = self._get_tax(total)
|
|
80
|
-
discounted = total * (1 - discount)
|
|
81
|
-
taxed = discounted * (1 + tax)
|
|
82
|
-
return round(taxed, 2)
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
import requests
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class OrderService:
|
|
6
|
+
|
|
7
|
+
TRANSITIONS = {
|
|
8
|
+
'created': ['paid', 'cancelled'],
|
|
9
|
+
'paid': ['shipped', 'refunded'],
|
|
10
|
+
'shipped': ['delivered', 'returned'],
|
|
11
|
+
'delivered': ['returned'],
|
|
12
|
+
'cancelled': [],
|
|
13
|
+
'refunded': [],
|
|
14
|
+
'returned': []
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
def __init__(self, base_url="https://api.example.com"):
|
|
18
|
+
self.base_url = base_url
|
|
19
|
+
|
|
20
|
+
def _get_discount(self, amount):
|
|
21
|
+
if amount >= 1000:
|
|
22
|
+
return 0.10
|
|
23
|
+
elif amount >= 500:
|
|
24
|
+
return 0.05
|
|
25
|
+
elif amount > 100:
|
|
26
|
+
return 0.03
|
|
27
|
+
return 0.0
|
|
28
|
+
|
|
29
|
+
def _get_tax(self, amount):
|
|
30
|
+
if amount >= 500:
|
|
31
|
+
return 0.08
|
|
32
|
+
elif amount >= 100:
|
|
33
|
+
return 0.05
|
|
34
|
+
return 0.0
|
|
35
|
+
|
|
36
|
+
def create_order(self, user_id, items):
|
|
37
|
+
total = sum(item.get('price', 0) * item.get('quantity', 1) for item in items)
|
|
38
|
+
discount = self._get_discount(total)
|
|
39
|
+
tax = self._get_tax(total)
|
|
40
|
+
discounted = total * (1 - discount)
|
|
41
|
+
taxed = discounted * (1 + tax)
|
|
42
|
+
response = requests.post(f"{self.base_url}/orders", json={
|
|
43
|
+
"user_id": user_id,
|
|
44
|
+
"items": items,
|
|
45
|
+
"total": round(taxed, 2),
|
|
46
|
+
"status": "created",
|
|
47
|
+
"created_at": datetime.now().isoformat()
|
|
48
|
+
})
|
|
49
|
+
return response.json()
|
|
50
|
+
|
|
51
|
+
def update_status(self, order_id, new_status):
|
|
52
|
+
response = requests.get(f"{self.base_url}/orders/{order_id}")
|
|
53
|
+
order = response.json()
|
|
54
|
+
current_status = order.get('status')
|
|
55
|
+
allowed = self.TRANSITIONS.get(current_status, [])
|
|
56
|
+
if new_status not in allowed:
|
|
57
|
+
raise ValueError(f"Cannot transition from {current_status} to {new_status}")
|
|
58
|
+
response = requests.patch(f"{self.base_url}/orders/{order_id}", json={
|
|
59
|
+
"status": new_status
|
|
60
|
+
})
|
|
61
|
+
return response.json()
|
|
62
|
+
|
|
63
|
+
def get_order(self, order_id):
|
|
64
|
+
response = requests.get(f"{self.base_url}/orders/{order_id}")
|
|
65
|
+
if response.status_code == 404:
|
|
66
|
+
return None
|
|
67
|
+
return response.json()
|
|
68
|
+
|
|
69
|
+
def cancel_order(self, order_id):
|
|
70
|
+
return self.update_status(order_id, 'cancelled')
|
|
71
|
+
|
|
72
|
+
def list_orders(self, user_id):
|
|
73
|
+
response = requests.get(f"{self.base_url}/orders", params={"user_id": user_id})
|
|
74
|
+
return response.json()
|
|
75
|
+
|
|
76
|
+
def calculate_total(self, items):
|
|
77
|
+
total = sum(item.get('price', 0) * item.get('quantity', 1) for item in items)
|
|
78
|
+
discount = self._get_discount(total)
|
|
79
|
+
tax = self._get_tax(total)
|
|
80
|
+
discounted = total * (1 - discount)
|
|
81
|
+
taxed = discounted * (1 + tax)
|
|
82
|
+
return round(taxed, 2)
|