-
Notifications
You must be signed in to change notification settings - Fork 0
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
[BE-FEAT] 정합성 확인을 통한 테스트 정상화 및 데이터 검증 테스트 작성 #370
Open
jinchiim
wants to merge
10
commits into
be/develop
Choose a base branch
from
feat/#364-data-test
base: be/develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7804482
test(PokeomonControllerTest): 사용하지 않는 테스트 삭제
jinchiim ca75bea
test(,,,): 포켓몬 개수 변경 및 사용하지 않는 테스트 삭제
jinchiim 757f945
test(PokemonDataTest): @disabled 삭제
jinchiim a0b2c3f
feat(MoveFlag): 누락된 MoveFlag 추가
jinchiim 459e114
feat(DataPattern): 데이터 패턴 상수 선언
jinchiim 20f3fbe
test(...): 정상 구동 데이터 테스트 작성
jinchiim 1b209ca
test(...): 오타 수정
jinchiim 0ace12d
test(BiomeDataTest): 바이옴 이름 형식 추가
jinchiim 278deee
Merge branch 'be/develop' of https://github.com/woowacourse-teams/202…
jinchiim 616dbeb
modify(MoveFlag) : 중복된 MoveFlag 삭제
jinchiim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
backend/pokerogue/src/test/java/com/pokerogue/data/AbilityDataTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.pokerogue.data; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.pokerogue.data.pattern.DataPattern; | ||
import com.pokerogue.environment.repository.MongoRepositoryTest; | ||
import com.pokerogue.helper.ability.data.Ability; | ||
import com.pokerogue.helper.ability.repository.AbilityRepository; | ||
import com.pokerogue.helper.pokemon.data.Pokemon; | ||
import com.pokerogue.helper.pokemon.repository.PokemonRepository; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class AbilityDataTest extends MongoRepositoryTest { | ||
|
||
private final PokemonRepository pokemonRepository; | ||
private final List<Ability> abilities; | ||
|
||
@Autowired | ||
public AbilityDataTest(AbilityRepository abilityRepository, PokemonRepository pokemonRepository) { | ||
this.pokemonRepository = pokemonRepository; | ||
this.abilities = abilityRepository.findAll(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Ability의 아이디는 영어 소문자와 단일 _ 로만 이루어져 있다.") | ||
void id_validateAbilityIds() { | ||
List<String> notMatchAbilityIds = abilities.stream() | ||
.map(Ability::getId) | ||
.filter(DataPattern.ID_PATTERN::isNotMatch) | ||
.toList(); | ||
|
||
assertThat(notMatchAbilityIds).isEmpty(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Ability 속 포켓몬 id들은 전부 존재한다.") | ||
void pokemonId_validatePokemonIds() { | ||
List<String> pokemonIds = abilities.stream() | ||
.map(Ability::getPokemonIds) | ||
.flatMap(List::stream) | ||
.toList(); | ||
List<Pokemon> pokemons = pokemonRepository.findAll(); | ||
List<String> ids = pokemons.stream() | ||
.map(Pokemon::getId) | ||
.toList(); | ||
|
||
List<String> notMatchIds = pokemonIds.stream() | ||
.filter(pokemonId -> !ids.contains(pokemonId)) | ||
.toList(); | ||
|
||
assertThat(notMatchIds).isEmpty(); | ||
} | ||
|
||
@Test | ||
@DisplayName("모든 능력 설명이 한글이 포함되어 구성하고 있다.") | ||
void description_compositionWithKorean() { | ||
List<String> notMatchDescription = abilities.stream() | ||
.map(Ability::getDescription) | ||
.filter(DataPattern.DESCRIPTION_PATTERN::isNotMatch) | ||
.toList(); | ||
|
||
assertThat(notMatchDescription).isEmpty(); | ||
} | ||
|
||
@Test | ||
@DisplayName("모든 KoName이 적어도 한 자의 한글과 영어로 이루어져 있다.") | ||
void koName_compositionWith_AtLeastOneKorean() { | ||
List<String> notMatchNames = abilities.stream() | ||
.map(Ability::getKoName) | ||
.filter(DataPattern.KO_NAME_PATTERN::isNotMatch) | ||
.toList(); | ||
|
||
assertThat(notMatchNames).isEmpty(); | ||
} | ||
|
||
@Test | ||
@DisplayName("모든 Name이 영어로 이루어져 있다.") | ||
void name_compositionWith_English() { | ||
List<String> notMatchNames = abilities.stream() | ||
.map(Ability::getName) | ||
.filter(DataPattern.NAME_PATTERN::isNotMatch) | ||
.toList(); | ||
|
||
assertThat(notMatchNames).isEmpty(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Ability의 pokemon Id들은 중복되지 않는다.") | ||
void pokemonIds_NotDuplicated() { | ||
List<String> duplicatedPokemonAbilityIds = abilities.stream() | ||
.filter(ability -> isDuplicated(ability.getPokemonIds())) | ||
.map(Ability::getId) | ||
.toList(); | ||
|
||
assertThat(duplicatedPokemonAbilityIds).isEmpty(); | ||
} | ||
|
||
private boolean isDuplicated(List<String> pokemonIds) { | ||
return pokemonIds.size() != new HashSet<>(pokemonIds).size(); | ||
} | ||
} |
206 changes: 206 additions & 0 deletions
206
backend/pokerogue/src/test/java/com/pokerogue/data/BiomeDataTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
package com.pokerogue.data; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.pokerogue.data.pattern.DataPattern; | ||
import com.pokerogue.environment.repository.MongoRepositoryTest; | ||
import com.pokerogue.helper.biome.data.Biome; | ||
import com.pokerogue.helper.biome.data.NativePokemon; | ||
import com.pokerogue.helper.biome.data.Tier; | ||
import com.pokerogue.helper.biome.data.Trainer; | ||
import com.pokerogue.helper.biome.repository.BiomeRepository; | ||
import com.pokerogue.helper.pokemon.data.Pokemon; | ||
import com.pokerogue.helper.pokemon.repository.PokemonRepository; | ||
import com.pokerogue.helper.type.data.Type; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class BiomeDataTest extends MongoRepositoryTest { | ||
|
||
private final List<Biome> biomes; | ||
private final List<String> pokemonIds; | ||
|
||
@Autowired | ||
public BiomeDataTest(BiomeRepository biomeRepository, PokemonRepository pokemonRepository) { | ||
this.biomes = biomeRepository.findAll(); | ||
|
||
List<Pokemon> pokemons = pokemonRepository.findAll(); | ||
this.pokemonIds = pokemons.stream() | ||
.map(Pokemon::getId) | ||
.toList(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Biome의 아이디는 영어 소문자와 단일 _ 로만 이루어져 있다. ") | ||
void id_validateBiomeIds() { | ||
List<String> notMatchBiomeIds = biomes.stream() | ||
.map(Biome::getId) | ||
.filter(DataPattern.ID_PATTERN::isNotMatch) | ||
.toList(); | ||
|
||
assertThat(notMatchBiomeIds).isEmpty(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Biome의 name은 영어 문자로 이루어져 있다.") | ||
void name_compositionWith_English() { | ||
List<String> notMatchNames = biomes.stream() | ||
.map(Biome::getName) | ||
.filter(DataPattern.BIOME_NAME_PATTERN::isNotMatch) | ||
.filter(name -> !name.equals("???")) | ||
.toList(); | ||
|
||
assertThat(notMatchNames).isEmpty(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Biome의 koName은 한글이 포함되어 구성하고 있다.") | ||
void koName_compositionWith_AtLeastOneKorean() { | ||
List<String> notMatchNames = biomes.stream() | ||
.map(Biome::getKoName) | ||
.filter(this::isNotMatchKoNamePattern) | ||
.toList(); | ||
|
||
assertThat(notMatchNames).isEmpty(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Biome의 타입들은 전부 Enum Type 안에 들어가있다.") | ||
void type_isInEnumType() { | ||
assertThat(biomes.stream() | ||
.flatMap(biome -> biome.getTypes().stream())) | ||
.allMatch(type -> type.getDeclaringClass() | ||
.equals(Type.class)); | ||
} | ||
|
||
@Test | ||
@DisplayName("Biome의 Tier 들은 전부 Enum Tier 안에 들어가있다.") | ||
void tier_isInEnumTier() { | ||
assertThat(biomes.stream() | ||
.flatMap(biome -> biome.getNativePokemons().stream() | ||
.map(NativePokemon::getTier) | ||
) | ||
).allMatch(tier -> tier.getDeclaringClass().equals(Tier.class)); | ||
} | ||
|
||
@Test | ||
@DisplayName("Biome의 트레이너들의 타입들은 전부 Enum Type 안에 들어가있다.") | ||
void trainerType_isInEnumType() { | ||
List<Type> types = biomes.stream() | ||
.flatMap(biome -> biome.getTrainers().stream() | ||
.map(Trainer::getTypes)) | ||
.flatMap(Collection::stream) | ||
.toList(); | ||
|
||
assertThat(types) | ||
.allMatch(type -> type.getDeclaringClass().equals(Type.class)); | ||
} | ||
|
||
@Test | ||
@DisplayName("Biome의 native Pokemon 속 pokemonId들이 전부 존재한다.") | ||
void nativePokemonId_isInPokemonCollection() { | ||
List<NativePokemon> nativePokemons = biomes.stream() | ||
.map(Biome::getNativePokemons) | ||
.flatMap(List::stream) | ||
.toList(); | ||
|
||
List<String> nativePokemonIds = nativePokemons.stream() | ||
.map(NativePokemon::getPokemonIds) | ||
.flatMap(List::stream) | ||
.toList(); | ||
|
||
List<String> notMatchIds = nativePokemonIds.stream() | ||
.filter(nativeId -> !pokemonIds.contains(nativeId)) | ||
.toList(); | ||
jinchiim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
assertThat(notMatchIds).isEmpty(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Biome Trainer 의 name 필드가 영어 소문자 혹은 연속되지 않는 _ 로 이루어져 있다.") | ||
void name_isCompositionWithEnglish() { | ||
List<Trainer> trainers = biomes.stream() | ||
.map(Biome::getTrainers) | ||
.flatMap(List::stream) | ||
.toList(); | ||
|
||
List<String> notMatchTrainerNames = trainers.stream() | ||
.map(Trainer::getName) | ||
.filter(DataPattern.NAME_PATTERN::isNotMatch) | ||
.toList(); | ||
|
||
assertThat(notMatchTrainerNames).isEmpty(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Biome Trainer 의 KoName 필드가 한국어로 이루어져있다.") | ||
void koName_isCompositionWithKorean() { | ||
List<Trainer> trainers = biomes.stream() | ||
.map(Biome::getTrainers) | ||
.flatMap(List::stream) | ||
.toList(); | ||
|
||
List<String> notMatchTrainerNames = trainers.stream() | ||
.map(Trainer::getKoName) | ||
.filter(this::isNotMatchKoNamePattern) | ||
.toList(); | ||
|
||
assertThat(notMatchTrainerNames).isEmpty(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Biome 의 nativePokemon Id들은 중복되지 않는다.") | ||
void nativePokemonIds_NotDuplicate() { | ||
List<List<NativePokemon>> nativePokemons = biomes.stream() | ||
.map(Biome::getNativePokemons) | ||
.toList(); | ||
|
||
List<NativePokemon> duplicatedNativePokemon = new ArrayList<>(); | ||
|
||
nativePokemons.forEach(natives -> | ||
natives.forEach(nativePokemon -> { | ||
if (isDuplicated(nativePokemon.getPokemonIds())) { | ||
duplicatedNativePokemon.add(nativePokemon); | ||
} | ||
}) | ||
); | ||
|
||
assertThat(duplicatedNativePokemon).isEmpty(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Biome의 trainer PokemonId 들은 중복되지 않는다.") | ||
void trainerPokemonIds_NotDuplicated() { | ||
List<List<Trainer>> trainers = biomes.stream() | ||
.map(Biome::getTrainers) | ||
.toList(); | ||
|
||
List<Trainer> duplicatedPokemonTrainer = new ArrayList<>(); | ||
|
||
trainers.forEach(trainerList -> | ||
trainerList.forEach(trainer -> { | ||
if (isDuplicated(trainer.getPokemonIds())) { | ||
duplicatedPokemonTrainer.add(trainer); | ||
} | ||
}) | ||
); | ||
|
||
assertThat(duplicatedPokemonTrainer).isEmpty(); | ||
} | ||
|
||
private boolean isNotMatchKoNamePattern(String koName) { | ||
if ("???".equals(koName)) { | ||
return false; | ||
} | ||
return DataPattern.KO_NAME_PATTERN.isNotMatch(koName); | ||
} | ||
|
||
private boolean isDuplicated(List<String> pokemonIds) { | ||
return pokemonIds.size() != new HashSet<>(pokemonIds).size(); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
컴파일 되면서
Enum Type
인지 체크해주지 않을까요??null인지는 확인해볼 필요가 있겠지만...
타입 체킹은 필요한 테스트인지 잘 모르겠어요.ㅠㅠ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
컴파일 상황에서는 해주지 않습니다! (왜냐면 컨버터를 만든 것이 저이기 때문에..)
런타임때 발견되는데, 저도 이미 따로 컨버터 테스트를 만들어서 필요한 지 모르겠으나
일단 목표는
Data
패키지만 돌릴 수 있는 것이기 때문이 일단 추가했습니다 😋