gpt4 book ai didi

python - Codewars Python TDD 离线

转载 作者:太空宇宙 更新时间:2023-11-04 05:18:53 24 4
gpt4 key购买 nike

我想使用我熟悉的开发环境离线执行 Codewars Python 套路。然而,所提供的测试使用与 Python 的 Unittest 完全不同的语法。我在任何地方都找不到测试框架的源代码。

我试过 codewars-client npm 包 ( https://github.com/shime/codewars ) 但它让我很困惑。我还查看了 codewars-cli runner,但它看起来更难理解,并且涉及 Docker。

这很令人沮丧,因为我真的只想练习一些基本的编码,但我最终不得不尝试理解 json 和依赖项以及包管理,只是为了启动和运行基本的 TDD 环境。

任何人都可以建议如何简单地在本地使用 python katas 中提供的测试吗?示例如下:

test.describe("Basic tests")
test.it("A resistor under 1000 ohms and with only three bands")
test.assert_equals(decode_resistor_colors("yellow violet black"), "47 ohms, 20%")
test.it("A resistor between 1000 and 999999 ohms, with a gold fourth band")
test.assert_equals(decode_resistor_colors("yellow violet red gold"), "4.7k ohms, 5%")
test.it("A resistor of 1000000 ohms or above, with a silver fourth band")
test.assert_equals(decode_resistor_colors("brown black green silver"), "1M ohms, 10%")

最佳答案

我只是将测试用例转换为代码中的打印语句,然后注释掉其余部分。然后直观地比较答案。

见下文:

# test.describe("Basic tests")
# test.it("A resistor under 1000 ohms and with only three bands")
print(decode_resistor_colors("yellow violet black")) # "47 ohms, 20%"

# test.it("A resistor between 1000 and 999999 ohms, with a gold fourth band")
print(decode_resistor_colors("yellow violet red gold")) # "4.7k ohms, 5%"

# test.it("A resistor of 1000000 ohms or above, with a silver fourth band")
print(decode_resistor_colors("brown black green silver")) # "1M ohms, 10%"

关于python - Codewars Python TDD 离线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40996317/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com