在以下测试中,
TestParticleForce
成功,但TestParticlePotentialEnergy
失败,即使它们都使用相同的精度。
据我了解,
EXPECT_NEAR(-0.00011127498, force, 0.00001);
意味着测试框架应该只考虑小数点后五位数字。那是对的吗?如果是的话,为什么会失败?
如何使用通用公差测试我的测试值?
Message:
Message:
The difference between 29.9625 and kinetic is 0.0015000000000000568, which exceeds 0.00001, where
29.9625 evaluates to 29.962499999999999,
kinetic evaluates to 29.960999999999999, and
0.00001 evaluates to 1.0000000000000001e-05.
测试粒子.cpp
#include "pch.h"
#include "header.h"
TEST(TestParticle, TestParticleForce)
{
Particle particle(1, Constants::ATOMIC_MASS,
Constants::EPSILON, Constants::SIGMA,
Constants::KB, Vec3(1, 1, 1),
Vec3(1, 1, 1));
Particle other(1, Constants::ATOMIC_MASS,
Constants::EPSILON, Constants::SIGMA,
Constants::KB, Vec3(0, 0, 0),
Vec3(1, 1, 1));
Vec3 force = particle.getForce(other);
EXPECT_NEAR(-0.00044463402, force.x, 0.00001);
EXPECT_NEAR(-0.00044463402, force.y, 0.00001);
EXPECT_NEAR(-0.00044463402, force.z, 0.00001);
}
TEST(TestParticle, TestParticlePotentialEnergy)
{
Particle particle(1, Constants::ATOMIC_MASS,
Constants::EPSILON, Constants::SIGMA,
Constants::KB, Vec3(1, 1, 1), Vec3(1, 1, 1));
Particle other(1, Constants::ATOMIC_MASS,
Constants::EPSILON, Constants::SIGMA,
Constants::KB, Vec3(0, 0, 0), Vec3(1, 1, 1));
real force = particle.getPotentialEnergy(other);
EXPECT_NEAR(-0.00011127498, force, 0.00001);
}
这意味着它只接受指定范围内的值
[-0.00011127498 - 0.00001,-0.00011127498 + 0.00001]
。
和 -0.00022251079577138472 < -0.00012127498. If the results are correct, consider using a larger tolerance.