Skip to content

Commit 427a433

Browse files
Rafael-SOWNetclaude
andcommitted
Check the C++ integral tests by differentiating, not by string
IntTest1 and IntTest2 compared Integrate's printed form against the literals "x2 / 2" and "x2 / 2 + 2x". Neither says what it looks like: "x2" parses as a variable of that name, not as a square. And neither survives Integrate gaining its constant of integration, which is why these two were the only failures of the twenty-four once the bindings were built against the current source instead of a 1.4.0-preview.2 package. The printed form was never the property under test. Both now differentiate the antiderivative and check the difference from the integrand simplifies to zero, which is what the rest of the suite does and what AGENTS.md asks for. That the form was the problem rather than the mathematics is visible in the second case: d/dx of the antiderivative of x + 2 prints as 2 + x, so even a corrected string would have been comparing arrangements rather than values. Measured: d/dx(x ^ 2 / 2 + C) is x, d/dx(x ^ 2 / 2 + 2 * x + C) is 2 + x, and both differences simplify to 0. cmake is not available here, so CTest on CI is the check. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 5ba0843 commit 427a433

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

Sources/Tests/CPPWrapperUnitTests/tests/RunTests.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <AngouriMath.h>
22
#include <gtest/gtest.h>
33
#include <vector>
4+
#include <string>
45

56
TEST(RunTests, ParsingTest1) {
67
auto src = "x / 2 + 3";
@@ -54,20 +55,25 @@ TEST(RunTests, DiffTest2) {
5455
EXPECT_EQ(expected.ToString(), actual.ToString());
5556
}
5657

58+
// An antiderivative is checked by differentiating it back, not by comparing its printed
59+
// form. These two compared against the literals "x2 / 2" and "x2 / 2 + 2x", which do not
60+
// say what they look like -- "x2" parses as a variable of that name rather than as a
61+
// square -- and which could not survive Integrate gaining its constant of integration.
62+
// The printed form is not the property under test: d/dx of the answer is.
63+
static void ExpectAntiderivative(const char* integrand) {
64+
AngouriMath::Entity entity = integrand;
65+
auto back = entity.Integrate("x").Differentiate("x");
66+
auto difference = AngouriMath::Entity(
67+
"(" + back.ToString() + ") - (" + std::string(integrand) + ")");
68+
EXPECT_EQ("0", difference.Simplify().ToString());
69+
}
70+
5771
TEST(RunTests, IntTest1) {
58-
auto src = "x";
59-
AngouriMath::Entity entity = src;
60-
auto actual = entity.Integrate("x");
61-
auto expected = AngouriMath::Entity("x2 / 2");
62-
EXPECT_EQ(expected.ToString(), actual.ToString());
72+
ExpectAntiderivative("x");
6373
}
6474

6575
TEST(RunTests, IntTest2) {
66-
auto src = "x + 2";
67-
AngouriMath::Entity entity = src;
68-
auto actual = entity.Integrate("x");
69-
auto expected = AngouriMath::Entity("x2 / 2 + 2x");
70-
EXPECT_EQ(expected.ToString(), actual.ToString());
76+
ExpectAntiderivative("x + 2");
7177
}
7278

7379
TEST(RunTests, LimTest1) {

0 commit comments

Comments
 (0)