Вторая лабораторная.
This commit is contained in:
parent
436fecf2ec
commit
4184b1c47a
@ -9,6 +9,11 @@
|
||||
<body>
|
||||
<input id="First" class="form-control" type="text" placeholder="Введите первое число" aria-label="readonly input example">
|
||||
<input id="Second" class="form-control" type="text" placeholder="Ведите второе число" aria-label="readonly input example">
|
||||
<select id="_Type" value="int" class="form-select form-select-sm" aria-label=".form-select-sm пример">
|
||||
<option selected>Откройте это меню выбора</option>
|
||||
<option value="int">Числа</option>
|
||||
<option value="string">Строки</option>
|
||||
</select>
|
||||
|
||||
<div>
|
||||
<button id="Sum" type="button" class="btn btn-success">+</button>
|
||||
|
@ -1,16 +1,19 @@
|
||||
const one = document.getElementById('First');
|
||||
const two = document.getElementById('Second');
|
||||
const type = document.getElementById('_Type');
|
||||
const result = document.getElementById('Result');
|
||||
const check = null;
|
||||
|
||||
const button_s = document.getElementById('Sum');
|
||||
button_s.addEventListener("click", function()
|
||||
{
|
||||
console.log("Кнопка нажата.");
|
||||
console.log("Кнопка нажата. 5");
|
||||
|
||||
fetch('http://localhost:8080/sum?num_1=' + one.value + '&num_2=' + two.value)
|
||||
fetch('http://localhost:8080/sum?num_1=' + one.value + '&num_2=' + two.value + '&type=' + type.value)
|
||||
.then((response) => response.text())
|
||||
.then((data) => result.value = data)
|
||||
.then((data) => result.value = data);
|
||||
|
||||
result.value = "6";
|
||||
});
|
||||
|
||||
const button_min = document.getElementById('Minus');
|
||||
@ -18,7 +21,7 @@ button_min.addEventListener("click", function()
|
||||
{
|
||||
console.log("Кнопка нажата.");
|
||||
|
||||
fetch('http://localhost:8080/minus?num_1=' + one.value + '&num_2=' + two.value)
|
||||
fetch('http://localhost:8080/minus?num_1=' + one.value + '&num_2=' + two.value + '&type=' + type.value)
|
||||
.then((response) => response.text())
|
||||
.then((data) => result.value = data)
|
||||
});
|
||||
@ -34,7 +37,7 @@ button_i.addEventListener("click", function()
|
||||
}
|
||||
else
|
||||
{
|
||||
fetch('http://localhost:8080/cont?num_1=' + one.value + '&num_2=' + two.value)
|
||||
fetch('http://localhost:8080/cont?num_1=' + one.value + '&num_2=' + two.value + '&type=' + type.value)
|
||||
.then((response) => response.text())
|
||||
.then((data) => result.value = data)
|
||||
}
|
||||
@ -45,7 +48,7 @@ button_m.addEventListener("click", function()
|
||||
{
|
||||
console.log("Кнопка нажата.");
|
||||
|
||||
fetch('http://localhost:8080/mul?num_1=' + one.value + '&num_2=' + two.value)
|
||||
fetch('http://localhost:8080/mul?num_1=' + one.value + '&num_2=' + two.value + '&type=' + type.value)
|
||||
.then((response) => response.text())
|
||||
.then((data) => result.value = data)
|
||||
});
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.example;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@SpringBootApplication
|
||||
@RestController
|
||||
public class SpringOnlineCalculatorApplication
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
SpringApplication.run(SpringOnlineCalculatorApplication.class, args);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.example.spring_online_calculator;
|
||||
package com.example;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
@ -1,48 +0,0 @@
|
||||
package com.example.spring_online_calculator;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@SpringBootApplication
|
||||
@RestController
|
||||
public class SpringOnlineCalculatorApplication {
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
SpringApplication.run(SpringOnlineCalculatorApplication.class, args);
|
||||
}
|
||||
|
||||
/*
|
||||
@GetMapping("/plus")
|
||||
public Integer Plus(@RequestParam(value="num_1") Integer num_1,
|
||||
@RequestParam(value="num_2") Integer num_2) {
|
||||
return num_1 + num_2;
|
||||
}
|
||||
|
||||
@GetMapping("/minus")
|
||||
public Integer Minus(@RequestParam(value="num_1") Integer num_1,
|
||||
@RequestParam(value="num_2") Integer num_2) {
|
||||
return num_1 - num_2;
|
||||
}
|
||||
|
||||
@GetMapping("/implement")
|
||||
public Integer Implements(@RequestParam(value="num_1") Integer num_1,
|
||||
@RequestParam(value="num_2") Integer num_2) {
|
||||
if(num_2 == 0){
|
||||
return 0;
|
||||
}
|
||||
|
||||
return num_1 / num_2;
|
||||
}
|
||||
|
||||
@GetMapping("/multiplication")
|
||||
public Integer Multiplication(@RequestParam(value="num_1") Integer num_1,
|
||||
@RequestParam(value="num_2") Integer num_2) {
|
||||
return num_1 * num_2;
|
||||
}
|
||||
*/
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.example;
|
||||
|
||||
import com.example.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 SpringOnlineCalculatorApplicationTests {
|
||||
|
||||
@Autowired
|
||||
MethodService methodService;
|
||||
|
||||
@Test
|
||||
void testMethodSumInt() {
|
||||
Assertions.assertEquals(3,Integer.parseInt(methodService.Sum(1, 2, "int")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodSumString() {
|
||||
Assertions.assertEquals("12", methodService.Sum("1", "2", "string"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodMinusInt() {
|
||||
Assertions.assertEquals(-1,Integer.parseInt(methodService.Minus(1, 2, "int")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodMinusString() {
|
||||
Assertions.assertEquals("214324", methodService.Minus("214324", "4", "string"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodMultInt() {
|
||||
Assertions.assertEquals(2, Integer.parseInt(methodService.Multiply(1, 2, "int")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodMultString() {
|
||||
Assertions.assertEquals("11", methodService.Multiply("1", "2", "string"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodContainsInt() {
|
||||
Assertions.assertEquals(60, Integer.parseInt(methodService.Contains(120, 2, "int")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodContainsString() {
|
||||
Assertions.assertEquals("false", methodService.Contains("1", "2", "string"));
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
package com.example.spring_online_calculator;
|
||||
|
||||
import com.example.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 SpringOnlineCalculatorApplicationTests {
|
||||
|
||||
@Autowired
|
||||
MethodService methodService;
|
||||
|
||||
@Test
|
||||
void testMethodSumInt() {
|
||||
final String res = methodService.Sum("1", "2", "int");
|
||||
Assertions.assertEquals("3", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodSumString() {
|
||||
final String res = methodService.Sum("1", "2", "string");
|
||||
Assertions.assertEquals("12", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodMinusInt() {
|
||||
final String res = methodService.Minus("1", "2", "int");
|
||||
Assertions.assertEquals("-1", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodMinusString() {
|
||||
final String res = methodService.Minus("214324", "4", "string");
|
||||
Assertions.assertEquals("2132", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodMultInt() {
|
||||
final String res = methodService.Multiply("1", "2", "int");
|
||||
Assertions.assertEquals("2", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodMultString() {
|
||||
final String res = methodService.Multiply("1", "2", "string");
|
||||
Assertions.assertEquals("11", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodContainsInt() {
|
||||
final String res = methodService.Contains("123", "2", "int");
|
||||
Assertions.assertEquals("true", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMethodContainsString() {
|
||||
final String res = methodService.Contains("1", "2", "string");
|
||||
Assertions.assertEquals("false", res);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user