Skip to content

feat(euler): add p0,1,2 tests and solns - #51

Merged
dchou1618 merged 1 commit into
masterfrom
feature/squares
Jul 16, 2026
Merged

dchou1618 merged 1 commit into
masterfrom
feature/squares

Conversation

@dchou1618

Copy link
Copy Markdown
Owner

No description provided.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Add Euler p0–p2 solution modules with initial pytest coverage

✨ Enhancement 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Add three Project Euler-style solution functions (p0–p2) under numerical_methods/euler.
• Introduce pytest files for p0–p2 exercising the new solution functions.
• Add basic input validation for edge cases (n < 1) in p0 and p2.
Diagram

graph TD
  A["Pytest runner"] --> B["tests/euler/p0_test.py"] --> C["Algorithms/.../euler/p0.py"]
  A --> D["tests/euler/p1_test.py"] --> E["Algorithms/.../euler/p1.py"]
  A --> F["tests/euler/p2_test.py"] --> G["Algorithms/.../euler/p2.py"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Use closed-form math for p1 (and optionally p0)
  • ➕ O(1) runtime instead of O(n) loops
  • ➕ Removes potential performance concerns for large inputs
  • ➖ More error-prone and less readable for beginners
  • ➖ Requires careful handling of inclusion/exclusion and integer division edge cases
2. Upgrade tests to assertions + parametrization
  • ➕ Turns p1/p2 from “smoke prints” into real regression tests
  • ➕ Easier to extend with multiple known-answer cases
  • ➖ Slightly more test code to maintain
  • ➖ Requires choosing canonical expected values (e.g., known Euler answers)

Recommendation: Keep the simple iterative implementations for clarity unless performance is a stated goal, but convert the p1/p2 tests from print(...) to assert ... == expected (ideally parameterized) so CI can actually catch regressions. If these utilities are intended to handle very large n, consider a closed-form implementation for p1 (sum of multiples of 3/5) and potentially p0.

Files changed (6) +48 / -0

Enhancement (3) +34 / -0
p0.pyAdd odd-square summation helper (sum_squares) +9/-0

Add odd-square summation helper (sum_squares)

• Introduces 'sum_squares(n)' which iterates 1..n and accumulates only odd squares. Raises 'ValueError' when 'n < 1'.

Algorithms/numerical_methods/euler/p0.py

p1.pyAdd multiples-of-3-or-5 summation (mult_35) +8/-0

Add multiples-of-3-or-5 summation (mult_35)

• Introduces 'mult_35(n)' which sums all positive integers less than 'n' divisible by 3 or 5 using a simple while loop.

Algorithms/numerical_methods/euler/p1.py

p2.pyAdd even Fibonacci sum up to limit (even_fib) +17/-0

Add even Fibonacci sum up to limit (even_fib)

• Introduces 'even_fib(n)' to generate Fibonacci numbers up to 'n' and sum the even-valued terms. Includes input validation for 'n < 1' and a special case for 'n == 1'.

Algorithms/numerical_methods/euler/p2.py

Tests (3) +14 / -0
p0_test.pyAdd assertion-based test for sum_squares +4/-0

Add assertion-based test for sum_squares

• Adds a pytest that imports 'sum_squares' and asserts a single large-n expected result.

tests/euler/p0_test.py

p1_test.pyAdd smoke test for mult_35 (prints output) +5/-0

Add smoke test for mult_35 (prints output)

• Adds a pytest that imports 'mult_35' but currently prints the result rather than asserting an expected value.

tests/euler/p1_test.py

p2_test.pyAdd smoke test for even_fib (prints output) +5/-0

Add smoke test for even_fib (prints output)

• Adds a pytest that imports 'even_fib' but currently prints the result rather than asserting an expected value.

tests/euler/p2_test.py

@dchou1618
dchou1618 merged commit 5a5a44a into master Jul 16, 2026
5 checks passed
@dchou1618
dchou1618 deleted the feature/squares branch July 16, 2026 03:34
@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (3) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Misleading function contract 🐞 Bug ⚙ Maintainability
Description
Algorithms/numerical_methods/euler/p0.py sum_squares() only adds squares when v % 2 != 0, so it
computes the sum of odd squares (not the sum of all squares). The function name and error message
suggest a different contract, making future usage error-prone.
Code

Algorithms/numerical_methods/euler/p0.py[R1-8]

+def sum_squares(n: int):
+    if n < 1:
+        raise ValueError("n must be specified for first n sum squares")
+    s = 0
+    for i in range(1, n+1):
+        v = i*i
+        if v % 2 != 0:
+            s += v
Relevance

⭐⭐ Medium

No direct history; similar “rename misleading parameter” readability suggestion was rejected in PR
#20.

PR-#20

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The implementation explicitly filters on square parity, and the added test asserts a value
consistent with summing only odd squares, not all squares—indicating a mismatch between name/message
and actual behavior.

Algorithms/numerical_methods/euler/p0.py[1-9]
tests/euler/p0_test.py[1-4]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`sum_squares()` filters out even squares, but its name/error message imply it sums all squares.

## Issue Context
The current test value aligns with summing odd squares up to `n`, so the implementation may be intentional; the API contract should match the behavior.

## Fix Focus Areas
- Algorithms/numerical_methods/euler/p0.py[1-8]
- tests/euler/p0_test.py[1-4]

## Suggested change
Choose one:
1) If the intention is **odd squares**: rename to something like `sum_odd_squares` and update the ValueError message accordingly.
2) If the intention is **all squares**: remove the odd-only filter (`if v % 2 != 0:`) and update the test expected value to match the full sum of squares.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

