/
essannikov
/
java.SearchForDuplicates
Обзор
Документация
Войти
/
essannikov
/
java.SearchForDuplicates
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/test/java/NormaliztionTest.java
110 строк
3 KB
essannikov
Version 1.0
30 янв 2024, 18:07
30 янв 2024, 18:07
52ef1fe
Код
Авторство
О чём код?
import junit.framework.TestCase; import java.util.ArrayList; import java.util.List; public class NormaliztionTest extends TestCase { @Override protected void setUp() throws Exception { super.setUp(); } public void testCompare(){ String s1 = "Hello world!"; String s2 = "Hello world!"; //1 int resActual = new Normalization().compare(s1, s2); int resExpected = 100; assertEquals(resActual, resExpected); //2 s2 = "Hello !"; resActual = new Normalization().compare(s1, s2); assert resActual > 50 && resActual < 100; } public void testProcessTemplate(){ String[] fragments = {"MacBook", "13", "Pro"}; List<String> resActual; //Prepare ArrayList<RegExType> regexList = new ArrayList<>(); RegExType regexListLine = new RegExType(); regexListLine.setPosition("2"); regexListLine.setRegex("^[xXхХ0-9\\~\\:\\(\\)\\[\\]\\-\\<\\>\\/\\\\]+$"); regexListLine.setName("Number"); regexListLine.setNote("num."); regexList.add(regexListLine); regexListLine = new RegExType(); regexListLine.setPosition("1"); regexListLine.setRegex("^[№0-9а-яА-ЯёЁ]+$|^[№0-9a-zA-Z]+$"); regexListLine.setName("Name"); regexListLine.setObligatory("X"); regexListLine.setMany("X"); regexList.add(regexListLine); Normalization obj = new Normalization(); obj.regexList = regexList; //Test try { resActual = obj.processTemplate(fragments); } catch (Exception e) { throw new RuntimeException(e); } //Compare List<String> resExpected = new ArrayList<>(); resExpected.add("MacBook Pro"); resExpected.add("num. 13"); assert resExpected.equals(resActual) == true; } public void testArgsParse(){ String[] args1 = {""}; boolean retActual; Normalization obj = new Normalization(); //1 try { args1[0] = "help"; retActual = obj.argsParse(args1); assertEquals(retActual, false); } catch (Exception e) { throw new RuntimeException(e); } try { args1[0] = "mistake"; retActual = obj.argsParse(args1); assert 1 == 0; } catch (Exception e) { //Correct } //3 String[] args2 = {"1", "2", "3"}; try { retActual = obj.argsParse(args2); assert 1 == 0; } catch (Exception e) { //Correct } } @Override protected void tearDown() throws Exception { super.tearDown(); } }