test Pesel
This commit is contained in:
parent
a2a20ce356
commit
158f566e64
10
pom.xml
10
pom.xml
@ -20,4 +20,14 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- https://mvnrepository.com/artifact/junit/junit -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.12</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
</project>
|
</project>
|
@ -1,12 +1,9 @@
|
|||||||
public class Pesel {
|
public class Pesel {
|
||||||
protected static String pesel;
|
|
||||||
|
|
||||||
public static boolean checkPesel(String pesel) {
|
public static boolean checkPesel(String pesel) {
|
||||||
Pesel.pesel = pesel;
|
return (len(pesel) && checksum(pesel) && dayOfBirth(pesel));
|
||||||
return (len() && checksum() && dayOfBirth());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checksum() {
|
public static boolean checksum(String pesel) {
|
||||||
int[] multipliers = {1, 3, 7, 9, 1, 3, 7, 9, 1, 3, 1};
|
int[] multipliers = {1, 3, 7, 9, 1, 3, 7, 9, 1, 3, 1};
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
|
|
||||||
@ -22,7 +19,7 @@ public class Pesel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean dayOfBirth() {
|
public static boolean dayOfBirth(String pesel) {
|
||||||
String dayOfBirthStr = pesel.substring(4,6);
|
String dayOfBirthStr = pesel.substring(4,6);
|
||||||
int dayOfBirth = Integer.valueOf(dayOfBirthStr);
|
int dayOfBirth = Integer.valueOf(dayOfBirthStr);
|
||||||
if(dayOfBirth > 0 && dayOfBirth < 32) {
|
if(dayOfBirth > 0 && dayOfBirth < 32) {
|
||||||
@ -33,7 +30,7 @@ public class Pesel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean len() {
|
public static boolean len(String pesel) {
|
||||||
if(pesel.length() == 11) {
|
if(pesel.length() == 11) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
63
src/test/java/PeselTest.java
Normal file
63
src/test/java/PeselTest.java
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class PeselTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkPeselText() {
|
||||||
|
String[] texts = {"Lorem ipsum", "dolor", "sit", "amet"};
|
||||||
|
|
||||||
|
for(String t : texts) {
|
||||||
|
boolean result = Pesel.checkPesel(t);
|
||||||
|
assertFalse(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkPeselInputLength() {
|
||||||
|
String[] numbers1 = {"49062718478", "77061559693", "55091042989", "60062692771", "51112482695", "45123178535"};
|
||||||
|
|
||||||
|
for(String num : numbers1) {
|
||||||
|
boolean result = Pesel.len(num);
|
||||||
|
assertTrue(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] numbers2 = {"490627184781", "770615596", "5509104298911", "6006269", "511124826952", "451231785355"};
|
||||||
|
for(String num : numbers2) {
|
||||||
|
boolean result = Pesel.len(num);
|
||||||
|
assertFalse(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkPeselChecksum() {
|
||||||
|
String[] numbers1 = {"49062718478", "77061559693", "55091042989", "60062692771", "51112482695", "45123178535"};
|
||||||
|
for(String num : numbers1) {
|
||||||
|
boolean result = Pesel.checksum(num);
|
||||||
|
assertTrue(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] numbers2 = {"49062718479", "77061559694", "55091042980", "60062692772", "51112482696", "45123178534"};
|
||||||
|
for(String num : numbers2) {
|
||||||
|
boolean result = Pesel.checksum(num);
|
||||||
|
assertFalse(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkPeselDayOfBirth() {
|
||||||
|
String[] numbers1 = {"49062718478", "77061559693", "55091042989", "60062692771", "51112482695", "45123178535"};
|
||||||
|
for (String num : numbers1) {
|
||||||
|
boolean result = Pesel.dayOfBirth(num);
|
||||||
|
assertTrue(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] numbers2 = {"49060018478", "77063259693", "55094442989", "60066592771", "51118782695", "45123278535"};
|
||||||
|
for (String num : numbers2) {
|
||||||
|
boolean result = Pesel.dayOfBirth(num);
|
||||||
|
assertFalse(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user