简体   繁体   English

如何测试特殊多项式的正确实现?

[英]How to test the correct implementation of special polynomials?

I need to implement the calculation of some special polynomials in Java (the language is not really important).我需要在Java中实现一些特殊多项式的计算(语言不是很重要)。 These are calculated as a weighted sum of a number of base polynomials with fixed coefficients.这些计算为多个具有固定系数的基本多项式的加权和。

Each base polynomial has 2 to 10 coefficients and there are typically 10 base polynomials considered, giving a total of, say 20-50 coefficients.每个基本多项式有 2 到 10 个系数,通常考虑 10 个基本多项式,总共有 20-50 个系数。

Basically the calculation is no big deal but I am worried about typos.基本上计算没什么大不了的,但我担心错别字。 I only have a printed document as a template.我只有一个打印文档作为模板。 So i would like to implement unit tests for the calculations.所以我想为计算实施单元测试。 The issue is: How do I get reliable testing data.问题是:我如何获得可靠的测试数据。 I do have another software that is supposed to calculate these functions but the process is complicated and also error prone - I would have to scale the input values, go through a number of menu selections in the software to produce the output and then paste it to my testing code.我确实有另一个应该计算这些函数的软件,但这个过程很复杂,而且容易出错——我必须缩放输入值,通过软件中的一些菜单选择来生成输出,然后将其粘贴到我的测试代码。

I guess that there is no way around using the external software to generate some testing data, but maybe you have some recommendations for making this type of testing procedure safer or minimize the required number of test cases .我想没有办法使用外部软件来生成一些测试数据,但也许您有一些建议可以使这种类型的测试过程更安全或最小化所需的测试用例数量

I am also worried about providing suitable input values: Depending on the value of the independent variable, certain terms will only have a tiny contribution to the output, while for other values they might dominate.我还担心提供合适的输入值:根据自变量的值,某些项对输出的贡献很小,而对于其他值,它们可能占主导地位。

The types of errors I expect (and need to avoid) are:我期望(并且需要避免)的错误类型是:

  • Typos in coefficients系数中的错别字
  • Coefficients applied to wrong power (ie a_7*x^6 instead of a_7*x^7 - just for demonstration, I am not calculating this way but am using Horner's scheme)应用于错误功率的系数(即a_7*x^6而不是a_7*x^7 - 只是为了演示,我不是这样计算而是使用霍纳的方案)
  • Off-by one errors (ie missing zero order or highest order term)错一错误(即缺少零阶或最高阶项)

Since you have a polynomial of degree 10, testing at 11 distinct points should give certainty.由于您有一个 10 次多项式,因此在 11 个不同的点上进行测试应该可以确定。

However, already a test at one well-randomized point, x=1.23004 to give an idea (away from small fractions like 2/3, 4/5), will with high probability show a difference if there is an error, because it is unlikely that the difference between the wrong and the true polynomial has a root at exactly this place.然而,已经在一个随机化的点x=1.23004进行了测试以给出一个想法(远离像 2/ x=1.23004 /5 这样的小分数),如果有错误,很可能会显示差异,因为它是错误多项式和真实多项式之间的差异不太可能在这个地方有根。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM