Compare commits
No commits in common. "unit-master" and "main" have entirely different histories.
unit-maste
...
main
@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CompilerConfiguration">
|
|
||||||
<annotationProcessing>
|
|
||||||
<profile name="Maven default annotation processors profile" enabled="true">
|
|
||||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
|
||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
|
||||||
<outputRelativeToContentRoot value="true" />
|
|
||||||
<module name="unit-test" />
|
|
||||||
</profile>
|
|
||||||
</annotationProcessing>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="RemoteRepositoriesConfiguration">
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="central" />
|
|
||||||
<option name="name" value="Central Repository" />
|
|
||||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="central" />
|
|
||||||
<option name="name" value="Maven Central repository" />
|
|
||||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="jboss.community" />
|
|
||||||
<option name="name" value="JBoss Community repository" />
|
|
||||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
|
||||||
</remote-repository>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
|
||||||
<component name="MavenProjectsManager">
|
|
||||||
<option name="originalFiles">
|
|
||||||
<list>
|
|
||||||
<option value="$PROJECT_DIR$/pom.xml" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="25" project-jdk-type="JavaSDK" />
|
|
||||||
</project>
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@ -1,93 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="AutoImportSettings">
|
|
||||||
<option name="autoReloadType" value="SELECTIVE" />
|
|
||||||
</component>
|
|
||||||
<component name="ChangeListManager">
|
|
||||||
<list default="true" id="584a2518-0bc5-4360-bc03-3335f62346fb" name="Changes" comment="commit unit-develop" />
|
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
||||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
||||||
</component>
|
|
||||||
<component name="Git.Settings">
|
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectColorInfo">{
|
|
||||||
"customColor": "",
|
|
||||||
"associatedIndex": 6
|
|
||||||
}</component>
|
|
||||||
<component name="ProjectId" id="3HBqDO3prNwKXkNae6M7Qu2HsQk" />
|
|
||||||
<component name="ProjectViewState">
|
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
|
||||||
<option name="showLibraryContents" value="true" />
|
|
||||||
</component>
|
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
|
||||||
"keyToString": {
|
|
||||||
"Maven.unit-test [org.apache.maven.plugins:maven-clean-plugin:3.2.0:clean].executor": "Run",
|
|
||||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
|
||||||
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
|
||||||
"TestNG.NegativeCalculatorTest.negativeTest.executor": "Run",
|
|
||||||
"TestNG.PositiveCalculatorTest.positiveTest.executor": "Run",
|
|
||||||
"git-widget-placeholder": "unit-develop",
|
|
||||||
"kotlin-language-version-configured": "true"
|
|
||||||
}
|
|
||||||
}]]></component>
|
|
||||||
<component name="RunManager" selected="TestNG.NegativeCalculatorTest.negativeTest">
|
|
||||||
<configuration name="NegativeCalculatorTest.negativeTest" type="TestNG" temporary="true" nameIsGenerated="true">
|
|
||||||
<module name="unit-test" />
|
|
||||||
<option name="PACKAGE_NAME" value="" />
|
|
||||||
<option name="MAIN_CLASS_NAME" value="NegativeCalculatorTest" />
|
|
||||||
<option name="METHOD_NAME" value="negativeTest" />
|
|
||||||
<option name="TEST_OBJECT" value="METHOD" />
|
|
||||||
<properties />
|
|
||||||
<listeners />
|
|
||||||
<method v="2">
|
|
||||||
<option name="Make" enabled="true" />
|
|
||||||
</method>
|
|
||||||
</configuration>
|
|
||||||
<configuration name="PositiveCalculatorTest.positiveTest" type="TestNG" temporary="true" nameIsGenerated="true">
|
|
||||||
<module name="unit-test" />
|
|
||||||
<option name="PACKAGE_NAME" value="" />
|
|
||||||
<option name="MAIN_CLASS_NAME" value="PositiveCalculatorTest" />
|
|
||||||
<option name="METHOD_NAME" value="positiveTest" />
|
|
||||||
<option name="TEST_OBJECT" value="METHOD" />
|
|
||||||
<properties />
|
|
||||||
<listeners />
|
|
||||||
<method v="2">
|
|
||||||
<option name="Make" enabled="true" />
|
|
||||||
</method>
|
|
||||||
</configuration>
|
|
||||||
<recent_temporary>
|
|
||||||
<list>
|
|
||||||
<item itemvalue="TestNG.NegativeCalculatorTest.negativeTest" />
|
|
||||||
<item itemvalue="TestNG.PositiveCalculatorTest.positiveTest" />
|
|
||||||
</list>
|
|
||||||
</recent_temporary>
|
|
||||||
</component>
|
|
||||||
<component name="TaskManager">
|
|
||||||
<task active="true" id="Default" summary="Default task">
|
|
||||||
<changelist id="584a2518-0bc5-4360-bc03-3335f62346fb" name="Changes" comment="" />
|
|
||||||
<created>1785351688906</created>
|
|
||||||
<option name="number" value="Default" />
|
|
||||||
<option name="presentableId" value="Default" />
|
|
||||||
<updated>1785351688906</updated>
|
|
||||||
</task>
|
|
||||||
<task id="LOCAL-00001" summary="commit unit-develop">
|
|
||||||
<option name="closed" value="true" />
|
|
||||||
<created>1785410404811</created>
|
|
||||||
<option name="number" value="00001" />
|
|
||||||
<option name="presentableId" value="LOCAL-00001" />
|
|
||||||
<option name="project" value="LOCAL" />
|
|
||||||
<updated>1785410404811</updated>
|
|
||||||
</task>
|
|
||||||
<option name="localTasksCounter" value="2" />
|
|
||||||
<servers />
|
|
||||||
</component>
|
|
||||||
<component name="VcsManagerConfiguration">
|
|
||||||
<MESSAGE value="commit unit-develop" />
|
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="commit unit-develop" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
33
pom.xml
33
pom.xml
@ -1,33 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<groupId>org.example</groupId>
|
|
||||||
<artifactId>unit-test</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<source>8</source>
|
|
||||||
<target>8</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<!-- todo: добавить необходимые зависимости -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.testng</groupId>
|
|
||||||
<artifactId>testng</artifactId>
|
|
||||||
<version>7.10.2</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</project>
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
import model.Calculator;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String[] params = readParams();
|
|
||||||
System.out.println(Calculator.execute(params));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String[] readParams() {
|
|
||||||
// todo: считать из консоли данные, затем вернуть их в виде массива строк
|
|
||||||
Scanner in = new Scanner(System.in);
|
|
||||||
|
|
||||||
String operator = in.nextLine();
|
|
||||||
String value1 = in.nextLine();
|
|
||||||
String value2 = in.nextLine();
|
|
||||||
return new String[]{operator, value1, value2};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,68 +0,0 @@
|
|||||||
package model;
|
|
||||||
|
|
||||||
public class Calculator {
|
|
||||||
|
|
||||||
public static String execute(String[] params) {
|
|
||||||
String operator = params[0];
|
|
||||||
double value1;
|
|
||||||
double value2;
|
|
||||||
// todo: доработать код, чтобы все негативные тесты проходили успешно
|
|
||||||
//value1 = Double.parseDouble(params[1]);
|
|
||||||
//value2 = Double.parseDouble(params[2]);
|
|
||||||
value1 = validDouble(params[1]);
|
|
||||||
value2 = validDouble(params[2]);
|
|
||||||
double result = calculate(operator, value1, value2);
|
|
||||||
if (result > Integer.MAX_VALUE || result < Integer.MIN_VALUE) {
|
|
||||||
throw new CalculatorException("Превышен порог значений");
|
|
||||||
}
|
|
||||||
return String.valueOf(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static double calculate(String operator, double a, double b) {
|
|
||||||
if (operator == null) {
|
|
||||||
throw new CalculatorException("Оператор не может быть null");
|
|
||||||
}
|
|
||||||
switch (operator) {
|
|
||||||
case "+":
|
|
||||||
return add(a, b);
|
|
||||||
case "-":
|
|
||||||
return subst(a, b);
|
|
||||||
case "*":
|
|
||||||
return mult(a, b);
|
|
||||||
case "/":
|
|
||||||
return div(a, b);
|
|
||||||
}
|
|
||||||
throw new CalculatorException("Неизвестный оператор");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static double add(double a, double b) {
|
|
||||||
return a + b;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static double subst(double a, double b) {
|
|
||||||
return a - b;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static double div(double a, double b) {
|
|
||||||
if (b == 0) {
|
|
||||||
throw new CalculatorException();
|
|
||||||
}
|
|
||||||
return a / b;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static double mult(double a, double b) {
|
|
||||||
return a * b;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static double validDouble (String number) throws CalculatorException{
|
|
||||||
if (number == null) {
|
|
||||||
throw new CalculatorException("Число не может быть null");
|
|
||||||
}
|
|
||||||
try{
|
|
||||||
return Double.parseDouble(number);
|
|
||||||
}
|
|
||||||
catch (NumberFormatException e){
|
|
||||||
throw new CalculatorException("Некорректное число: " + number, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
package model;
|
|
||||||
|
|
||||||
public class CalculatorException extends RuntimeException {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -1135355618665392597L;
|
|
||||||
private static final String MESSAGE = "Ошибка вычисления!";
|
|
||||||
|
|
||||||
public CalculatorException() {
|
|
||||||
super(MESSAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CalculatorException(String str) {
|
|
||||||
super(MESSAGE + " " + str);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CalculatorException(Throwable e) {
|
|
||||||
super(MESSAGE, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CalculatorException(String str, Throwable e) {
|
|
||||||
super(MESSAGE + " " + str, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,48 +0,0 @@
|
|||||||
import model.Calculator;
|
|
||||||
import model.CalculatorException;
|
|
||||||
import org.testng.Assert;
|
|
||||||
import org.testng.annotations.DataProvider;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
public class NegativeCalculatorTest {
|
|
||||||
// todo: @DataProvider for negativeData
|
|
||||||
// todo: negative test
|
|
||||||
@DataProvider
|
|
||||||
public Object[][] negativeData(){
|
|
||||||
return new Object [][]{
|
|
||||||
{"+", String.valueOf(Integer.MAX_VALUE), "1"},
|
|
||||||
{"+", String.valueOf(Integer.MIN_VALUE), "-1"},
|
|
||||||
{"*", String.valueOf((double)Integer.MAX_VALUE+1), "2"},
|
|
||||||
{"*", String.valueOf((double)Integer.MIN_VALUE-1), "2"},
|
|
||||||
|
|
||||||
{"/", "10", "0"},
|
|
||||||
|
|
||||||
{"+", "", "5"},
|
|
||||||
{"-", "3", ""},
|
|
||||||
{"*", "", ""},
|
|
||||||
|
|
||||||
{"+", "abc", "5"},
|
|
||||||
{"-", "3", "xyz"},
|
|
||||||
{"*", "12.5a", "3"},
|
|
||||||
{"/", "4", "2.3.5"},
|
|
||||||
|
|
||||||
{"+", "@#$", "5"},
|
|
||||||
{"-", "3", "!@#"},
|
|
||||||
|
|
||||||
{"+", " ", "5"},
|
|
||||||
{"-", "3", " "},
|
|
||||||
|
|
||||||
{"", "10", "5"},
|
|
||||||
{"=", "5", "3"},
|
|
||||||
|
|
||||||
{null, "5", "3"},
|
|
||||||
{"+", null, "3"},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test (dataProvider = "negativeData", expectedExceptions = CalculatorException.class)
|
|
||||||
public void negativeTest(String operator, String a, String b){
|
|
||||||
String[] params = {operator, a, b};
|
|
||||||
Calculator.execute(params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,43 +0,0 @@
|
|||||||
import model.Calculator;
|
|
||||||
import org.testng.Assert;
|
|
||||||
import org.testng.annotations.DataProvider;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
public class PositiveCalculatorTest {
|
|
||||||
// todo: @DataProvider for positiveData
|
|
||||||
// todo: positive test
|
|
||||||
@DataProvider
|
|
||||||
public Object[][] positiveData(){
|
|
||||||
return new Object [][]{
|
|
||||||
{"+", "3", "4", 7.0},
|
|
||||||
{"+", "10.5", "2.3", 12.8},
|
|
||||||
{"+", "-5.5", "3.2", -2.3},
|
|
||||||
|
|
||||||
{"-", "10", "5", 5.0},
|
|
||||||
{"-", "15.7", "3.2", 12.5},
|
|
||||||
{"-", "-2.5", "-1.5", -1.0},
|
|
||||||
|
|
||||||
{"*", "3", "0", 0.0},
|
|
||||||
{"*", "2.5", "4.0", 10.0},
|
|
||||||
{"*", "-3.0", "2.5", -7.5},
|
|
||||||
|
|
||||||
{"/", "10", "2", 5.0},
|
|
||||||
{"/", "15.0", "4.0", 3.75},
|
|
||||||
{"/", "-10.0", "4.0", -2.5},
|
|
||||||
|
|
||||||
|
|
||||||
{"+", String.valueOf(Integer.MAX_VALUE - 1), "1", (double)Integer.MAX_VALUE},
|
|
||||||
{"+", String.valueOf(Integer.MIN_VALUE + 1), "-1", (double)Integer.MIN_VALUE},
|
|
||||||
{"*", String.valueOf(Integer.MIN_VALUE), "1", (double)Integer.MIN_VALUE},
|
|
||||||
{"/", String.valueOf(Integer.MAX_VALUE), "2", (double)Integer.MAX_VALUE/2},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(dataProvider = "positiveData")
|
|
||||||
public void positiveTest(String operator, String a, String b, double expected){
|
|
||||||
String[] params = {operator, a, b};
|
|
||||||
double result = Double.parseDouble(Calculator.execute(params));
|
|
||||||
Assert.assertEquals(result, expected, 0.001);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user