summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormaks <maks@jopek.eu>2022-11-09 08:10:30 +0100
committermaks <maks@jopek.eu>2022-11-09 08:10:30 +0100
commitd9c3799fbd368ea672d41f5b98df168b8191148e (patch)
tree848d5da4c52941b83b0c0bd72321a4291d21cb2c
parent81ff51148575b9ad4bc16ebf18afa5819174c7e6 (diff)
downloadapplicationdevrification-d9c3799fbd368ea672d41f5b98df168b8191148e.tar.gz
applicationdevrification-d9c3799fbd368ea672d41f5b98df168b8191148e.tar.zst
applicationdevrification-d9c3799fbd368ea672d41f5b98df168b8191148e.zip
Add testsHEADmaster
-rw-r--r--.idea/misc.xml5
-rw-r--r--app/src/main/java/com/jopek/applicationdevrification/CodeOption.java13
-rw-r--r--app/src/main/java/com/jopek/applicationdevrification/MainActivity.java105
-rw-r--r--app/src/main/java/com/jopek/applicationdevrification/RegexTester.java78
-rw-r--r--app/src/test/java/com/jopek/applicationdevrification/MainActivityTestAddress.java32
-rw-r--r--app/src/test/java/com/jopek/applicationdevrification/MainActivityTestCensorship.java32
-rw-r--r--app/src/test/java/com/jopek/applicationdevrification/MainActivityTestEmail.java32
-rw-r--r--app/src/test/java/com/jopek/applicationdevrification/MainActivityTestIdcard.java32
-rw-r--r--app/src/test/java/com/jopek/applicationdevrification/MainActivityTestNameNSurname.java32
-rw-r--r--app/src/test/java/com/jopek/applicationdevrification/MainActivityTestPassword.java32
-rw-r--r--app/src/test/java/com/jopek/applicationdevrification/MainActivityTestPesel.java32
-rw-r--r--app/src/test/java/com/jopek/applicationdevrification/MainActivityTestPhone.java32
12 files changed, 381 insertions, 76 deletions
diff --git a/.idea/misc.xml b/.idea/misc.xml
index bdd9278..6b4853f 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
+ <component name="EntryPointsManager">
+ <list size="1">
+ <item index="0" class="java.lang.String" itemvalue="org.junit.Test" />
+ </list>
+ </component>
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
diff --git a/app/src/main/java/com/jopek/applicationdevrification/CodeOption.java b/app/src/main/java/com/jopek/applicationdevrification/CodeOption.java
new file mode 100644
index 0000000..d4b96f2
--- /dev/null
+++ b/app/src/main/java/com/jopek/applicationdevrification/CodeOption.java
@@ -0,0 +1,13 @@
+package com.jopek.applicationdevrification;
+
+public enum CodeOption {
+ zipCode,
+ address,
+ phone,
+ email,
+ pesel,
+ idcard,
+ nameNSurname,
+ password,
+ censorship,
+}
diff --git a/app/src/main/java/com/jopek/applicationdevrification/MainActivity.java b/app/src/main/java/com/jopek/applicationdevrification/MainActivity.java
index e9c9603..1b46be2 100644
--- a/app/src/main/java/com/jopek/applicationdevrification/MainActivity.java
+++ b/app/src/main/java/com/jopek/applicationdevrification/MainActivity.java
@@ -7,7 +7,6 @@ import android.graphics.Color;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.InputType;
-import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
@@ -21,19 +20,8 @@ import androidx.appcompat.app.AppCompatActivity;
import java.util.regex.Pattern;
-enum CodeOption {
- zipCode,
- address,
- phone,
- email,
- pesel,
- idcard,
- nameNSurname,
- password,
- censorship,
-}
-
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
+ public boolean testing = false;
ArrayAdapter<CharSequence> adapter;
EditText input;
TextView output;
@@ -68,72 +56,37 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
} else if (selOption == CodeOption.zipCode) {
Requests requests = new Requests();
requests.get("https://jopek.eu/maks/get-city?code=" + in, txt -> {
- validateResult(txt.length() != 0, "");
+ validateResult(txt.length() != 0, txt);
});
return;
- } else if (selOption == CodeOption.address) {
- Pattern p = Pattern.compile("^([a-ząśćżźńłęó]+ )+\\d+[a-z]?$", Pattern.CASE_INSENSITIVE);
- result = p.matcher(in).matches();
- } else if (selOption == CodeOption.phone) {
- Pattern p;
- if (in.charAt(0) == '+') {
- p = Pattern.compile("\\+(\\d\\d?\\d?)\\d{9}", Pattern.CASE_INSENSITIVE);
- } else {
- p = Pattern.compile("\\d{7}(\\d{2})?", Pattern.CASE_INSENSITIVE);
- }
- result = p.matcher(in).matches();
- } else if (selOption == CodeOption.email) {
- Pattern p = Pattern.compile("^[a-zA-Z][\\w.]+[\\w]@[a-z]{2,}\\.[a-z]{2,}$");
- result = p.matcher(in).matches();
} else if (selOption == CodeOption.pesel) {
- int lastDigit = Integer.parseInt(in.substring(10, 11));
- int a = Integer.parseInt(in.substring(0, 1));
- int b = Integer.parseInt(in.substring(1, 2));
- int c = Integer.parseInt(in.substring(2, 3));
- int d = Integer.parseInt(in.substring(3, 4));
- int e = Integer.parseInt(in.substring(4, 5));
- int f = Integer.parseInt(in.substring(5, 6));
- int g = Integer.parseInt(in.substring(6, 7));
- int h = Integer.parseInt(in.substring(7, 8));
- int i = Integer.parseInt(in.substring(8, 9));
- int j = Integer.parseInt(in.substring(9, 10));
- int sum = 9 * a + 7 * b + 3 * c + 1 * d + 9 * e + 7 * f + 3 * g + 1 * h + 9 * i + 7 * j;
- result = sum % 10 == lastDigit;
- if (result) {
- int plec = Integer.parseInt(in.substring(9, 10));
- if (plec % 2 == 0 || plec == 0) {
- gender = "K";
- } else {
- gender = "M";
+ if (in.length() != 11) {
+ result = false;
+ } else {
+ int lastDigit = Integer.parseInt(in.substring(10, 11));
+ int a = Integer.parseInt(in.substring(0, 1));
+ int b = Integer.parseInt(in.substring(1, 2));
+ int c = Integer.parseInt(in.substring(2, 3));
+ int d = Integer.parseInt(in.substring(3, 4));
+ int e = Integer.parseInt(in.substring(4, 5));
+ int f = Integer.parseInt(in.substring(5, 6));
+ int g = Integer.parseInt(in.substring(6, 7));
+ int h = Integer.parseInt(in.substring(7, 8));
+ int i = Integer.parseInt(in.substring(8, 9));
+ int j = Integer.parseInt(in.substring(9, 10));
+ int sum = 9 * a + 7 * b + 3 * c + 1 * d + 9 * e + 7 * f + 3 * g + 1 * h + 9 * i + 7 * j;
+ result = sum % 10 == lastDigit;
+ if (result) {
+ int plec = Integer.parseInt(in.substring(9, 10));
+ if (plec % 2 == 0 || plec == 0) {
+ gender = "K";
+ } else {
+ gender = "M";
+ }
}
}
- } else if (selOption == CodeOption.idcard) {
- Pattern p = Pattern.compile(".*\\d.*");
- result = p.matcher(in).matches();
- if (result) {
- p = Pattern.compile("^[a-z][a-z\\d]+$", Pattern.CASE_INSENSITIVE);
- result = p.matcher(in).matches();
- }
- } else if (selOption == CodeOption.nameNSurname) {
- Pattern p = Pattern.compile("^[a-z]+ [a-z]+(-[a-z]+)?$", Pattern.CASE_INSENSITIVE);
- result = p.matcher(in).matches();
- } else if (selOption == CodeOption.password) {
- result = in.matches(".*[A-Z].*");
- Log.d("maks", "validate: " + result);
- result = result && in.matches(".*[a-z].*");
- Log.d("maks", "validate: " + result);
- result = result && in.matches(".*([^\\w\\s]|_).*");
- Log.d("maks", "validate: " + result);
- result = result && in.matches(".*\\d.*");
- Log.d("maks", "validate: " + result);
- result = result && in.matches(".{7,}");
- Log.d("maks", "validate: " + result);
- } else if (selOption == CodeOption.censorship) {
- String[] illegal = new String[]{"wtf", "rabarbar", "kobieta", "bezalkoholowe", "kamienskiego"};
- result = true;
- for (String ill : illegal) {
- result = result && !in.matches(".*" + ill + ".*");
- }
+ } else {
+ result = RegexTester.validate(in, selOption);
}
validateResult(result, gender);
@@ -167,7 +120,7 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
selOption = CodeOption.address// input.setMinLines(1);
// input.setLines(2);
// input.setMaxLines(10);
-;
+ ;
} else if ("phone".contentEquals(selectedOption)) {
selOption = CodeOption.phone;
} else if ("email".contentEquals(selectedOption)) {
@@ -195,7 +148,7 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
} else if (selOption == CodeOption.pesel) {
input.setFilters(new InputFilter[]{new InputFilter.LengthFilter(11)});
input.setInputType(InputType.TYPE_CLASS_NUMBER);
- } else if (selOption == CodeOption.password || selOption == CodeOption.censorship) {
+ } else if (/* selOption == CodeOption.password || */ selOption == CodeOption.censorship) {
input.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
input.setSingleLine(false);
}
diff --git a/app/src/main/java/com/jopek/applicationdevrification/RegexTester.java b/app/src/main/java/com/jopek/applicationdevrification/RegexTester.java
new file mode 100644
index 0000000..da491fc
--- /dev/null
+++ b/app/src/main/java/com/jopek/applicationdevrification/RegexTester.java
@@ -0,0 +1,78 @@
+package com.jopek.applicationdevrification;
+
+import java.util.regex.Pattern;
+
+public class RegexTester {
+ static boolean validate(String in, CodeOption selOption) {
+ String gender = "";
+ boolean result = false;
+ if (in.length() == 0) {
+ result = false;
+ } else if (selOption == CodeOption.zipCode) {
+ return true;
+ } else if (selOption == CodeOption.address) {
+ Pattern p = Pattern.compile("^([a-ząśćżźńłęó]+ )+\\d+[a-z]?$", Pattern.CASE_INSENSITIVE);
+ result = p.matcher(in).matches();
+ } else if (selOption == CodeOption.phone) {
+ Pattern p;
+ if (in.charAt(0) == '+') {
+ p = Pattern.compile("\\+(\\d\\d?\\d?)\\d{9}", Pattern.CASE_INSENSITIVE);
+ } else {
+ p = Pattern.compile("\\d{7}(\\d{2})?", Pattern.CASE_INSENSITIVE);
+ }
+ result = p.matcher(in).matches();
+ } else if (selOption == CodeOption.email) {
+ Pattern p = Pattern.compile("^[a-zA-Z][\\w.]+[\\w]@[a-z]{2,}\\.[a-z]{2,}$");
+ result = p.matcher(in).matches();
+ } else if (selOption == CodeOption.pesel) {
+ if (in.length() != 11) {
+ result = false;
+ } else {
+ int lastDigit = Integer.parseInt(in.substring(10, 11));
+ int a = Integer.parseInt(in.substring(0, 1));
+ int b = Integer.parseInt(in.substring(1, 2));
+ int c = Integer.parseInt(in.substring(2, 3));
+ int d = Integer.parseInt(in.substring(3, 4));
+ int e = Integer.parseInt(in.substring(4, 5));
+ int f = Integer.parseInt(in.substring(5, 6));
+ int g = Integer.parseInt(in.substring(6, 7));
+ int h = Integer.parseInt(in.substring(7, 8));
+ int i = Integer.parseInt(in.substring(8, 9));
+ int j = Integer.parseInt(in.substring(9, 10));
+ int sum = 9 * a + 7 * b + 3 * c + 1 * d + 9 * e + 7 * f + 3 * g + 1 * h + 9 * i + 7 * j;
+ result = sum % 10 == lastDigit;
+ if (result) {
+ int plec = Integer.parseInt(in.substring(9, 10));
+ if (plec % 2 == 0 || plec == 0) {
+ gender = "K";
+ } else {
+ gender = "M";
+ }
+ }
+ }
+ } else if (selOption == CodeOption.idcard) {
+ Pattern p = Pattern.compile(".*\\d.*");
+ result = p.matcher(in).matches();
+ if (result) {
+ p = Pattern.compile("^[a-z][a-z\\d]+$", Pattern.CASE_INSENSITIVE);
+ result = p.matcher(in).matches();
+ }
+ } else if (selOption == CodeOption.nameNSurname) {
+ Pattern p = Pattern.compile("^[a-z]+ [a-z]+(-[a-z]+)?$", Pattern.CASE_INSENSITIVE);
+ result = p.matcher(in).matches();
+ } else if (selOption == CodeOption.password) {
+ result = in.matches(".*[A-Z].*");
+ result = result && in.matches(".*[a-z].*");
+ result = result && in.matches(".*([^\\w\\s]|_).*");
+ result = result && in.matches(".*\\d.*");
+ result = result && in.matches(".{7,}");
+ } else if (selOption == CodeOption.censorship) {
+ String[] illegal = new String[]{"wtf", "rabarbar", "kobieta", "bezalkoholowe", "kamienskiego"};
+ result = true;
+ for (String ill : illegal) {
+ result = result && !in.matches(".*" + ill + ".*");
+ }
+ }
+ return result;
+ }
+}
diff --git a/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestAddress.java b/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestAddress.java
new file mode 100644
index 0000000..0bbf284
--- /dev/null
+++ b/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestAddress.java
@@ -0,0 +1,32 @@
+package com.jopek.applicationdevrification;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class MainActivityTestAddress {
+ @Test
+ public void test1() {
+ boolean res = RegexTester.validate("Tomaszkowice 552", CodeOption.address);
+ assertEquals(res, true);
+ }
+
+ @Test
+ public void test2() {
+ boolean res = RegexTester.validate("Lacznosc 359a", CodeOption.address);
+ assertTrue(res);
+ }
+
+ @BeforeClass
+ public static void beforeClass() {
+ System.out.println("Testing address");
+ }
+ @AfterClass
+ public static void afterClass() {
+ System.out.println("Address passed tests");
+ }
+} \ No newline at end of file
diff --git a/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestCensorship.java b/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestCensorship.java
new file mode 100644
index 0000000..22d52bc
--- /dev/null
+++ b/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestCensorship.java
@@ -0,0 +1,32 @@
+package com.jopek.applicationdevrification;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class MainActivityTestCensorship {
+ @Test
+ public void test1() {
+ boolean res = RegexTester.validate("aakobietaaaa", CodeOption.censorship);
+ assertEquals(res, false);
+ }
+
+ @Test
+ public void test2() {
+ boolean res = RegexTester.validate("Good txt", CodeOption.censorship);
+ assertTrue(res);
+ }
+
+ @BeforeClass
+ public static void beforeClass() {
+ System.out.println("Testing censorship");
+ }
+ @AfterClass
+ public static void afterClass() {
+ System.out.println("Censorship passed tests");
+ }
+} \ No newline at end of file
diff --git a/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestEmail.java b/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestEmail.java
new file mode 100644
index 0000000..e79dce7
--- /dev/null
+++ b/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestEmail.java
@@ -0,0 +1,32 @@
+package com.jopek.applicationdevrification;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class MainActivityTestEmail {
+ @Test
+ public void test1() {
+ boolean res = RegexTester.validate("maks@jopek.eu", CodeOption.email);
+ assertNotEquals(res, false);
+ }
+
+ @Test
+ public void test2() {
+ boolean res = RegexTester.validate("nie emial", CodeOption.email);
+ assertNotEquals(res, true);
+ }
+
+ @BeforeClass
+ public static void beforeClass() {
+ System.out.println("Testing email");
+ }
+ @AfterClass
+ public static void afterClass() {
+ System.out.println("Email passed tests");
+ }
+}
diff --git a/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestIdcard.java b/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestIdcard.java
new file mode 100644
index 0000000..224c25e
--- /dev/null
+++ b/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestIdcard.java
@@ -0,0 +1,32 @@
+package com.jopek.applicationdevrification;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class MainActivityTestIdcard {
+ @Test
+ public void test1() {
+ boolean res = RegexTester.validate("qwe123ASD@!#(", CodeOption.idcard);
+ assertEquals(res, false);
+ }
+
+ @Test
+ public void test2() {
+ boolean res = RegexTester.validate("asd123", CodeOption.idcard);
+ assertTrue(res);
+ }
+
+ @BeforeClass
+ public static void beforeClass() {
+ System.out.println("Testing idcard");
+ }
+ @AfterClass
+ public static void afterClass() {
+ System.out.println("Idcard passed tests");
+ }
+}
diff --git a/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestNameNSurname.java b/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestNameNSurname.java
new file mode 100644
index 0000000..87f1b5b
--- /dev/null
+++ b/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestNameNSurname.java
@@ -0,0 +1,32 @@
+package com.jopek.applicationdevrification;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class MainActivityTestNameNSurname {
+ @Test
+ public void test1() {
+ boolean res = RegexTester.validate("asd123)(ADS aASD", CodeOption.nameNSurname);
+ assertEquals(res, false);
+ }
+
+ @Test
+ public void test2() {
+ boolean res = RegexTester.validate("mkas jopek", CodeOption.nameNSurname);
+ assertTrue(res);
+ }
+
+ @BeforeClass
+ public static void beforeClass() {
+ System.out.println("Testing nameNSurname");
+ }
+ @AfterClass
+ public static void afterClass() {
+ System.out.println("NameNSurname passed tests");
+ }
+}
diff --git a/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestPassword.java b/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestPassword.java
new file mode 100644
index 0000000..a1e2033
--- /dev/null
+++ b/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestPassword.java
@@ -0,0 +1,32 @@
+package com.jopek.applicationdevrification;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class MainActivityTestPassword {
+ @Test
+ public void test1() {
+ boolean res = RegexTester.validate("Tomaszkowice 552", CodeOption.password);
+ assertEquals(res, false);
+ }
+
+ @Test
+ public void test2() {
+ boolean res = RegexTester.validate("qwe123$%^naksaASD", CodeOption.password);
+ assertTrue(res);
+ }
+
+ @BeforeClass
+ public static void beforeClass() {
+ System.out.println("Testing password");
+ }
+ @AfterClass
+ public static void afterClass() {
+ System.out.println("Password passed tests");
+ }
+}
diff --git a/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestPesel.java b/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestPesel.java
new file mode 100644
index 0000000..577a3f5
--- /dev/null
+++ b/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestPesel.java
@@ -0,0 +1,32 @@
+package com.jopek.applicationdevrification;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class MainActivityTestPesel {
+ @Test
+ public void test1() {
+ boolean res = RegexTester.validate("Tomaszkowice 552", CodeOption.pesel);
+ assertEquals(res, true);
+ }
+
+ @Test
+ public void test2() {
+ boolean res = RegexTester.validate("03282606339", CodeOption.pesel);
+ assertTrue(res);
+ }
+
+ @BeforeClass
+ public static void beforeClass() {
+ System.out.println("Testing pesel");
+ }
+ @AfterClass
+ public static void afterClass() {
+ System.out.println("Pesel passed tests");
+ }
+}
diff --git a/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestPhone.java b/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestPhone.java
new file mode 100644
index 0000000..5f17459
--- /dev/null
+++ b/app/src/test/java/com/jopek/applicationdevrification/MainActivityTestPhone.java
@@ -0,0 +1,32 @@
+package com.jopek.applicationdevrification;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class MainActivityTestPhone {
+ @Test
+ public void test1() {
+ boolean res = RegexTester.validate("123(*&123", CodeOption.phone);
+ assertEquals(res,false);
+ }
+
+ @Test
+ public void test2() {
+ boolean res = RegexTester.validate("123456789", CodeOption.phone);
+ assertTrue(res);
+ }
+
+ @BeforeClass
+ public static void beforeClass() {
+ System.out.println("Testing phone");
+ }
+ @AfterClass
+ public static void afterClass() {
+ System.out.println("Phone passed tests");
+ }
+}