为 Euler 项目进行单元测试 [英] Making unit tests for project Euler

查看:20
本文介绍了为 Euler 项目进行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始研究 Euler 项目中的问题,我想用 TDD 风格来解决它,但我无法找到不包含代码的问题的数字答案.是否有包含这些数据的任何资源,以便我可以制作测试用例来告诉我是否正确解决了问题?

I'm starting to go through the questions in project Euler, and I'd like to approach it with a TDD style, but I'm having trouble finding the numeric answer to the question that doesn't include the code. Is there any resource with that data so that I can make test cases that will tell me if I've solved the problem correctly?

我这样做的动机是我觉得算法是答案,而不是数字.如果我查看其他人的代码示例,就会破坏如何解决问题的挑战.

My motivation for this is that I feel like the algorithm is the answer, not the number. If I look at someone else's code sample, it ruins the challenge of figuring out how to solve the problem.

我正在专门寻找没有上下文或算法的答案的数量,以便我可以执行以下操作.我知道它更冗长,但我希望能够有一个通过/失败结果来告诉我我的算法是否正确,而不是查看其他人的代码示例来知道我是否正确完成了它.

I'm looking specifically for the number of the answer with no context or algorithm with it so that I can do something like the following. I know it's more verbose, but I'd like to be able to have a pass/fail result to tell me whether or not my algorithm is correct, rather than looking at someone else's code example to know whether I've done it correctly.

import unittest
class ProblemOneTest(unittest.TestCase):
    def test_me(self):
        self.assertEquals(solve_problem_one(),233168)

if __name__ == '__main__':
    print "Problem 1 possible answer: %d" % solve_problem_one()
    sys.exit(unittest.main())

推荐答案

项目 Euler 网站上的问题页面有一个输入来检查您的答案.这就是我真正需要的.

The problem page on the project Euler website has an input to check your answer. That's all I really need.

这篇关于为 Euler 项目进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