Bir sayının basamakları
Önceki derste gördüğümüz, bir sayının son basamağını bulan yöntemi düşün. Bu yöntem bir tamsayının son basamağını almak için % 10 kullanır.
Verilen bir tamsayı değeri için bu yöntemin çalıştığını gösteren GEÇEN bir test yaz.
Gerekli JUnit paketleri senin için içe aktarıldı.
Bu egzersiz
Java'da Teste Giriş
kursunun bir parçasıdırEgzersiz talimatları
- Bu testi JUnit'in çalıştırmasını sağlayacak doğru anotasyonu gir.
- Verilen tamsayının beklenen son basamağını gir.
- Beklenen ve gerçek değerlerin eşitliğini doğrulamak için doğru JUnit assertion'ını kullan.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
public class LastDigitWithTests {
public static void main(String[] args) {
launchTestsAndPrint(LastDigitTest.class);
}
}
class LastDigitTest {
// Use the correct annotation to mark this as a JUnit test
@____
void testLastDigit() {
int number = 2025;
// What is the expected output?
int expected = ____;
int actual = LastDigit.lastDigit(number);
// Use the correct JUnit assertion for the scenario
____(expected, actual);
}
}