diff --git a/.project b/.project new file mode 100644 index 0000000000000000000000000000000000000000..89e3f8e7035bf51fee3ae0eafbd3b1a213ed35d0 --- /dev/null +++ b/.project @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>soft160--homework</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + </buildSpec> + <natures> + </natures> +</projectDescription> diff --git a/homework-6.4/conditionals_homework/.classpath b/homework-6.4/conditionals_homework/.classpath new file mode 100755 index 0000000000000000000000000000000000000000..b698c368b041cd9d3c397cd13e53c6db78cd55d9 --- /dev/null +++ b/homework-6.4/conditionals_homework/.classpath @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" output="target/classes" path="src/main/java"> + <attributes> + <attribute name="optional" value="true"/> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="src" output="target/test-classes" path="src/test/java"> + <attributes> + <attribute name="optional" value="true"/> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> + <classpathentry kind="output" path="target/classes"/> +</classpath> diff --git a/homework-6.4/conditionals_homework/.gitignore b/homework-6.4/conditionals_homework/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..d2bfa81407cdf56bce05020d533f920fb90f8400 --- /dev/null +++ b/homework-6.4/conditionals_homework/.gitignore @@ -0,0 +1,10 @@ +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.DS_Store diff --git a/homework-6.4/conditionals_homework/.project b/homework-6.4/conditionals_homework/.project new file mode 100755 index 0000000000000000000000000000000000000000..d746603641ced56bc38a460af8e9f9771f2d80dc --- /dev/null +++ b/homework-6.4/conditionals_homework/.project @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>conditionals_homework</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.m2e.core.maven2Builder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>org.eclipse.m2e.core.maven2Nature</nature> + </natures> +</projectDescription> diff --git a/homework-6.4/conditionals_homework/.settings/org.eclipse.jdt.core.prefs b/homework-6.4/conditionals_homework/.settings/org.eclipse.jdt.core.prefs new file mode 100755 index 0000000000000000000000000000000000000000..714351aec195a9a572640e6844dcafd51565a2a5 --- /dev/null +++ b/homework-6.4/conditionals_homework/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/homework-6.4/conditionals_homework/.settings/org.eclipse.m2e.core.prefs b/homework-6.4/conditionals_homework/.settings/org.eclipse.m2e.core.prefs new file mode 100755 index 0000000000000000000000000000000000000000..f897a7f1cb2389f85fe6381425d29f0a9866fb65 --- /dev/null +++ b/homework-6.4/conditionals_homework/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/homework-6.4/conditionals_homework/documentation/.gitignore b/homework-6.4/conditionals_homework/documentation/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/homework-6.4/conditionals_homework/documentation/AutonomousCarCoverage.png b/homework-6.4/conditionals_homework/documentation/AutonomousCarCoverage.png new file mode 100644 index 0000000000000000000000000000000000000000..d8fb4cfddbcf41f5953e55324e1363eb6145683b Binary files /dev/null and b/homework-6.4/conditionals_homework/documentation/AutonomousCarCoverage.png differ diff --git a/homework-6.4/conditionals_homework/documentation/MembershipCoverage.png b/homework-6.4/conditionals_homework/documentation/MembershipCoverage.png new file mode 100644 index 0000000000000000000000000000000000000000..2134dfe0d0a9717ff1f250d604ec28817ac683da Binary files /dev/null and b/homework-6.4/conditionals_homework/documentation/MembershipCoverage.png differ diff --git a/homework-6.4/conditionals_homework/documentation/ScrambleCoverage.png b/homework-6.4/conditionals_homework/documentation/ScrambleCoverage.png new file mode 100644 index 0000000000000000000000000000000000000000..d0c188c09abf687a0b30784c5bd248f4db038b88 Binary files /dev/null and b/homework-6.4/conditionals_homework/documentation/ScrambleCoverage.png differ diff --git a/homework-6.4/conditionals_homework/pom.xml b/homework-6.4/conditionals_homework/pom.xml new file mode 100755 index 0000000000000000000000000000000000000000..05771d8a295295dd061bc0389f5c27284a1f4962 --- /dev/null +++ b/homework-6.4/conditionals_homework/pom.xml @@ -0,0 +1,32 @@ +<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/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>edu.unl.cse.soft160.conditionals</groupId> + <artifactId>conditionals</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + <name>conditionals</name> + <url>http://maven.apache.org</url> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + </plugins> + </pluginManagement> + </build> +</project> diff --git a/homework-6.4/conditionals_homework/src/main/java/edu/unl/cse/soft160/conditionals/AutonomousCar.java b/homework-6.4/conditionals_homework/src/main/java/edu/unl/cse/soft160/conditionals/AutonomousCar.java new file mode 100755 index 0000000000000000000000000000000000000000..2c7d1c5c6759d27c9fb1f296e7bb335e330a5b16 --- /dev/null +++ b/homework-6.4/conditionals_homework/src/main/java/edu/unl/cse/soft160/conditionals/AutonomousCar.java @@ -0,0 +1,26 @@ +package edu.unl.cse.soft160.conditionals; + +import java.util.Scanner; + +//Christian Lampe +//The code looks at each of the inputs to check to see if any of them evaluate to false. +//If any of them evaluate to false, it prints start breaking +//If none of them are false, then they are all true so it prints continue driving. + +public class AutonomousCar { + public static void main(String... arguments) { + Scanner scanner = new Scanner(System.in); + System.out.print("Has an obstacle been detected (yes/no)? "); + boolean obstacle = scanner.nextLine().matches("[Yy].*"); + System.out.print("Is the car approaching a red light (yes/no)? "); + boolean redLight = scanner.nextLine().matches("[Yy].*"); + System.out.print("Does the driver want to stop (yes/no)? "); + boolean driverRequest = scanner.nextLine().matches("[Yy].*"); + if (obstacle == true || redLight == true || driverRequest == true) { + System.out.print("Start braking\n"); + }else { + System.out.print("Continue\n"); + } + scanner.close(); + } +} diff --git a/homework-6.4/conditionals_homework/src/main/java/edu/unl/cse/soft160/conditionals/Membership.java b/homework-6.4/conditionals_homework/src/main/java/edu/unl/cse/soft160/conditionals/Membership.java new file mode 100755 index 0000000000000000000000000000000000000000..38153db0e9c348f31953ad28d3636aa79b55ca6f --- /dev/null +++ b/homework-6.4/conditionals_homework/src/main/java/edu/unl/cse/soft160/conditionals/Membership.java @@ -0,0 +1,29 @@ +package edu.unl.cse.soft160.conditionals; + +import java.util.Scanner; + +public class Membership { + public static void main(String... arguments) { + Scanner scanner = new Scanner(System.in); + System.out.print("How long has the customer been a member for (in years)? "); + double membershipDuration = Double.parseDouble(scanner.nextLine()); + System.out.print("Has the member spent at least $10K each year in the past 2 years (yes/no)? "); + boolean highSpender = scanner.nextLine().matches("[Yy].*"); + System.out.print("Has the member accumulated at least 5,000 reward points (yes/no)? "); + boolean rewardPoints = scanner.nextLine().matches("[Yy].*"); + // [write code here] + if (membershipDuration == 2 && highSpender == true) { + System.out.print("VIP Member\n"); + } + else if (membershipDuration >= 6 && rewardPoints == true) { + System.out.print("VIP Member\n"); + } + else if (membershipDuration >= 12) { + System.out.print("VIP Member\n"); + } + else { + System.out.print("Member\n"); + } + scanner.close(); + } +} diff --git a/homework-6.4/conditionals_homework/src/main/java/edu/unl/cse/soft160/conditionals/Scramble.java b/homework-6.4/conditionals_homework/src/main/java/edu/unl/cse/soft160/conditionals/Scramble.java new file mode 100755 index 0000000000000000000000000000000000000000..a583a66f070717018e40b9673ffad9ea22feb46d --- /dev/null +++ b/homework-6.4/conditionals_homework/src/main/java/edu/unl/cse/soft160/conditionals/Scramble.java @@ -0,0 +1,51 @@ +package edu.unl.cse.soft160.conditionals; + +import java.util.Scanner; + +//Christian Lampe +//The code looks at the side lengths of different triangles to determine which type of triangle they are. +//If all sides are equal, it is a regular triangle, if two are the same, it is a symmetric triangle. +//If none of the sides are equal, it is a irregular triangle. + +public class Scramble { + public static void main(String... arguments) { + Scanner scanner = new java.util.Scanner(System.in); + System.out.print("Enter length of the first edge: "); + int firstEdge = Integer.parseInt(scanner.nextLine()); + System.out.print("Enter length of the second edge: "); + int secondEdge = Integer.parseInt(scanner.nextLine()); + System.out.print("Enter length of the third edge: "); + int thirdEdge = Integer.parseInt(scanner.nextLine()); + if (firstEdge == thirdEdge) { + if (secondEdge == thirdEdge) { + System.out.println("The triangle is regular."); + } else { + System.out.println("The triangle is symmetric."); + } + } else { + if (firstEdge == secondEdge) { + System.out.println("The triangle is symmetric."); + + } else { + System.out.println("The triangle is irregular."); + + } + if (secondEdge == thirdEdge) { + System.out.println("The triangle is symmetric."); + } else { + + + + + + + + + + + + scanner.close(); + } + } + } +} diff --git a/homework-6.4/conditionals_homework/src/test/java/edu/unl/cse/soft160/conditionals/AutonomousCarTest.java b/homework-6.4/conditionals_homework/src/test/java/edu/unl/cse/soft160/conditionals/AutonomousCarTest.java new file mode 100644 index 0000000000000000000000000000000000000000..83b51595e4116379a41eaa0aa943fbbd126d15ab --- /dev/null +++ b/homework-6.4/conditionals_homework/src/test/java/edu/unl/cse/soft160/conditionals/AutonomousCarTest.java @@ -0,0 +1,94 @@ +package edu.unl.cse.soft160.conditionals; + +import static org.junit.Assert.*; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.PrintStream; + +import org.junit.Test; + +public class AutonomousCarTest { + + protected static String assemble(String... lines) { + return String.join("\n", lines) + "\n"; + } + + protected static String runMain(String... inputs) { + InputStream in = System.in; + PrintStream out = System.out; + System.setIn(new ByteArrayInputStream(assemble(inputs).getBytes())); + ByteArrayOutputStream collector = new ByteArrayOutputStream(); + System.setOut(new PrintStream(collector)); + AutonomousCar.main(); + System.setIn(in); + System.setOut(out); + return collector.toString(); + } + + @Test + public void testContinueWithNoReason() { + assertEquals( + assemble("Has an obstacle been detected (yes/no)? " + "Is the car approaching a red light (yes/no)? " + + "Does the driver want to stop (yes/no)? " + "Continue"), + runMain("no", "no", "no")); + } + + @Test + public void testBrakeWithDriverRequest() { + assertEquals( + assemble("Has an obstacle been detected (yes/no)? " + "Is the car approaching a red light (yes/no)? " + + "Does the driver want to stop (yes/no)? " + "Start braking"), + runMain("no", "no", "yes")); + } + + @Test + public void testBrakeWithRedLight() { + assertEquals( + assemble("Has an obstacle been detected (yes/no)? " + "Is the car approaching a red light (yes/no)? " + + "Does the driver want to stop (yes/no)? " + "Start braking"), + runMain("no", "yes", "no")); + } + + @Test + public void testBrakeWithNoObstacle() { + assertEquals( + assemble("Has an obstacle been detected (yes/no)? " + "Is the car approaching a red light (yes/no)? " + + "Does the driver want to stop (yes/no)? " + "Start braking"), + runMain("no", "yes", "yes")); + } + + @Test + public void testBrakeWithObstacle() { + assertEquals( + assemble("Has an obstacle been detected (yes/no)? " + "Is the car approaching a red light (yes/no)? " + + "Does the driver want to stop (yes/no)? " + "Start braking"), + runMain("yes", "no", "no")); + } + + @Test + public void testBrakeWithNoRedLight() { + assertEquals( + assemble("Has an obstacle been detected (yes/no)? " + "Is the car approaching a red light (yes/no)? " + + "Does the driver want to stop (yes/no)? " + "Start braking"), + runMain("yes", "no", "yes")); + } + + @Test + public void testBrakeWithNoDriverRequest() { + assertEquals( + assemble("Has an obstacle been detected (yes/no)? " + "Is the car approaching a red light (yes/no)? " + + "Does the driver want to stop (yes/no)? " + "Start braking"), + runMain("yes", "yes", "no")); + } + + @Test + public void testBrakeWithAllReason() { + assertEquals( + assemble("Has an obstacle been detected (yes/no)? " + "Is the car approaching a red light (yes/no)? " + + "Does the driver want to stop (yes/no)? " + "Start braking"), + runMain("yes", "yes", "yes")); + } + +} diff --git a/homework-6.4/conditionals_homework/src/test/java/edu/unl/cse/soft160/conditionals/MembershipTest.java b/homework-6.4/conditionals_homework/src/test/java/edu/unl/cse/soft160/conditionals/MembershipTest.java new file mode 100644 index 0000000000000000000000000000000000000000..ca6f91e29cdb6342dc9cdaae8244fa57e10358de --- /dev/null +++ b/homework-6.4/conditionals_homework/src/test/java/edu/unl/cse/soft160/conditionals/MembershipTest.java @@ -0,0 +1,290 @@ +package edu.unl.cse.soft160.conditionals; + +import static org.junit.Assert.*; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.PrintStream; + +import org.junit.Test; + +public class MembershipTest { + + protected static String assemble(String... lines) { + return String.join("\n", lines) + "\n"; + } + + protected static String runMain(String... inputs) { + InputStream in = System.in; + PrintStream out = System.out; + System.setIn(new ByteArrayInputStream(assemble(inputs).getBytes())); + ByteArrayOutputStream collector = new ByteArrayOutputStream(); + System.setOut(new PrintStream(collector)); + Membership.main(); + System.setIn(in); + System.setOut(out); + return collector.toString(); + } + + // LESS THAN 2 YEARS OF MEMBERSHIP + @Test + public void testMembershipWithNoRequirementMet() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"), + runMain("1", "no", "no")); + } + + @Test + public void testMembershipWithFewYearsAndRewards() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"), + runMain("1", "no", "yes")); + } + + @Test + public void testMembershipWithFewYearsAndSpending() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"), + runMain("1", "yes", "no")); + } + + @Test + public void testMembershipWithFewYears() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"), + runMain("1", "yes", "yes")); + } + + // 2 YEARS OF MEMBERSHIP + @Test + public void testMembershipWith2Years() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"), + runMain("2", "no", "no")); + } + + @Test + public void testMembershipWith2YearsNoSpending() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"), + runMain("2", "no", "yes")); + } + + @Test + public void testMembershipWith2YearsNoRewards() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"), + runMain("2", "yes", "no")); + } + + @Test + public void testMembershipWith2YearsAndAll() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"), + runMain("2", "yes", "yes")); + } + + // BETWEEN 2 AND 6 YEARS OF MEMBERSHIP + @Test + public void testMembershipBetween2And6Years() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"), + runMain("3", "no", "no")); + } + + @Test + public void testMembershipBetween2And6YearsNoSpending() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"), + runMain("3", "no", "yes")); + } + + @Test + public void testMembershipBetween2And6YearsNoRewards() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"), + runMain("3", "yes", "no")); + } + + @Test + public void testMembershipBetween2And6YearsAll() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"), + runMain("3", "yes", "yes")); + } + + // 6 YEARS OF MEMBERSHIP + + @Test + public void testMembership6Years() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"), + runMain("6", "no", "no")); + } + + @Test + public void testMembership6YearsNoSpending() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"), + runMain("6", "no", "yes")); + } + + @Test + public void testMembership6YearsNoRewards() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"), + runMain("6", "yes", "no")); + } + + @Test + public void testMembership6YearsAll() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"), + runMain("6", "yes", "yes")); + } + + // BETWEEN 6 AND 12 YEARS OF MEMBERSHIP + @Test + public void testMembership6PlusYears() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"), + runMain("7", "no", "no")); + } + + @Test + public void testMembership6PlusYearsNoSpending() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"), + runMain("7", "no", "yes")); + } + + @Test + public void testMembership6PlusYearsNoRewards() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "Member"), + runMain("7", "yes", "no")); + } + + @Test + public void testMembership6PlusYearsAll() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"), + runMain("7", "yes", "yes")); + } + + // 12 YEARS OF MEMBERSHIP + @Test + public void testMembership12Years() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"), + runMain("12", "no", "no")); + } + + @Test + public void testMembership12YearsNoSpending() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"), + runMain("12", "no", "yes")); + } + + @Test + public void testMembership12YearsNoRewards() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"), + runMain("12", "yes", "no")); + } + + @Test + public void testMembership12YearsAll() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"), + runMain("12", "yes", "yes")); + } + + // MORE THAN 12 YEARS OF MEMBERSHIP + @Test + public void testMembership12PlusYears() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"), + runMain("13", "no", "no")); + } + + @Test + public void testMembership12PlusYearsNoSpending() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"), + runMain("13", "no", "yes")); + } + + @Test + public void testMembership12PlusYearsNoRewards() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"), + runMain("13", "yes", "no")); + } + + @Test + public void testMembership12PlusYearsAll() { + assertEquals( + assemble("How long has the customer been a member for (in years)? " + + "Has the member spent at least $10K each year in the past 2 years (yes/no)? " + + "Has the member accumulated at least 5,000 reward points (yes/no)? " + "VIP Member"), + runMain("13", "yes", "yes")); + } + +} diff --git a/homework-6.4/conditionals_homework/src/test/java/edu/unl/cse/soft160/conditionals/ScrambleTest.java b/homework-6.4/conditionals_homework/src/test/java/edu/unl/cse/soft160/conditionals/ScrambleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..5b0c0bc9e59a3f7c3c4d1459208802a8850119c4 --- /dev/null +++ b/homework-6.4/conditionals_homework/src/test/java/edu/unl/cse/soft160/conditionals/ScrambleTest.java @@ -0,0 +1,60 @@ +package edu.unl.cse.soft160.conditionals; + +import static org.junit.Assert.*; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.PrintStream; + +import org.junit.Test; + +public class ScrambleTest { + + protected static String assemble(String... lines) { + return String.join("\n", lines) + "\n"; + } + + protected static String runMain(String... inputs) { + InputStream in = System.in; + PrintStream out = System.out; + System.setIn(new ByteArrayInputStream(assemble(inputs).getBytes())); + ByteArrayOutputStream collector = new ByteArrayOutputStream(); + System.setOut(new PrintStream(collector)); + Scramble.main(); + System.setIn(in); + System.setOut(out); + return collector.toString(); + } + + @Test + public void testRegular() { + assertEquals(assemble("Enter length of the first edge: " + "Enter length of the second edge: " + + "Enter length of the third edge: " + "The triangle is regular."), runMain("1", "1", "1")); + } + + @Test + public void testSymmetric12() { + assertEquals(assemble("Enter length of the first edge: " + "Enter length of the second edge: " + + "Enter length of the third edge: " + "The triangle is symmetric."), runMain("1", "1", "2")); + } + + @Test + public void testSymmetric13() { + assertEquals(assemble("Enter length of the first edge: " + "Enter length of the second edge: " + + "Enter length of the third edge: " + "The triangle is symmetric."), runMain("1", "2", "1")); + } + + @Test + public void testSymmetric23() { + assertEquals(assemble("Enter length of the first edge: " + "Enter length of the second edge: " + + "Enter length of the third edge: " + "The triangle is symmetric."), runMain("2", "1", "1")); + } + + @Test + public void testIrregular() { + assertEquals(assemble("Enter length of the first edge: " + "Enter length of the second edge: " + + "Enter length of the third edge: " + "The triangle is irregular."), runMain("1", "2", "3")); + } + +}