mirror of
https://github.com/TheAlgorithms/Java.git
synced 2026-03-13 08:40:43 +08:00
Added program to check Lucky number (#6962)
added program for lucky number
This commit is contained in:
committed by
GitHub
parent
aa91451203
commit
d9f2ac8340
32
src/test/java/com/thealgorithms/maths/LuckyNumberTest.java
Normal file
32
src/test/java/com/thealgorithms/maths/LuckyNumberTest.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.thealgorithms.maths;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
class LuckyNumberTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"1", "3", "13", "49", "109", "459", "949"})
|
||||
void luckyNumbersTest(int n) {
|
||||
assertTrue(LuckyNumber.isLucky(n));
|
||||
assertTrue(LuckyNumber.isLuckyNumber(n));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"2", "17", "100", "300", "700"})
|
||||
void nonLuckyNumbersTest(int n) {
|
||||
assertFalse(LuckyNumber.isLucky(n));
|
||||
assertFalse(LuckyNumber.isLuckyNumber(n));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"0", "-1"})
|
||||
void throwsNegativeNumbersNotAllowed(int n) {
|
||||
assertThrows(IllegalArgumentException.class, () -> LuckyNumber.isLucky(n));
|
||||
assertThrows(IllegalArgumentException.class, () -> LuckyNumber.isLuckyNumber(n));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user