final 2 lab

This commit is contained in:
Татьяна Артамонова 2023-03-27 15:13:58 +04:00
parent 6bd3b5c5be
commit 499575123d
4 changed files with 170 additions and 88 deletions

View File

@ -2,71 +2,109 @@
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>LabWork01</title> <title>LabWork02</title>
<script src="/node_modules/bootstrap/dist/js/bootstrap.min.js"></script> <script src="/node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/node_modules/bootstrap/dist/css/bootstrap.min.css"> <link rel="stylesheet" href="/node_modules/bootstrap/dist/css/bootstrap.min.css">
</head> </head>
<body> <body class="bg-light">
<div class="container">
<div class="container mt-4"> <div class="py-5 text-center"><h2>Лабораторная работа 2</h2></div>
<div class="row justify-content-center"> <div class="row">
<div class="col-lg-6"> <div>
<h3 class="text-center font-weight-light my-2">Лабораторная работа 1</h3> <form>
<form> <div class="row">
<div class="form-row"> <div class="col-md-6 mb-3">
<div class="col"> <label for="input1">Значение 1 (string или double)</label>
<div class="form-group"> <input class="form-control" id="input1" placeholder="Введите значение 1">
<label for="input1">Первая строка</label> </div>
<input type="text" class="form-control" id="input1" placeholder="Введите перую строку"> <div class="col-md-6 mb-3">
<label for="input1">Значение 2 (string или double)</label>
<input class="form-control" id="input2" placeholder="Введите значение 2">
</div> </div>
</div> </div>
<div class="col"> <div class="row">
<div class="form-group"> <div class="form-group">
<label for="input2">Вторая строка</label> <label for="operator">Выберите функцию</label>
<input type="text" class="form-control" id="input2" placeholder="Введите вторую строку"> <select class="form-control" id="operator">
<option value>Выбрать...</option>
<option value="Func1">(string, double)Сумма</option>
<option value="Func2">(double)Минимум, (string)Сумма в верхний регистр</option>
<option value="Func3">(double)Mаксимум, (string)Разделить</option>
<option value="Func4">(double)Число 1 в степени числа 2, (string)Сумма в нижний регистр</option>
</select>
</div> </div>
</div> </div>
<button type="button" class="btn btn-primary btn-block" onclick="Sum()">Сумма</button> <div class="row">
<div class="col">
<div class="form-group"> <div class="form-group">
<label for="input3">Строка</label> <label for="operator">Выберите тип данных</label>
<input type="text" class="form-control" id="input3" placeholder="Введите строку"> <select class="form-control" id="Type">
<option value>Выбрать...</option>
<option value="str">String</option>
<option value="double">Double</option>
</select>
</div> </div>
</div> </div>
<button type="button" class="btn btn-primary btn-block" onclick="ToUpper()">В верхний регистр</button> <div class="row">
<div class="col">
<div class="form-group"> <div class="form-group">
<label for="input4">Строка</label> <label for="result">Результат</label>
<input type="text" class="form-control" id="input4" placeholder="Введите строку"> <input type="text" class="form-control result" id="result" readonly>
<label for="input5">Разделитель</label> <hr class="mb-4">
<input type="text" class="form-control" id="input5" placeholder="Введите разделитель"> <button type="button" class="btn btn-primary btn-block" onclick="calculate()">Посчитать</button>
</div> </div>
</div> </div>
<button type="button" class="btn btn-primary btn-block" onclick="Split()">Разделить</button> </form>
</div>
<div class="col">
<div class="form-group">
<label for="input6">Строка</label>
<input type="text" class="form-control" id="input6" placeholder="Введите строку">
<label for="input7">Новый символ</label>
<input type="text" class="form-control" id="input7" placeholder="Введите старый символ">
<label for="input8">Старый символ</label>
<input type="text" class="form-control" id="input8" placeholder="Введите новый символ">
</div>
</div>
<button type="button" class="btn btn-primary btn-block" onclick="Replace()">Заменить</button>
</div>
<div class="form-group">
<label for="result">Результат</label>
<input type="text" class="form-control result" id="result" readonly>
</div>
</form>
</div> </div>
</div> </div>
</div>
<!--<div class="container mt-4">-->
<!-- <div class="row justify-content-center">-->
<!-- <div class="col-lg-6">-->
<!-- <h3 class="text-center font-weight-light my-2">Лабораторная работа 2</h3>-->
<!-- <form>-->
<!-- <div class="form-row">-->
<!-- <div class="col">-->
<!-- <div class="form-group">-->
<!-- <label for="input1">Значение 1 (string или double)</label>-->
<!-- <input class="form-control" id="input1" placeholder="Введите значение 1">-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="col">-->
<!-- <div class="form-group">-->
<!-- <label for="input2">Значение 2 (string или double)</label>-->
<!-- <input class="form-control" id="input2" placeholder="Введите значение 2">-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="col">-->
<!-- <div class="form-group">-->
<!-- <label for="operator">Выбрать функцию...</label>-->
<!-- <select class="form-control" id="operator">-->
<!-- <option value="Func1">Сумма</option>-->
<!-- <option value="Func2">Минимум, Сумма в верхний регистр</option>-->
<!-- <option value="Func3">Mаксимум, Разделить</option>-->
<!-- <option value="Func4">Число 1 в степени числа 2, Сумма в нижний регистр</option>-->
<!-- </select>-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="col">-->
<!-- <div class="form-group">-->
<!-- <label for="operator">Выбрать тип данных...</label>-->
<!-- <select class="form-control" id="Type">-->
<!-- <option value="str">String</option>-->
<!-- <option value="double">Double</option>-->
<!-- </select>-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="form-group">-->
<!-- <label for="result">Результат</label>-->
<!-- <input type="text" class="form-control result" id="result" readonly>-->
<!-- </div>-->
<!-- <button type="button" class="btn btn-primary btn-block" onclick="calculate()">Посчитать</button>-->
<!-- </form>-->
<!-- </div>-->
<!-- </div>-->
<!--</div>-->
<script src = "script.js"></script> <script src = "script.js"></script>
</body> </body>
</html> </html>

