Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add Unit Test for LargestPrimeDivisor #241

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hailduong
Copy link

@hailduong hailduong commented Dec 17, 2024

Hello, this PR introduces unit tests for the LargestPrimeDivisor program to ensure its correctness across various input scenarios. The tests verify the program’s behavior for small numbers, prime numbers, composite numbers, and negative numbers.

Changes Made:

• Added JUnit 5 test methods with input/output redirection to simulate user input and capture program output.
• Validated program logic against edge cases, including:
• Small numbers and prime numbers.
• Large composite numbers with multiple prime factors.
• Negative numbers, ensuring absolute values are handled correctly.

Test Scenarios:

Test Name Input Expected Output Description
testSmallNumbers 2\n6\n100\n0\n -1\n3\n5 Handles small numbers and basic composites.
testPrimeNumber 17\n0\n -1 Prime number → no largest prime divisor.
testLargeNumber 13195\n0\n 29 Largest prime divisor for composite input.
testNegativeNumbers -100\n0\n 5 Handles negative input by using absolute value.

Why is this needed?

•	These unit tests ensure the program handles edge cases correctly and adheres to problem requirements.
•	Adds confidence in program behavior for both typical and atypical inputs.

How to Test:

Run the tests using Maven:
mvn clean test

Verify all tests pass successfully.

Notes:

The test suite includes edge cases like prime numbers, negative inputs, and large composite numbers to validate the robustness of the program logic.

@Hoopeu
Copy link

Hoopeu commented Dec 17, 2024 via email

@lingbaoer
Copy link

lingbaoer commented Dec 17, 2024 via email

@Jiruiyang
Copy link

Jiruiyang commented Dec 17, 2024 via email

@JR00010
Copy link

JR00010 commented Dec 17, 2024 via email

@hailduong hailduong force-pushed the test/LargestPrimeDevisor branch from 7856f98 to 677d90e Compare December 17, 2024 15:39
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.

6 participants