From 2b2d1a651a670f92b4c328beae6531eb5779ca37 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 19 Feb 2026 09:28:16 +0000 Subject: [PATCH] test(cas): add tests for Cas.evaluate Added comprehensive tests for Cas.evaluate covering: - Differentiation commands (d/dx) - Integration commands (int) - Simplification - Equation handling - Error cases This ensures that the command parsing logic for CAS operations is verified and regressions can be detected. Co-authored-by: smjxpro <9335473+smjxpro@users.noreply.github.com> --- test/cas_test.dart | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 test/cas_test.dart diff --git a/test/cas_test.dart b/test/cas_test.dart new file mode 100644 index 0000000..99da96e --- /dev/null +++ b/test/cas_test.dart @@ -0,0 +1,63 @@ +import 'package:functionx/src/cas/cas.dart'; +import 'package:test/test.dart'; + +void main() { + group('Cas', () { + group('evaluate', () { + test('differentiates single variable: d/dx(x^2)', () { + // math_expressions derivative logic produces this unsimplified form + expect(Cas.evaluate('d/dx(x^2)'), equals('((x^2.0) * (2.0 * (1.0 / x)))')); + }); + + test('differentiates trig function: d/dx(sin(x))', () { + // sin(x) derives to cos(x) * 1, which simplifies to cos(x) + expect(Cas.evaluate('d/dx(sin(x))'), equals('cos(x)')); + }); + + test('differentiates constant: d/dx(5)', () { + expect(Cas.evaluate('d/dx(5)'), equals('0.0')); + }); + + test('differentiates with different variable: d/dt(t^2)', () { + expect(Cas.evaluate('d/dt(t^2)'), equals('((t^2.0) * (2.0 * (1.0 / t)))')); + }); + + test('integrates variable: int(x)dx', () { + expect(Cas.evaluate('int(x)dx'), equals('0.5*x^2')); + }); + + test('integrates variable (implicit dx): int(x)', () { + expect(Cas.evaluate('int(x)'), equals('0.5*x^2')); + }); + + test('integrates trig function: int(cos(x))dx', () { + expect(Cas.evaluate('int(cos(x))dx'), equals('sin(x)')); + }); + + test('integrates constant: int(5)dx', () { + expect(Cas.evaluate('int(5)dx'), equals('5.0*x')); + }); + + test('simplifies expression: x + x', () { + // simplification logic does not combine like terms in this version + expect(Cas.evaluate('x + x'), equals('(x + x)')); + }); + + test('evaluates equation: d/dx(x^2) = 2*x', () { + expect(Cas.evaluate('d/dx(x^2) = 2*x'), equals('((x^2.0) * (2.0 * (1.0 / x))) = (2.0 * x)')); + }); + + test('throws on invalid derivative format', () { + expect(() => Cas.evaluate('d/dx'), throwsFormatException); + }); + + test('throws on invalid integral format', () { + expect(() => Cas.evaluate('int(x'), throwsFormatException); + }); + + test('throws on unsupported integration', () { + expect(() => Cas.evaluate('int(tan(x))dx'), throwsFormatException); + }); + }); + }); +}