통화 변환
여러분은 통화 트레이딩 플랫폼에서 일하고 있어요. 통화 간 변환을 수행하는 유틸리티 클래스가 있고, 공개된 convert() 메서드는 첫 번째 통화의 금액과 환율을 받아 다른 통화의 값을 반환합니다.
여러분의 과제는 요구 사항을 코드베이스의 일부로 명확히 하기 위해 테스트를 작성하는 것입니다. 좋은 출발점은 이 메서드의 성공 시나리오에 대한 단위 테스트를 작성하는 거예요.
필요한 JUnit 패키지는 이미 임포트되어 있습니다.
이 연습은 강의의 일부입니다
Java 테스트 소개
연습 안내
- 통화 금액과 환율을 사용해
convert()메서드를 호출하세요. - 올바른 JUnit 단언을 사용하여
convertedCurrency금액이 기대값과 동일한지 확인하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
public class CurrencyConverterWithTests {
public static void main(String[] args) {
launchTestsAndPrint(CurrencyConverterTest.class);
}
}
class CurrencyConverter {
public static double convert(double currency, double exchangeRate) {
return currency * exchangeRate;
}
}
class CurrencyConverterTest {
@Test
void convert_returnsConvertedCurrency_whenValidInputs() {
double currency = 100;
double exchangeRate = 1.2;
// Call the convert method with the currency and exchange rate
double convertedCurrency = CurrencyConverter.____(currency, ____);
// Use the correct JUnit assertion, the expected value, and the converted currency amount
____(120, ____);
}
}