Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kgpMainでの異常系処理を追加 #802

Merged
merged 2 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions example/Abnormals/BuildFailure/kgenprog.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
root-dir = "./"
src = ["src/example/CloseToZero.java"]
test = ["src/example/CloseToZeroTest.java"]

15 changes: 15 additions & 0 deletions example/Abnormals/BuildFailure/src/example/CloseToZero.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package example;

public class CloseToZero {

public int close_to_zero(int n) {
if (n == 0) {
k++; // build failure
} else if (n > 0) {
n--;
} else {
n++;
}
return n;
}
}
26 changes: 26 additions & 0 deletions example/Abnormals/BuildFailure/src/example/CloseToZeroTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package example;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class CloseToZeroTest {
@Test
public void test01() {
assertEquals(9, new CloseToZero().close_to_zero(10));
}

@Test
public void test02() {
assertEquals(99, new CloseToZero().close_to_zero(100));
}

@Test
public void test03() {
assertEquals(0, new CloseToZero().close_to_zero(0));
}

@Test
public void test04() {
assertEquals(-9, new CloseToZero().close_to_zero(-10));
Copy link
Contributor

@hnymA hnymA Dec 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assertEquals(-9, new CloseToZero().close_to_zero(-10));
assertEquals(-9, new CloseToZero().close_to_zero(-8));

じゃないでしょうか

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertEquals は expect, actual の順で書くのでこれで正しい.
Assertj#assertThat は(英語文法とassertjの仕組み上)actual, expect の順で書くので混同しがち.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

すいません,その通りですね
混乱してました

}
}
4 changes: 4 additions & 0 deletions example/Abnormals/NoBugs/kgenprog.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
root-dir = "./"
src = ["src/example/CloseToZero.java"]
test = ["src/example/CloseToZeroTest.java"]

15 changes: 15 additions & 0 deletions example/Abnormals/NoBugs/src/example/CloseToZero.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package example;

public class CloseToZero {

public int close_to_zero(int n) {
if (n == 0) {
; // do nothing, means no bugs
} else if (n > 0) {
n--;
} else {
n++;
}
return n;
}
}
26 changes: 26 additions & 0 deletions example/Abnormals/NoBugs/src/example/CloseToZeroTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package example;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class CloseToZeroTest {
@Test
public void test01() {
assertEquals(9, new CloseToZero().close_to_zero(10));
}

@Test
public void test02() {
assertEquals(99, new CloseToZero().close_to_zero(100));
}

@Test
public void test03() {
assertEquals(0, new CloseToZero().close_to_zero(0));
}

@Test
public void test04() {
assertEquals(-9, new CloseToZero().close_to_zero(-10));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同様

}
}
5 changes: 2 additions & 3 deletions src/main/java/jp/kusumotolab/kgenprog/CUILauncher.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package jp.kusumotolab.kgenprog;

import java.util.List;
import java.util.Random;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.Level;
import jp.kusumotolab.kgenprog.KGenProgMain.ExitStatus;
import jp.kusumotolab.kgenprog.fl.FaultLocalization;
import jp.kusumotolab.kgenprog.ga.codegeneration.DefaultSourceCodeGeneration;
import jp.kusumotolab.kgenprog.ga.codegeneration.SourceCodeGeneration;
Expand All @@ -19,7 +19,6 @@
import jp.kusumotolab.kgenprog.ga.selection.VariantSelection;
import jp.kusumotolab.kgenprog.ga.validation.DefaultCodeValidation;
import jp.kusumotolab.kgenprog.ga.validation.SourceCodeValidation;
import jp.kusumotolab.kgenprog.ga.variant.Variant;
import jp.kusumotolab.kgenprog.output.Exporters;
import jp.kusumotolab.kgenprog.project.test.LocalTestExecutor;
import jp.kusumotolab.kgenprog.project.test.TestExecutor;
Expand All @@ -38,7 +37,7 @@ public static void main(final String[] args) {
}
}

public List<Variant> launch(final Configuration config) {
public ExitStatus launch(final Configuration config) {
setLogLevel(config.getLogLevel());

final FaultLocalization faultLocalization = config.getFaultLocalization()
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/jp/kusumotolab/kgenprog/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.kohsuke.args4j.spi.StringArrayOptionHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.electronwill.nightconfig.core.UnmodifiableConfig.Entry;
import com.electronwill.nightconfig.core.conversion.Conversion;
import com.electronwill.nightconfig.core.conversion.Converter;
import com.electronwill.nightconfig.core.conversion.InvalidValueException;
Expand Down Expand Up @@ -334,14 +335,12 @@ private Builder() {
testPaths = new ArrayList<>();
}

public static Configuration buildFromCmdLineArgs(final String[] args)
throws IllegalArgumentException {
public static Configuration buildFromCmdLineArgs(final String[] args) {
final Builder builder = createFromCmdLineArgs(args);
return builder.build();
}

public static Builder createFromCmdLineArgs(final String[] args)
throws IllegalArgumentException {
public static Builder createFromCmdLineArgs(final String[] args) {

final Builder builder = new Builder();
final CmdLineParser parser = new CmdLineParser(builder);
Expand Down Expand Up @@ -503,19 +502,19 @@ public Builder setHistoryRecord(final boolean historyRecord) {
return this;
}

private static void validateArgument(final Builder builder) throws IllegalArgumentException {
private static void validateArgument(final Builder builder) {
validateExistences(builder);
validateCurrentDir(builder);
}

private static void validateExistences(final Builder builder) throws IllegalArgumentException {
private static void validateExistences(final Builder builder) {
validateExistence(builder.rootDir);
builder.productPaths.forEach(Builder::validateExistence);
builder.testPaths.forEach(Builder::validateExistence);
builder.classPaths.forEach(Builder::validateExistence);
}

private static void validateExistence(final Path path) throws IllegalArgumentException {
private static void validateExistence(final Path path) {
if (Files.notExists(path)) {
log.error(path.toString() + " does not exist.");
throw new IllegalArgumentException(path.toString() + " does not exist.");
Expand Down Expand Up @@ -549,7 +548,7 @@ private static boolean needsParseConfigFile(final String[] args) {
.contains("--config");
}

private void parseConfigFile() throws InvalidValueException, NoSuchFileException {
private void parseConfigFile() throws NoSuchFileException {
try (final FileConfig config = loadConfig()) {
final ObjectConverter converter = new ObjectConverter();
converter.toObject(config, this);
Expand All @@ -563,7 +562,7 @@ private void findOptionsSetInConfigFile() throws NoSuchFileException {
// 設定ファイルに記述されているオプション一覧を取得
final Set<String> optionNames = config.entrySet()
.stream()
.map(o -> o.getKey())
.map(Entry::getKey)
.collect(Collectors.toSet());

final Class<?> clazz = this.getClass();
Expand Down
Loading