Skip to content
Snippets Groups Projects
Commit 8e86b72d authored by Jiawei Wang's avatar Jiawei Wang
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-12">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
/bin/
.project 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>otktest4</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=12
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=12
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=12
class Calculator {
private int result;
public Calculator() {
reset();
}
public void reset() {
this.result = 0;
}
public int getResult() {
return this.result;
}
public void add(int value) {
this.result += value;
}
public void subtract(int value) {
this.result += value;
}
public void multiply(int value) {
for (int i=1; i<value; i++) {
add(value);
}
}
public void exponent(int value) {
for(int i=1; i<value; i++) {
multiply(value);
}
}
}
\ No newline at end of file
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class CalculatorTest {
@Test
void resetTest() {
Calculator cal = new Calculator();
assertTrue(cal.getResult() == 0);
}
@Test
void addTest() {
Calculator cal = new Calculator();
cal.add(1);
assertEquals(1, cal.getResult());
}
@Test
void subtractTest() {
Calculator cal = new Calculator();
cal.subtract(2);
}
@Test
void multiplyTest() {
Calculator cal = new Calculator();
cal.multiply(3);
}
@Test
void exponentTest() {
Calculator cal = new Calculator();
cal.exponent(2);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment