Generation of the Sequence numbers (#14589)

* Add of unit test.

* Add of unit test.

* Update and rename GenerationOfAlphabetsUsingForVariousWaysUnitTest.java to GenerationOfCharactersUsingForVariousWaysUnitTest.java

* Replace the variable name

* Update GenerationOfCharactersUsingForVariousWaysUnitTest.java
This commit is contained in:
Zahid Khan 2023-09-29 09:17:51 +05:30 committed by GitHub
parent ed4b43ce98
commit cf058499c4
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
package com.baeldung.alphabetgeneration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
class GenerationOfCharactersUsingForVariousWaysUnitTest {
@Test
void whenUsingForLoop_thenGenerateCharacters(){
final List<Character> allCapitalCharacters = Arrays.asList('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
List<Character> characters = new ArrayList<>();
for (char character = 'A'; character <= 'Z'; character++) {
characters.add(character);
}
Assertions.assertEquals(characters, allCapitalCharacters);
}
@Test
void whenUsingStreams_thenGenerateCharacters() {
final List<Character> allCapitalCharacters = Arrays.asList('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
final List<Character> characters = IntStream.rangeClosed('A', 'Z').mapToObj(c -> (char) c).collect(Collectors.toList());
Assertions.assertEquals(characters, allCapitalCharacters);
}
}