diff --git a/Experiment.pdf b/Experiment.pdf new file mode 100644 index 0000000..62ae075 Binary files /dev/null and b/Experiment.pdf differ diff --git a/experiment1/.classpath b/experiment1/.classpath new file mode 100644 index 0000000..df66b20 --- /dev/null +++ b/experiment1/.classpath @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/experiment1/.project b/experiment1/.project new file mode 100644 index 0000000..7458a5b --- /dev/null +++ b/experiment1/.project @@ -0,0 +1,34 @@ + + + experiment1 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + + + 1733408540557 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/experiment1/.settings/org.eclipse.jdt.apt.core.prefs b/experiment1/.settings/org.eclipse.jdt.apt.core.prefs new file mode 100644 index 0000000..d4313d4 --- /dev/null +++ b/experiment1/.settings/org.eclipse.jdt.apt.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.apt.aptEnabled=false diff --git a/experiment1/.settings/org.eclipse.jdt.core.prefs b/experiment1/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..a4e59d9 --- /dev/null +++ b/experiment1/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.processAnnotations=disabled +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/experiment1/.settings/org.eclipse.m2e.core.prefs b/experiment1/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/experiment1/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/experiment1/pom.xml b/experiment1/pom.xml new file mode 100644 index 0000000..fc31704 --- /dev/null +++ b/experiment1/pom.xml @@ -0,0 +1,50 @@ + + 4.0.0 + com.example + experiment1 + 1.0-SNAPSHOT + + + + 17 + 17 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 17 + + + + org.codehaus.mojo + exec-maven-plugin + 3.1.0 + + com.example.App + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M7 + + + + + + + + org.junit.jupiter + junit-jupiter + 5.10.0 + test + + + diff --git a/experiment1/report.md b/experiment1/report.md new file mode 100644 index 0000000..45a12ba --- /dev/null +++ b/experiment1/report.md @@ -0,0 +1,93 @@ +# Decision Table +|-----------------+------------+---------------+------------------------| +| number_of_items | total_cost | delivery_time | cost | +|-----------------+------------+---------------+------------------------| +| <= 3 | <= 100 | NEXT_DAY | 25 | +|-----------------+------------+---------------+------------------------| +| <=3 | <= 100 | SECOND_DAY | 10 | +|-----------------+------------+---------------+------------------------| +| <= 3 | <= 100 | THIS_WEEK | number_of_items * 1.50 | +|-----------------+------------+---------------+------------------------| +| <= 3 | > 100 | NEXT_DAY | 35.00 | +|-----------------+------------+---------------+------------------------| +| <= 3 | > 100 | SECOND_DAY | 15.00 | +|-----------------+------------+---------------+------------------------| +| <= 3 | > 100 | THIS_WEEK | 10.00 | +|-----------------+------------+---------------+------------------------| +| > 3 | <= 100 | NEXT_DAY | number_of_items * 6.00 | +|-----------------+------------+---------------+------------------------| +| > 3 | <= 100 | SECOND_DAY | number_of_items * 2.50 | +|-----------------+------------+---------------+------------------------| +| > 3 | <= 100 | THIS_WEEK | 0.00 | +|-----------------+------------+---------------+------------------------| +| > 3 | > 100 | NEXT_DAY | number_of_items * 7.50 | +|-----------------+------------+---------------+------------------------| +| > 3 | > 100 | SECOND_DAY | number_of_items * 3.50 | +|-----------------+------------+---------------+------------------------| +| > 3 | > 100 | THIS_WEEK | number_of_items * 2.50 | +|-----------------+------------+---------------+------------------------| + +time take to generate this : 14.20 min (including song selection 😜 ) + + +# Equivalance testing: + +## Input parameters: +* number of item + * Positive integers are the valid values. +* total cost + * Positive numbers are the valid values. +* delivery time + * NEXT_DAY , SECOND_DAY and THIS_WEEK are the valid values. + + +## Equivalance partitions + +|-----------------|----------------|---------------------------------|----------------| +| Input | Partition Type | Partition Condition | Selected Value | +|-----------------|----------------|---------------------------------|----------------| +| number_of_items | Valid | <= 3 | 3 | +| | Valid | > 3 | 4 | +| | Invalid | <= 0 | -1 | +|-----------------|----------------|---------------------------------|----------------| +| total_cost | Valid | <= 100 | 100 | +| | Valid | > 100 | 101 | +| | Invalid | < 0 | -2 | +|-----------------|----------------|---------------------------------|----------------| +| delivery_time | Valid | NEXT_DAY, SECOND_DAY, THIS_WEEK | SECOND_DAY | +| | Invalid | Null or unsupported value | null | +|-----------------|----------------|---------------------------------|----------------| + +## Test cases + +|-----------|-----------------|------------|---------------|------------------|---------------------------------| +| Test Case | number_of_items | total_cost | delivery_time | Partition Type | Expected Outcome | +|-----------|-----------------|------------|---------------|------------------|---------------------------------| +| 1 | 3 | 100 | NEXT_DAY | All Valid | 25.00 | +| 2 | 3 | 150 | SECOND_DAY | All Valid | 15.00 | +| 3 | 4 | 100 | THIS_WEEK | All Valid | 0.00 | +| 4 | 4 | 150 | NEXT_DAY | All Valid | 30.00 | +| 5 | -1 | 100 | NEXT_DAY | Invalid Items | Exception | +| 6 | 3 | -50 | SECOND_DAY | Invalid Cost | Exception | +| 7 | 3 | 100 | null | Invalid Delivery | Exception | +|-----------|-----------------|------------|---------------|------------------|---------------------------------| + +# Boundary Value + +|-----------------|------------| +| Input | Boundaries | +|-----------------|------------| +| number_of_items | -1 | +| | 0 | +| | 1 | +| | 3 | +| | 4 | +|-----------------|------------| +| total_cost | -1 | +| | 0 | +| | 1 | +| | 100 | +| | 101 | +|-----------------|------------| +| delivery_time | n/a | +|-----------------|------------| diff --git a/experiment1/src/main/java/com/example/App.java b/experiment1/src/main/java/com/example/App.java new file mode 100644 index 0000000..091ec2a --- /dev/null +++ b/experiment1/src/main/java/com/example/App.java @@ -0,0 +1,11 @@ +package com.example; +import com.example.DecisionTable; + +public class App +{ + public static void main( String[] args ) + { + System.out.println("helo"); + + } +} diff --git a/experiment1/src/main/java/com/example/DecisionTable.java b/experiment1/src/main/java/com/example/DecisionTable.java new file mode 100644 index 0000000..733bd74 --- /dev/null +++ b/experiment1/src/main/java/com/example/DecisionTable.java @@ -0,0 +1,81 @@ +package com.example; + +public class DecisionTable { + + private static final int purchase_amount_limit = 100; + private static final int number_of_items_limit = 3; + + + public Double calculate_costs(final int number_of_items, final double total_cost, final SHIPPING_TIME delivery_time) { + if (number_of_items <= 0 || total_cost <= 0) { + throw new IllegalArgumentException("Unsupported value"); + } + switch (delivery_time) { + case NEXT_DAY: + return calculate_next_day_delivery_cost(number_of_items,total_cost); + case SECOND_DAY: + return calculate_second_day_delivery_cost(number_of_items,total_cost); + case THIS_WEEK: + return calculate_week_delivery_cost(number_of_items,total_cost); + default: + throw new UnsupportedOperationException("Unsupported option: " + delivery_time); + } + } + + public double calculate_next_day_delivery_cost(final int number_of_items, final double total_cost) { + + if (total_cost > 100) { + if (number_of_items > 3) { + return number_of_items * 7.50; + } else { + return 35.00; + } + + } else { + if (number_of_items > 3) { + return number_of_items * 6.00; + } else { + return 25; + } + + } + } + + public double calculate_second_day_delivery_cost(final int number_of_items, final double total_cost) { + + if (total_cost > 100) { + if (number_of_items > 3) { + return number_of_items * 3.50; + } else { + return 15; + } + + } else { + if (number_of_items > 3) { + return number_of_items * 2.50; + } else { + return 10; + } + + } + } + + public double calculate_week_delivery_cost(final int number_of_items, final double total_cost) { + + if (total_cost > 100) { + if (number_of_items > 3) { + return number_of_items * 2.50; + } else { + return 10.00; + } + + } else { + if (number_of_items > 3) { + return 0; + } else { + return number_of_items * 1.50; + } + + } + } +} diff --git a/experiment1/src/main/java/com/example/SHIPPING_TIME.java b/experiment1/src/main/java/com/example/SHIPPING_TIME.java new file mode 100644 index 0000000..64039ea --- /dev/null +++ b/experiment1/src/main/java/com/example/SHIPPING_TIME.java @@ -0,0 +1,7 @@ +package com.example; + +public enum SHIPPING_TIME { + NEXT_DAY, + SECOND_DAY, + THIS_WEEK +} diff --git a/experiment1/src/test/java/com/example/AppTest.java b/experiment1/src/test/java/com/example/AppTest.java new file mode 100644 index 0000000..6e5b3b7 --- /dev/null +++ b/experiment1/src/test/java/com/example/AppTest.java @@ -0,0 +1,157 @@ +package com.example; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.List; +import java.util.ArrayList; + +public class AppTest { + + public class Test_scenario { + public double total_cost; + public int number_of_items; + public SHIPPING_TIME delivery_time; + public double exp_cost; + + public Test_scenario(double total_cost, + int number_of_items, + SHIPPING_TIME delivery_time, + double exp_cost) { + this.total_cost = total_cost; + this.number_of_items = number_of_items; + this.delivery_time = delivery_time; + this.exp_cost = exp_cost; + } + + } + + + /** + * Took 26 min to write tests, mvn execution time was + * mvn test 4.59s user 0.31s system 456% cpu 1.073 total + * According to mvn test took + * Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.008 sec + * generated cases: 12 + */ + @Test + public void decision_table_testing() { + DecisionTable dt = new DecisionTable(); + + List scenarios = new ArrayList<>(); + scenarios.add(new Test_scenario(100.0,3,SHIPPING_TIME.NEXT_DAY,25.0)); + scenarios.add(new Test_scenario(100.0,3,SHIPPING_TIME.SECOND_DAY,10.0)); + scenarios.add(new Test_scenario(100.0,3,SHIPPING_TIME.THIS_WEEK,4.5)); + scenarios.add(new Test_scenario(150.0,3,SHIPPING_TIME.NEXT_DAY,35.0)); + scenarios.add(new Test_scenario(150.0,3,SHIPPING_TIME.SECOND_DAY,15.0)); + scenarios.add(new Test_scenario(150.0,3,SHIPPING_TIME.THIS_WEEK,10.0)); + scenarios.add(new Test_scenario(100.0,6,SHIPPING_TIME.NEXT_DAY,36.0)); + scenarios.add(new Test_scenario(100.0,6,SHIPPING_TIME.SECOND_DAY,15.0)); + scenarios.add(new Test_scenario(100.0,6,SHIPPING_TIME.THIS_WEEK,0.0)); + scenarios.add(new Test_scenario(150.0,6,SHIPPING_TIME.NEXT_DAY,45.0)); + scenarios.add(new Test_scenario(150.0,6,SHIPPING_TIME.SECOND_DAY,21.0)); + scenarios.add(new Test_scenario(150.0,6,SHIPPING_TIME.THIS_WEEK,15.0)); + + for (Test_scenario scenario : scenarios) { + assertEquals(scenario.exp_cost, + dt.calculate_costs(scenario.number_of_items, + scenario.total_cost, + scenario.delivery_time), + 0.01, + String.format("Failed for Items: %d, Cost: %.2f, Delivery: %s", + scenario.number_of_items, scenario.total_cost, + scenario.delivery_time)); + } + + } + + /** + * Took 40 minutes to create and implement tests + * mvn test 6.49s user 0.32s system 474% cpu 1.435 total + * Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.028 s - in com.example.AppTest + * generated cases: 7 + */ + @Test + public void equivalance_testing() { + + DecisionTable dt = new DecisionTable(); + + List valid_scenarios = new ArrayList<>(); + List invalid_scenarios = new ArrayList<>(); + valid_scenarios.add(new Test_scenario(100.0,3,SHIPPING_TIME.NEXT_DAY,25.0)); + valid_scenarios.add(new Test_scenario(150.0,3,SHIPPING_TIME.SECOND_DAY,15.0)); + valid_scenarios.add(new Test_scenario(100.0,4,SHIPPING_TIME.THIS_WEEK,0.0)); + valid_scenarios.add(new Test_scenario(150.0,4,SHIPPING_TIME.NEXT_DAY,30.0)); + + invalid_scenarios.add(new Test_scenario(100.0,-1,SHIPPING_TIME.NEXT_DAY,0)); + invalid_scenarios.add(new Test_scenario(-50.0,3,SHIPPING_TIME.SECOND_DAY,0)); + invalid_scenarios.add(new Test_scenario(100.0,3,null,0)); + + for (Test_scenario scenario : valid_scenarios) { + assertEquals(scenario.exp_cost, + dt.calculate_costs(scenario.number_of_items, + scenario.total_cost, + scenario.delivery_time), + 0.01, + String.format("Failed for Items: %d, Cost: %.2f, Delivery: %s", + scenario.number_of_items, scenario.total_cost, + scenario.delivery_time)); + } + + for (Test_scenario scenario : invalid_scenarios) { + assertThrows(Throwable.class, () -> dt.calculate_costs( + scenario.number_of_items, + scenario.total_cost, + scenario.delivery_time), + String.format("Failed for Items: %d, Cost: %.2f, Delivery: %s", + scenario.number_of_items, scenario.total_cost, + scenario.delivery_time)); + } + } + + /** + * Took 24 minutes to create and implement tests + * mvn test 7.01s user 0.31s system 503% cpu 1.454 total + * Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.026 s - in com.example.AppTest + * generated cases: 9 + */ + @Test + public void boundary_value_testing() { + + DecisionTable dt = new DecisionTable(); + List valid_scenarios = new ArrayList<>(); + List invalid_scenarios = new ArrayList<>(); + invalid_scenarios.add(new Test_scenario(100.0,-1,SHIPPING_TIME.NEXT_DAY,25.0)); + invalid_scenarios.add(new Test_scenario(100.0,0,SHIPPING_TIME.NEXT_DAY,25.0)); + valid_scenarios.add(new Test_scenario(100.0,1,SHIPPING_TIME.NEXT_DAY,25.0)); + valid_scenarios.add(new Test_scenario(100.0,3,SHIPPING_TIME.NEXT_DAY,25.0)); + valid_scenarios.add(new Test_scenario(100.0,4,SHIPPING_TIME.NEXT_DAY,24.0)); + invalid_scenarios.add(new Test_scenario(-1.0,1,SHIPPING_TIME.NEXT_DAY,25.0)); + invalid_scenarios.add(new Test_scenario(0.0,1,SHIPPING_TIME.NEXT_DAY,25.0)); + valid_scenarios.add(new Test_scenario(1.0,3,SHIPPING_TIME.NEXT_DAY,25.0)); + valid_scenarios.add(new Test_scenario(101.0,3,SHIPPING_TIME.NEXT_DAY,35.0)); + + for (Test_scenario scenario : valid_scenarios) { + assertEquals(scenario.exp_cost, + dt.calculate_costs(scenario.number_of_items, + scenario.total_cost, + scenario.delivery_time), + 0.01, + String.format("Failed for Items: %d, Cost: %.2f, Delivery: %s", + scenario.number_of_items, scenario.total_cost, + scenario.delivery_time)); + } + + for (Test_scenario scenario : invalid_scenarios) { + assertThrows(Throwable.class, () -> dt.calculate_costs( + scenario.number_of_items, + scenario.total_cost, + scenario.delivery_time), + String.format("Failed for Items: %d, Cost: %.2f, Delivery: %s", + scenario.number_of_items, scenario.total_cost, + scenario.delivery_time)); + } + + } +} diff --git a/experiment1/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/experiment1/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..169815a --- /dev/null +++ b/experiment1/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,4 @@ +com/example/DecisionTable$1.class +com/example/App.class +com/example/DecisionTable.class +com/example/SHIPPING_TIME.class diff --git a/experiment1/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/experiment1/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..9d2e237 --- /dev/null +++ b/experiment1/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,3 @@ +/home/alican/school/test/experiment/experiment1/src/main/java/com/example/SHIPPING_TIME.java +/home/alican/school/test/experiment/experiment1/src/main/java/com/example/App.java +/home/alican/school/test/experiment/experiment1/src/main/java/com/example/DecisionTable.java diff --git a/experiment1/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/experiment1/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..779285c --- /dev/null +++ b/experiment1/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1,2 @@ +com/example/AppTest$Test_scenario.class +com/example/AppTest.class diff --git a/experiment1/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/experiment1/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..c2fad47 --- /dev/null +++ b/experiment1/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +/home/alican/school/test/experiment/experiment1/src/test/java/com/example/AppTest.java diff --git a/experiment1/target/surefire-reports/TEST-com.example.AppTest.xml b/experiment1/target/surefire-reports/TEST-com.example.AppTest.xml new file mode 100644 index 0000000..85f7bcc --- /dev/null +++ b/experiment1/target/surefire-reports/TEST-com.example.AppTest.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/experiment1/target/surefire-reports/com.example.AppTest.txt b/experiment1/target/surefire-reports/com.example.AppTest.txt new file mode 100644 index 0000000..5d907d5 --- /dev/null +++ b/experiment1/target/surefire-reports/com.example.AppTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: com.example.AppTest +------------------------------------------------------------------------------- +Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.03 s - in com.example.AppTest