View File

@ -1,44 +1,13 @@
'use strict' 'use strict'
let num1 = document.getElementById("input1") async function calculate(){
let num2 = document.getElementById("input2") let num1 = document.getElementById("input1").value
let num3 = document.getElementById("input3") let num2 = document.getElementById("input2").value
let num4 = document.getElementById("input4") let operator = document.getElementById("operator").value
let num5 = document.getElementById("input5") let result = document.getElementById("result")
let num6 = document.getElementById("input6") let type = document.getElementById("Type").value
let num7 = document.getElementById("input7")
let num8 = document.getElementById("input8")
let operator = document.getElementById("operator")
let result = document.getElementById("result")
async function Sum(){ let response = await fetch(`http://localhost:8080/${operator}?Type=${type}&value1=${num1}&value2=${num2}`)
let str1 = num1.value
let str2 = num2.value
let response = await fetch(`http://localhost:8080/Sum/${str1}/${str2}`)
let res = await response.text()
result.value = res
}
async function ToUpper(){
let str3 = num3.value
let response = await fetch(`http://localhost:8080/ToUpper/${str3}`)
let res = await response.text()
result.value = res
}
async function Split(){
let str4 = num4.value
let str5 = num5.value
let response = await fetch(`http://localhost:8080/Split/${str4}/${str5}`)
let res = await response.text()
result.value = res
}
async function Replace(){
let str6 = num6.value
let str7 = num7.value
let str8 = num8.value
let response = await fetch(`http://localhost:8080/Replace/${str6}/${str7}/${str8}`)
let res = await response.text() let res = await response.text()
result.value = res result.value = res
} }

View File

@ -1,7 +1,7 @@
package ru.ulstu.is.sbapp.service; package ru.ulstu.is.sbapp.service;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.apache.catalina.core.ApplicationContext; import org.springframework.context.ApplicationContext;
import ru.ulstu.is.sbapp.interfaces.ITypeOfData; import ru.ulstu.is.sbapp.interfaces.ITypeOfData;
@Service @Service

View File

@ -1,13 +1,88 @@
package ru.ulstu.is.sbapp; package ru.ulstu.is.sbapp;
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;
import ru.ulstu.is.sbapp.service.ServiceType;
@SpringBootTest @SpringBootTest
class SbappApplicationTests { class SbappApplicationTests {
@Autowired
ServiceType Service;
@Test @Test
void contextLoads() { void contextLoads() {
} }
@Test
void testIntPlus() {
final String res = (String) Service.Func1( "100", "10", "int");
Assertions.assertEquals("110", res);
}
@Test
void testIntMinus() {
final String res = (String)Service.Func2( "100", "10", "int");
Assertions.assertEquals("90", res);
}
@Test
void testIntMultiply() {
final String res = (String)Service.Func3( "100", "10", "int");
Assertions.assertEquals("1000", res);
}
@Test
void testIntDivision() {
final String res = (String)Service.Func4( "100", "10", "int");
Assertions.assertEquals("10", res);
}
@Test
void testStringPlus() {
final String res = (String)Service.Func1( "abc", "dfe", "str");
Assertions.assertEquals("abcdfe", res);
}
@Test
void testStringtoUpper() {
final String res = (String)Service.Func2( "abc", "dfe", "str");
Assertions.assertEquals("ABCDFE", res);
}
@Test
void testStringtoLower() {
final String res = (String)Service.Func3( "abc", "dfe", "str");
Assertions.assertEquals("abcdfe", res);
}
@Test
void testStringStrange() {
final String res = (String)Service.Func4( "abc", "dfe", "str");
Assertions.assertEquals("abcDFE", res);
}
@Test
void testDoublePlus() {
final String res = (String)Service.Func1( "1.01", "2.76", "double");
Assertions.assertEquals("3.7699999999999996", res);
}
@Test
void testDoubleMinus() {
final String res = (String)Service.Func2( "1.01", "2.76", "double");
Assertions.assertEquals("-1.7499999999999998", res);
}
@Test
void testDoubleMyltiply() {
final String res = (String)Service.Func3( "1.01", "2.76", "double");
Assertions.assertEquals("2.7876", res);
}
@Test
void testDoubleDivision() {
final String res = (String)Service.Func4( "1.01", "2.76", "double");
Assertions.assertEquals("0.36594202898550726", res);
}
} }