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:
parent
ed4b43ce98
commit
cf058499c4
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue