Merge pull request 'unit-develop' (#1) from unit-develop into unit-master
Reviewed-on: paninvaleriy/homework#1
This commit is contained in:
commit
c0b17c384e
13
.idea/compiler.xml
Normal file
13
.idea/compiler.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?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>
|
||||
20
.idea/jarRepositories.xml
Normal file
20
.idea/jarRepositories.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?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>
|
||||
12
.idea/misc.xml
Normal file
12
.idea/misc.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?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,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/temp_calculator" vcs="Git" />
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
93
.idea/workspace.xml
Normal file
93
.idea/workspace.xml
Normal file
@ -0,0 +1,93 @@
|
||||
<?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>
|
||||
6
pom.xml
6
pom.xml
@ -23,5 +23,11 @@
|
||||
|
||||
<dependencies>
|
||||
<!-- todo: добавить необходимые зависимости -->
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<version>7.10.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -10,6 +10,11 @@ public class Main {
|
||||
|
||||
private static String[] readParams() {
|
||||
// todo: считать из консоли данные, затем вернуть их в виде массива строк
|
||||
return null;
|
||||
Scanner in = new Scanner(System.in);
|
||||
|
||||
String operator = in.nextLine();
|
||||
String value1 = in.nextLine();
|
||||
String value2 = in.nextLine();
|
||||
return new String[]{operator, value1, value2};
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,8 +7,10 @@ public class Calculator {
|
||||
double value1;
|
||||
double value2;
|
||||
// todo: доработать код, чтобы все негативные тесты проходили успешно
|
||||
value1 = Double.parseDouble(params[1]);
|
||||
value2 = Double.parseDouble(params[2]);
|
||||
//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("Превышен порог значений");
|
||||
@ -17,6 +19,9 @@ public class Calculator {
|
||||
}
|
||||
|
||||
private static double calculate(String operator, double a, double b) {
|
||||
if (operator == null) {
|
||||
throw new CalculatorException("Оператор не может быть null");
|
||||
}
|
||||
switch (operator) {
|
||||
case "+":
|
||||
return add(a, b);
|
||||
@ -48,4 +53,16 @@ public class Calculator {
|
||||
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,4 +1,48 @@
|
||||
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,4 +1,43 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
BIN
target/classes/Main.class
Normal file
BIN
target/classes/Main.class
Normal file
Binary file not shown.
BIN
target/classes/model/Calculator.class
Normal file
BIN
target/classes/model/Calculator.class
Normal file
Binary file not shown.
BIN
target/classes/model/CalculatorException.class
Normal file
BIN
target/classes/model/CalculatorException.class
Normal file
Binary file not shown.
BIN
target/test-classes/NegativeCalculatorTest.class
Normal file
BIN
target/test-classes/NegativeCalculatorTest.class
Normal file
Binary file not shown.
BIN
target/test-classes/PositiveCalculatorTest.class
Normal file
BIN
target/test-classes/PositiveCalculatorTest.class
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user