Skip to content

Commit

Permalink
other exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
CristianLopez3 committed Jun 17, 2024
1 parent ad1cb65 commit ff9e0ae
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/test/java/com/finance/programming/UsageOfStream.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.finance.programming;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.*;

public class UsageOfStream {

@Test
@DisplayName("Given a list of numbers, when filter function is applied, then should return the even numbers")
void creatingAnInfiniteStream(){
int[] actualResult = Stream.iterate(0, x -> x + 2)
.limit(10)
.mapToInt(Integer::intValue)
.toArray();
int[] expectedResult = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18};


assertArrayEquals(expectedResult, actualResult,
"The array doesn't match");
}

}
3 changes: 1 addition & 2 deletions tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Description: Define a Supplier that returns a random string of 10 characters.
✔️ **Exercise 6: Filtering a list**
Description: Filter a list of integers to keep only the even numbers using streams and Predicate.


✔️ **Exercise 7: Mapping a list**
Description: Take a list of strings and use map to convert all strings to uppercase.

Expand All @@ -37,7 +36,7 @@ Description: Sort a list of strings in reverse alphabetical order using streams.
✔️ **Exercise 11: Using collect**
Description: Convert a list of strings into a single comma-separated string using Collectors.joining.

**Exercise 12: Creating an infinite Stream**
✔️ **Exercise 12: Creating an infinite Stream**
Description: Use Stream.iterate to create an infinite stream of even numbers and take the first 10 elements.

**Exercise 13: Using Optional**
Expand Down

0 comments on commit ff9e0ae

Please sign in to comment.