Advertisement
Guest User

Testy

a guest
Jan 5th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.37 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.regex.Matcher;
  4. import java.util.regex.Pattern;
  5.  
  6. public class Metody {
  7.     public boolean validateZipCode(String zipCode) {
  8.         return zipCode.matches("\\d{2}-\\d{3}");
  9.     }
  10.    
  11.     public static List<String> findEmails(String longText) {
  12.         Pattern p = Pattern.compile("(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\\\"(?:[\\\\x01-\\\\x08\\\\x0b\\\\x0c\\\\x0e-\\\\x1f\\\\x21\\\\x23-\\\\x5b\\\\x5d-\\\\x7f]|\\\\\\\\[\\\\x01-\\\\x09\\\\x0b\\\\x0c\\\\x0e-\\\\x7f])*\\\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\\\x01-\\\\x08\\\\x0b\\\\x0c\\\\x0e-\\\\x1f\\\\x21-\\\\x5a\\\\x53-\\\\x7f]|\\\\\\\\[\\\\x01-\\\\x09\\\\x0b\\\\x0c\\\\x0e-\\\\x7f])+)\\\\])");
  13.         Matcher m = p.matcher(longText);
  14.         List<String> results = new ArrayList<>();
  15.         while(m.find()) {
  16.             results.add(m.group());
  17.         }
  18.         return results;
  19.     }
  20.    
  21. }
  22.  
  23.  
  24. import java.util.ArrayList;
  25. import java.util.List;
  26. import org.junit.Test;
  27. import static org.junit.Assert.*;
  28.  
  29. /**
  30.  *
  31.  * @author kc
  32.  */
  33. public class MetodyTest {
  34.  
  35.     /**
  36.      * Test of validateZipCode method, of class Metody.
  37.      */
  38.     @Test
  39.     public void testValidateZipCode() {
  40.         System.out.println("validateZipCode");
  41.         String zipCode = "80-855";
  42.         Metody instance = new Metody();
  43.         boolean expResult = true;
  44.         boolean result = instance.validateZipCode(zipCode);
  45.         assertEquals(expResult, result);
  46.         // TODO review the generated test code and remove the default call to fail.
  47.         fail("The test case is a prototype.");
  48.     }
  49.    
  50.     @Test
  51.     public void testValidateZipCode2() {
  52.         System.out.println("validateZipCode");
  53.         String zipCode = "abcd";
  54.         Metody instance = new Metody();
  55.         boolean expResult = false;
  56.         boolean result = instance.validateZipCode(zipCode);
  57.         assertEquals(expResult, result);
  58.         // TODO review the generated test code and remove the default call to fail.
  59.         fail("The test case is a prototype.");
  60.     }
  61.    
  62.     @Test
  63.     public void testValidateZipCode3() {
  64.         System.out.println("validateZipCode");
  65.         String zipCode = "tekst 85-855";
  66.         Metody instance = new Metody();
  67.         boolean expResult = false;
  68.         boolean result = instance.validateZipCode(zipCode);
  69.         assertEquals(expResult, result);
  70.         // TODO review the generated test code and remove the default call to fail.
  71.         fail("The test case is a prototype.");
  72.     }
  73.    
  74.    
  75.    
  76.  
  77.     /**
  78.      * Test of findEmails method, of class Metody.
  79.      */
  80.     @Test
  81.     public void testFindEmails() {
  82.         System.out.println("findEmails");
  83.         String longText = "gsajkldgaklsgajgemail@o2.pldsajaskdaljfalsfkalkf lkfajsjjjjskk looqeiq kar.cie@gmail.com djkjdjutuj 812841 1.@@85.com";
  84.         List<String> expResult = new ArrayList();
  85.         expResult.add("kar.cie@gmail.com");
  86.         expResult.add("email@o2.pl");
  87.         List<String> result = Metody.findEmails(longText);
  88.         assertEquals(expResult, result);
  89.         // TODO review the generated test code and remove the default call to fail.
  90.         fail("The test case is a prototype.");
  91.     }
  92.    
  93.     @Test
  94.     public void testFindEmails2() {
  95.         System.out.println("findEmails");
  96.         String longText = "błąd/..@gmail.com email123@gmail.com złymai_.l@@test.pl";
  97.         List<String> expResult = new ArrayList();
  98.         expResult.add("email123@gmail.com");
  99.         List<String> result = Metody.findEmails(longText);
  100.         assertEquals(expResult, result);
  101.         // TODO review the generated test code and remove the default call to fail.
  102.         fail("The test case is a prototype.");
  103.     }  
  104.    
  105.     @Test
  106.     public void testFindEmails3() {
  107.         System.out.println("findEmails");
  108.         String longText = "Pusty tekst, oczekiwany brak adresów email.";
  109.         List<String> expResult = new ArrayList();
  110.         List<String> result = Metody.findEmails(longText);
  111.         assertEquals(expResult, result);
  112.         // TODO review the generated test code and remove the default call to fail.
  113.         fail("The test case is a prototype.");
  114.     }  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement