41 lines
1.1 KiB
Java
41 lines
1.1 KiB
Java
import org.junit.Before;
|
|
import org.junit.Test;
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
public class MainTest {
|
|
String testPesel;
|
|
@Before
|
|
public void setUp() throws Exception {
|
|
testPesel = "98032614335";
|
|
}
|
|
|
|
@Test/*(expected = NumberFormatException.class)*/
|
|
public void checkPesel() {
|
|
long pesel = Long.valueOf(testPesel);
|
|
assertTrue(testPesel.length() == 11);
|
|
int checkSum = 0;
|
|
int lastDigit = (int)( pesel % 10);
|
|
pesel /= 10;
|
|
checkSum += 3 * (pesel % 10);
|
|
pesel /= 10;
|
|
checkSum += 1 * (pesel % 10);
|
|
pesel /= 10;
|
|
checkSum += 9 * (pesel % 10);
|
|
pesel /= 10;
|
|
checkSum += 7 * (pesel % 10);
|
|
pesel /= 10;
|
|
checkSum += 3 * (pesel % 10);
|
|
pesel /= 10;
|
|
checkSum += 1 * (pesel % 10);
|
|
pesel /= 10;
|
|
checkSum += 9 * (pesel % 10);
|
|
pesel /= 10;
|
|
checkSum += 7 * (pesel % 10);
|
|
pesel /= 10;
|
|
checkSum += 3 * (pesel % 10);
|
|
pesel /= 10;
|
|
checkSum += 1 * (pesel % 10);
|
|
assertTrue((10 - (checkSum % 10)) % 10 == lastDigit );
|
|
}
|
|
} |