如何使用doctest测试浮点结果? [英] How to test floats results with doctest?

查看:50
本文介绍了如何使用doctest测试浮点结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个程序,该程序可以进行一些浮点计算.有什么方法可以用doctests测试我的函数(传递浮点数)吗?

I'm developing a program that makes some floating points calculations. Is there any way to test my functions (which deliver floats) with doctests?

推荐答案

当然,请根据对浮点数显示精度的了解,以合理的格式对浮点数进行格式化-例如,如果期望精度为2小数点后的数字,您可以使用:

Sure, just format the floats with a reasonable format, based on your knowledge of what precision you expect them to exhibit -- e.g, if you expect accuracy to 2 digits after the decimal point, you could use:

''' Rest of your docstring and then...

    >>> '%.2f' % funcreturningfloat()
    '123.45'

'''

这篇关于如何使用doctest测试浮点结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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