From aac82d37eecbf78396c8449f694baf3e728faab9 Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Tue, 28 Feb 2023 10:48:49 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=A02=20=D1=82=D0=B5=D1=81=D1=82=D1=8B?= =?UTF-8?q?=20=D0=B8=20=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=BA=D0=B0=20MethodInt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../is/lab1/speaker/domain/MethodInt.java | 10 ++--- .../is/lab1/speaker/domain/MethodString.java | 10 ++--- .../ulstu/is/lab1/Lab1ApplicationTests.java | 45 +++++++++++++++++++ 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/src/main/java/ru/ulstu/is/lab1/speaker/domain/MethodInt.java b/src/main/java/ru/ulstu/is/lab1/speaker/domain/MethodInt.java index 6034879..ebd47bd 100644 --- a/src/main/java/ru/ulstu/is/lab1/speaker/domain/MethodInt.java +++ b/src/main/java/ru/ulstu/is/lab1/speaker/domain/MethodInt.java @@ -5,20 +5,20 @@ import org.springframework.stereotype.Component; @Component(value="int") public class MethodInt implements IMethod{ public Integer Sum(Integer first, Integer second) { - return Integer.parseInt(first.toString()) + Integer.parseInt(second.toString()); + return first + second; } public Integer Minus(Integer first, Integer second) { - return Integer.parseInt(first.toString()) - Integer.parseInt(second.toString()); + return first - second; } public Integer Reverse(Integer first, Integer second) { - return (Integer.parseInt(first.toString()) + Integer.parseInt(second.toString())) * (-1); + return (first + second) * (-1); } public Integer Comparison(Integer first, Integer second) { - int num1 = Integer.parseInt(first.toString()); - int num2 = Integer.parseInt(second.toString()); + int num1 = first; + int num2 = second; if (num1 >= num2){ return num1; }else{ diff --git a/src/main/java/ru/ulstu/is/lab1/speaker/domain/MethodString.java b/src/main/java/ru/ulstu/is/lab1/speaker/domain/MethodString.java index a12c991..1d2ea65 100644 --- a/src/main/java/ru/ulstu/is/lab1/speaker/domain/MethodString.java +++ b/src/main/java/ru/ulstu/is/lab1/speaker/domain/MethodString.java @@ -11,9 +11,9 @@ public class MethodString implements IMethod{ @Override public String Minus(String first, String second) { - String arr[] = first.split(""); + String[] arr = first.split(""); for(int i = 0; i < first.length(); i++){ - if (second.indexOf(arr[i]) >= 0){ + if (second.contains(arr[i])){ arr[i] = ""; } } @@ -23,11 +23,11 @@ public class MethodString implements IMethod{ @Override public String Reverse(String first, String second) { String ourStr = first.concat(second); - String newStr = ""; + StringBuilder newStr = new StringBuilder(); for(int i = ourStr.length() - 1; i >= 0; i--){ - newStr += ourStr.charAt(i); + newStr.append(ourStr.charAt(i)); } - return newStr; + return newStr.toString(); } @Override diff --git a/src/test/java/ru/ulstu/is/lab1/Lab1ApplicationTests.java b/src/test/java/ru/ulstu/is/lab1/Lab1ApplicationTests.java index 4113855..772942c 100644 --- a/src/test/java/ru/ulstu/is/lab1/Lab1ApplicationTests.java +++ b/src/test/java/ru/ulstu/is/lab1/Lab1ApplicationTests.java @@ -1,13 +1,58 @@ package ru.ulstu.is.lab1; +import ru.ulstu.is.lab1.speaker.service.MethodService; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest class Lab1ApplicationTests { + @Autowired + MethodService methodService; @Test void contextLoads() { } + @Test + void testPlusInt() { + final String res = methodService.Sum(10, 10, "int"); + Assertions.assertEquals(20, Integer.parseInt(res)); + } + @Test + void testMinusInt() { + final String res = methodService.Ras(8, 4, "int"); + Assertions.assertEquals(4, Integer.parseInt(res)); + } + @Test + void testReverseInt() { + final String res = methodService.Rev(10, 10, "int"); + Assertions.assertEquals(-20, Integer.parseInt(res)); + } + @Test + void testComparisonInt() { + final String res = methodService.Com(8, 4, "int"); + Assertions.assertEquals(8, Integer.parseInt(res)); + } + @Test + void testPlusStr() { + final String res = methodService.Sum("10", "10", "string"); + Assertions.assertEquals("1010", res); + } + @Test + void testMinusStr() { + final String res = methodService.Ras("846734", "4", "string"); + Assertions.assertEquals("8673", res); + } + @Test + void testReverseStr() { + final String res = methodService.Rev("846734", "312", "string"); + Assertions.assertEquals("213437648", res); + } + @Test + void testComparisonStr() { + final String res = methodService.Com("846734", "312", "string"); + Assertions.assertEquals("846734", res); + } }