룰렛 합계 검증
- Float 값이라 정확히 100.0이 나오지 않으므로 totalPercentage가 99.9보다 크고 100.1보다 작으면 통과되도록 조건 수정
This commit is contained in:
parent
263ca3ac9a
commit
0e0114a7d1
|
@ -23,7 +23,6 @@ import kr.co.vividnext.sodalive.member.MemberRole
|
|||
import org.springframework.data.repository.findByIdOrNull
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import java.math.BigDecimal
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||
import kotlin.concurrent.write
|
||||
import kotlin.random.Random
|
||||
|
@ -237,8 +236,8 @@ class RouletteService(
|
|||
throw SodaException("룰렛 옵션은 최소 2개, 최대 10개까지 설정할 수 있습니다.")
|
||||
}
|
||||
|
||||
val totalPercentage = items.map { BigDecimal(it.percentage.toDouble()) }.reduce(BigDecimal::plus)
|
||||
if (totalPercentage != BigDecimal(100.0)) {
|
||||
val totalPercentage = items.map { it.percentage }.sum()
|
||||
if (totalPercentage > 100.1f || totalPercentage < 99.9f) {
|
||||
throw SodaException("확률이 100%가 아닙니다")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue