ЛР2 тесты и корректировка MethodInt

This commit is contained in:
ityurner02@mail.ru 2023-02-28 10:48:49 +04:00
parent 84c206fb61
commit aac82d37ee
3 changed files with 55 additions and 10 deletions

View File

@ -5,20 +5,20 @@ import org.springframework.stereotype.Component;
@Component(value="int") @Component(value="int")
public class MethodInt implements IMethod<Integer>{ public class MethodInt implements IMethod<Integer>{
public Integer Sum(Integer first, Integer second) { 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) { 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) { 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) { public Integer Comparison(Integer first, Integer second) {
int num1 = Integer.parseInt(first.toString()); int num1 = first;
int num2 = Integer.parseInt(second.toString()); int num2 = second;
if (num1 >= num2){ if (num1 >= num2){
return num1; return num1;
}else{ }else{

View File

@ -11,9 +11,9 @@ public class MethodString implements IMethod<String>{
@Override @Override
public String Minus(String first, String second) { public String Minus(String first, String second) {
String arr[] = first.split(""); String[] arr = first.split("");
for(int i = 0; i < first.length(); i++){ for(int i = 0; i < first.length(); i++){
if (second.indexOf(arr[i]) >= 0){ if (second.contains(arr[i])){
arr[i] = ""; arr[i] = "";
} }
} }
@ -23,11 +23,11 @@ public class MethodString implements IMethod<String>{
@Override @Override
public String Reverse(String first, String second) { public String Reverse(String first, String second) {
String ourStr = first.concat(second); String ourStr = first.concat(second);
String newStr = ""; StringBuilder newStr = new StringBuilder();
for(int i = ourStr.length() - 1; i >= 0; i--){ for(int i = ourStr.length() - 1; i >= 0; i--){
newStr += ourStr.charAt(i); newStr.append(ourStr.charAt(i));
} }
return newStr; return newStr.toString();
} }
@Override @Override

View File

@ -1,13 +1,58 @@
package ru.ulstu.is.lab1; 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.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest @SpringBootTest
class Lab1ApplicationTests { class Lab1ApplicationTests {
@Autowired
MethodService methodService;
@Test @Test
void contextLoads() { 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);
}
} }