Skip to content

Fixing A_SumOfNumbers test case #5

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static <T> List<T> getUniqueNumberFromList(List<T> input) {
return input.stream().distinct().toList();
}

public static long sumOfNumbers(List<Integer> input) {
public static Integer sumOfNumbers(List<Integer> input) {
Copy link
Owner

Choose a reason for hiding this comment

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

The sum of the list of integers should be stored in a long or a data type with sufficient capacity to avoid potential overflow. Using an int might lead to incorrect results for larger lists.

return input.stream().reduce(0, Integer::sum);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

/*
* Given an array of {5,6,7,8,5,5,8,8,7)
* Find the sum of the unique elements.
* The output should be in this case is: 26.
* Find the sum of the all the elements.
Copy link
Owner

Choose a reason for hiding this comment

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

The documentation update is clear and looks good.

* The output should be in this case is: 59.
*/
class A_SumOfNumbers {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class I_SegregateEvenOddNumbers {
@Test
@Disabled
void testSegregationOfEvenOddNumbersTest() {
final var input = IntStream.range(1, 50).boxed();
final var mySolution = NumbersProblemSolution.segregateEvenOddNumbers(input);
final var input = IntStream.range(1, 50).boxed().toList();
Copy link
Owner

@ZahidFKhan ZahidFKhan Apr 6, 2025

Choose a reason for hiding this comment

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

Using a terminal operation here appears unnecessary and might result in slowing down of unit test case performance. We can streamline this code by keeping it within the Stream API.

final var mySolution = NumbersProblemSolution.segregateEvenOddNumbers(input.stream());
final var yourSolution = new ArrayList<>();

Assertions.assertEquals(mySolution, yourSolution);
}
}