शुरू करेंमुफ़्त में शुरू करें

मुद्रा रूपांतरण

आप एक करेंसी ट्रेडिंग प्लेटफ़ॉर्म पर काम कर रहे हैं। एक यूटिलिटी क्लास है जो मुद्राओं के बीच कन्वर्ट करती है। इसकी public convert() मेथड पहली करेंसी में दी गई राशि और एक exchange rate लेती है, और दूसरी करेंसी में मान लौटाती है.

आपका कार्य है इसके लिए प्रोजेक्ट आवश्यकताओं को टेस्ट्स लिखकर कोडबेस का हिस्सा बनाना। शुरुआत के लिए एक अच्छा कदम होगा कि आप इस मेथड के success scenario के लिए एक unit test लिखें.

आवश्यक JUnit पैकेज आपके लिए इम्पोर्ट कर दिए गए हैं.

यह अभ्यास पाठ्यक्रम का हिस्सा है

Java में Testing परिचय

पाठ्यक्रम देखें

अभ्यास निर्देश

  • convert() मेथड को currency राशि और exchange rate के साथ कॉल करें.
  • सही JUnit assertion का उपयोग करके जाँचें कि 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, ____); 
    }
}
कोड संपादित करें और चलाएँ