Lab2
This commit is contained in:
parent
eab61da355
commit
70ec81dc5c
@ -1,8 +1,8 @@
|
||||
package ru.ulstu.is.cbapp.Lab2.domain;
|
||||
|
||||
public interface Calculate<T> {
|
||||
Object add(T a, T b);
|
||||
Object sut(T a, T b);
|
||||
Object len(T a);
|
||||
Object inv(T a);
|
||||
T add(T a, T b);
|
||||
T sut(T a, T b);
|
||||
Integer len(T a);
|
||||
T inv(T a);
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ public class StringCalculate implements Calculate<String> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String len(String a) {
|
||||
return "Длина = "+a.length();
|
||||
public Integer len(String a) {
|
||||
return a.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,8 +30,8 @@ public class ServiceCalculate {
|
||||
catch (Exception ex){
|
||||
return new Errors(400, ex.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Object sut(Object a, Object b, String type){
|
||||
Calculate calculate = (Calculate)applicationContext.getBean(type);
|
||||
if (a==null || a.equals("") || b==null || b.equals("")){
|
||||
|
@ -1,13 +1,52 @@
|
||||
package ru.ulstu.is.cbapp;
|
||||
|
||||
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;
|
||||
import ru.ulstu.is.cbapp.Lab2.service.ServiceCalculate;
|
||||
|
||||
@SpringBootTest
|
||||
class CbappApplicationTests {
|
||||
|
||||
@Autowired
|
||||
ServiceCalculate serviceCalculate;
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
void stringSum() {
|
||||
Assertions.assertEquals("testData",serviceCalculate.add("test","Data","string"));
|
||||
Assertions.assertEquals("1022",serviceCalculate.add("102","2","string"));
|
||||
}
|
||||
@Test
|
||||
void numberSum() {
|
||||
Assertions.assertEquals(104,serviceCalculate.add("102","2","number"));
|
||||
}
|
||||
@Test
|
||||
void stringSut() {
|
||||
Assertions.assertEquals("tt",serviceCalculate.sut("test","es","string"));
|
||||
Assertions.assertEquals("10",serviceCalculate.sut("102","2","string"));
|
||||
}
|
||||
@Test
|
||||
void numberSut() {
|
||||
Assertions.assertEquals(100,serviceCalculate.sut(102,2,"number"));
|
||||
}
|
||||
@Test
|
||||
void stringLen() {
|
||||
Assertions.assertEquals("Длина = 4",serviceCalculate.len("test","string"));
|
||||
}
|
||||
@Test
|
||||
void numberLen() {
|
||||
Assertions.assertEquals(3,serviceCalculate.len(305,"number"));
|
||||
Assertions.assertEquals(2,serviceCalculate.len(24,"number"));
|
||||
}
|
||||
@Test
|
||||
void stringInv() {
|
||||
Assertions.assertEquals("gnirts",serviceCalculate.inv("string","string"));
|
||||
}
|
||||
@Test
|
||||
void numberInv() {
|
||||
Assertions.assertEquals(-102,serviceCalculate.inv(102,"number"));
|
||||
Assertions.assertEquals(12,serviceCalculate.inv(-12,"number"));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user