2. Missing EOF newline 🐞 Bug ⚙ Maintainability
Description
Several newly added files are missing a trailing newline at end-of-file, which creates persistent
diff noise and may violate repo formatting expectations.
Code

Algorithms/numerical_methods/euler/p0.py[R1-9]

+def sum_squares(n: int):
+    if n < 1:
+        raise ValueError("n must be specified for first n sum squares")
+    s = 0
+    for i in range(1, n+1):
+        v = i*i
+        if v % 2 != 0:
+            s += v
+    return s
Relevance

⭐⭐⭐ High

EOF newline fixes have been accepted recently to avoid diff noise (PR #49).

PR-#49

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The PR diff explicitly marks several files with No newline at end of file, and the same formatting
issue was previously addressed in this repo.

Algorithms/numerical_methods/euler/p0.py[1-9]
Algorithms/numerical_methods/euler/p1.py[1-8]
tests/euler/p0_test.py[1-4]
tests/euler/p1_test.py[1-5]
tests/euler/p2_test.py[1-5]
PR-#49

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Multiple new files were committed without a trailing newline at EOF.

## Issue Context
The repo has previously accepted a fix specifically to add a trailing newline to avoid this recurring diff/formatting issue.

## Fix Focus Areas
- Algorithms/numerical_methods/euler/p0.py[1-9]
- Algorithms/numerical_methods/euler/p1.py[1-8]
- tests/euler/p0_test.py[1-4]
- tests/euler/p1_test.py[1-5]
- tests/euler/p2_test.py[1-5]

## Suggested change
Ensure each file ends with a final newline (configure editor or run a formatter).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Tests lack assertions 🐞 Bug ≡ Correctness
Description
tests/euler/p1_test.py and tests/euler/p2_test.py only print results, so pytest will pass even if
mult_35/even_fib return incorrect values. The prints also add unnecessary noise to CI output.
Code

tests/euler/p1_test.py[R4-5]

+def test_sol1():
+    print(mult_35(1000))
Relevance

⭐ Low

Similar guidance to replace print-based tests with pytest assertions was rejected in PR #16.

PR-#16

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Both tests only print function outputs and make no assertions, so they succeed as long as the call
doesn’t raise. Other tests in the repo use assertions to validate behavior.

tests/euler/p1_test.py[1-5]
tests/euler/p2_test.py[1-5]
tests/algorithms/test_ast_tree.py[50-54]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`test_sol1` in `tests/euler/p1_test.py` and `tests/euler/p2_test.py` uses `print(...)` instead of assertions, so the tests don't validate correctness.

## Issue Context
These files are newly added tests and should enforce known Euler answers.

## Fix Focus Areas
- tests/euler/p1_test.py[4-5]
- tests/euler/p2_test.py[4-5]

## Suggested change
- Replace prints with assertions, e.g.:
 - `assert mult_35(1000) == 233168`
 - `assert even_fib(4_000_000) == 4613732`
- Remove the `print(...)` calls.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Comment on lines +1 to +8
def sum_squares(n: int):
if n < 1:
raise ValueError("n must be specified for first n sum squares")
s = 0
for i in range(1, n+1):
v = i*i
if v % 2 != 0:
s += v

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

2. Misleading function contract 🐞 Bug ⚙ Maintainability

Algorithms/numerical_methods/euler/p0.py sum_squares() only adds squares when v % 2 != 0, so it
computes the sum of odd squares (not the sum of all squares). The function name and error message
suggest a different contract, making future usage error-prone.
Agent Prompt
## Issue description
`sum_squares()` filters out even squares, but its name/error message imply it sums all squares.

## Issue Context
The current test value aligns with summing odd squares up to `n`, so the implementation may be intentional; the API contract should match the behavior.

## Fix Focus Areas
- Algorithms/numerical_methods/euler/p0.py[1-8]
- tests/euler/p0_test.py[1-4]

## Suggested change
Choose one:
1) If the intention is **odd squares**: rename to something like `sum_odd_squares` and update the ValueError message accordingly.
2) If the intention is **all squares**: remove the odd-only filter (`if v % 2 != 0:`) and update the test expected value to match the full sum of squares.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +1 to +9
def sum_squares(n: int):
if n < 1:
raise ValueError("n must be specified for first n sum squares")
s = 0
for i in range(1, n+1):
v = i*i
if v % 2 != 0:
s += v
return s No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Informational

3. Missing eof newline 🐞 Bug ⚙ Maintainability

Several newly added files are missing a trailing newline at end-of-file, which creates persistent
diff noise and may violate repo formatting expectations.
Agent Prompt
## Issue description
Multiple new files were committed without a trailing newline at EOF.

## Issue Context
The repo has previously accepted a fix specifically to add a trailing newline to avoid this recurring diff/formatting issue.

## Fix Focus Areas
- Algorithms/numerical_methods/euler/p0.py[1-9]
- Algorithms/numerical_methods/euler/p1.py[1-8]
- tests/euler/p0_test.py[1-4]
- tests/euler/p1_test.py[1-5]
- tests/euler/p2_test.py[1-5]

## Suggested change
Ensure each file ends with a final newline (configure editor or run a formatter).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant