LabWork_02 добвлен еще один тип, лаба сдана
This commit is contained in:
parent
d80f64a86e
commit
63c115f8be
@ -49,6 +49,7 @@
|
||||
<option value="int">Integer</option>
|
||||
<option value="str">String</option>
|
||||
<option value="double">Double</option>
|
||||
<option value="array">Array</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -2,6 +2,7 @@ package ru.IP_LabWorks.IP.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import ru.IP_LabWorks.IP.domain.TypeArray;
|
||||
import ru.IP_LabWorks.IP.domain.TypeDouble;
|
||||
import ru.IP_LabWorks.IP.domain.TypeInt;
|
||||
import ru.IP_LabWorks.IP.domain.TypeString;
|
||||
@ -22,4 +23,9 @@ public class TypeConfiguration {
|
||||
public TypeDouble createDoubleType(){
|
||||
return new TypeDouble();
|
||||
}
|
||||
|
||||
@Bean(value = "array")
|
||||
public TypeArray createArrayType(){
|
||||
return new TypeArray();
|
||||
}
|
||||
}
|
||||
|
43
src/main/java/ru/IP_LabWorks/IP/domain/TypeArray.java
Normal file
43
src/main/java/ru/IP_LabWorks/IP/domain/TypeArray.java
Normal file
@ -0,0 +1,43 @@
|
||||
package ru.IP_LabWorks.IP.domain;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TypeArray implements ITypeInterface<ArrayList<Integer>> {
|
||||
|
||||
@Override
|
||||
public ArrayList<Integer> Method1(ArrayList<Integer> value1, ArrayList<Integer> value2) {
|
||||
ArrayList<Integer> result = new ArrayList<>();
|
||||
for (int i = 0; i < Math.min(value1.size(), value2.size()); ++i){
|
||||
result.add(value1.get(i) + value2.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<Integer> Method2(ArrayList<Integer> value1, ArrayList<Integer> value2) {
|
||||
ArrayList<Integer> result = new ArrayList<>();
|
||||
for (int i = 0; i < Math.min(value1.size(), value2.size()); ++i){
|
||||
result.add(value1.get(i) - value2.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<Integer> Method3(ArrayList<Integer> value1, ArrayList<Integer> value2) {
|
||||
ArrayList<Integer> result = new ArrayList<>();
|
||||
for (int i = 0; i < Math.min(value1.size(), value2.size()); ++i){
|
||||
result.add(value1.get(i) * value2.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<Integer> Method4(ArrayList<Integer> value1, ArrayList<Integer> value2) {
|
||||
ArrayList<Integer> result = new ArrayList<>();
|
||||
for (int i = 0; i < Math.min(value1.size(), value2.size()); ++i){
|
||||
result.add(value1.get(i) / value2.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -4,6 +4,12 @@ import ru.IP_LabWorks.IP.domain.ITypeInterface;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class TypeService {
|
||||
|
||||
@ -42,8 +48,15 @@ public class TypeService {
|
||||
_value1 = value1;
|
||||
_value2 = value2;
|
||||
}
|
||||
case "array" -> {
|
||||
_value1 = Arrays.stream(value1.toString().split(","))
|
||||
.map(Integer::parseInt)
|
||||
.collect(Collectors.toList());
|
||||
_value2 = Arrays.stream(value2.toString().split(","))
|
||||
.map(Integer::parseInt)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Object Method1(Object value1, Object value2, String type){
|
||||
|
@ -86,4 +86,28 @@ class IpApplicationTests {
|
||||
final String res = (String)Service.Method4( "1.01", "2.76", "double");
|
||||
Assertions.assertEquals("0.36594202898550726", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testArrayPlus(){
|
||||
final String res = (String)Service.Method1( "1,2,3", "1,2,3", "array");
|
||||
Assertions.assertEquals("[2, 4, 6]", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testArrayMinus(){
|
||||
final String res = (String)Service.Method2( "1,2,3", "1,2,3", "array");
|
||||
Assertions.assertEquals("[0, 0, 0]", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testArrayMult(){
|
||||
final String res = (String)Service.Method3( "1,2,3", "1,2,3", "array");
|
||||
Assertions.assertEquals("[1, 4, 9]", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testArrayDiv(){
|
||||
final String res = (String)Service.Method4( "1,2,3", "1,2,3", "array");
|
||||
Assertions.assertEquals("[1, 1, 1]", res);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user