From b31190ff1a4d58715ec4a4be27639a5f096018ab Mon Sep 17 00:00:00 2001 From: Sara El Alaoui <saraelalaoui@SEA-2.local> Date: Thu, 3 Oct 2019 20:49:46 -0500 Subject: [PATCH] Adjusted formatting and changed to JUnit4 --- .classpath | 1 + .../conditionals/AutonomousCarTest.java | 90 ++-- .../soft160/conditionals/MembershipTest.java | 437 ++++++++++-------- .../soft160/conditionals/ScrambleTest.java | 126 +++-- 4 files changed, 343 insertions(+), 311 deletions(-) mode change 100755 => 100644 src/test/java/edu/unl/cse/soft160/conditionals/AutonomousCarTest.java mode change 100755 => 100644 src/test/java/edu/unl/cse/soft160/conditionals/MembershipTest.java mode change 100755 => 100644 src/test/java/edu/unl/cse/soft160/conditionals/ScrambleTest.java diff --git a/.classpath b/.classpath index 83dd2f4..b698c36 100755 --- a/.classpath +++ b/.classpath @@ -22,5 +22,6 @@ <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/src/test/java/edu/unl/cse/soft160/conditionals/AutonomousCarTest.java b/src/test/java/edu/unl/cse/soft160/conditionals/AutonomousCarTest.java old mode 100755 new mode 100644 index 5c03fb4..83b5159 --- a/src/test/java/edu/unl/cse/soft160/conditionals/AutonomousCarTest.java +++ b/src/test/java/edu/unl/cse/soft160/conditionals/AutonomousCarTest.java @@ -1,22 +1,15 @@ package edu.unl.cse.soft160.conditionals; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.Assert.*; -import java.io.InputStream; import java.io.ByteArrayInputStream; -import java.io.PrintStream; import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.PrintStream; -public class AutonomousCarTest extends TestCase { - public AutonomousCarTest(String testName) { - super(testName); - } +import org.junit.Test; - public static Test suite() { - return new TestSuite(AutonomousCarTest.class); - } +public class AutonomousCarTest { protected static String assemble(String... lines) { return String.join("\n", lines) + "\n"; @@ -34,59 +27,68 @@ public class AutonomousCarTest extends TestCase { 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")); + 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")); + 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")); + 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")); + 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")); + 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")); + 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")); + 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")); + 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/src/test/java/edu/unl/cse/soft160/conditionals/MembershipTest.java b/src/test/java/edu/unl/cse/soft160/conditionals/MembershipTest.java old mode 100755 new mode 100644 index 00eb0c6..ca6f91e --- a/src/test/java/edu/unl/cse/soft160/conditionals/MembershipTest.java +++ b/src/test/java/edu/unl/cse/soft160/conditionals/MembershipTest.java @@ -1,22 +1,15 @@ package edu.unl.cse.soft160.conditionals; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.Assert.*; -import java.io.InputStream; import java.io.ByteArrayInputStream; -import java.io.PrintStream; import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.PrintStream; -public class MembershipTest extends TestCase { - public MembershipTest(String testName) { - super(testName); - } +import org.junit.Test; - public static Test suite() { - return new TestSuite(MembershipTest.class); - } +public class MembershipTest { protected static String assemble(String... lines) { return String.join("\n", lines) + "\n"; @@ -34,206 +27,264 @@ public class MembershipTest extends TestCase { return collector.toString(); } - // LESS THAN 2 YEARS OF MEMBERSHIP + // 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")); - } - - 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")); - } - - 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")); - } - - 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 - 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")); - } - + 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")); + 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")); + 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")); + 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 + // 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")); + 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")); } - 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 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")); } - - 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 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")); } - 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")); + @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 + + // 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")); - } - - 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")); - } - - 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")); - } - - 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 + 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")); - } - - 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")); - } - - 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")); - } - - 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 + 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")); - } - - 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")); - } - - 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")); - } - - 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 + 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")); - } - - 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")); - } - - 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")); - } - - 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")); - } - + 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/src/test/java/edu/unl/cse/soft160/conditionals/ScrambleTest.java b/src/test/java/edu/unl/cse/soft160/conditionals/ScrambleTest.java old mode 100755 new mode 100644 index c52b67b..5b0c0bc --- a/src/test/java/edu/unl/cse/soft160/conditionals/ScrambleTest.java +++ b/src/test/java/edu/unl/cse/soft160/conditionals/ScrambleTest.java @@ -1,82 +1,60 @@ package edu.unl.cse.soft160.conditionals; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.Assert.*; -import java.io.InputStream; import java.io.ByteArrayInputStream; -import java.io.PrintStream; import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.PrintStream; -public class ScrambleTest extends TestCase { - - public ScrambleTest(String testName) { - super(testName); - } - - public static Test suite() { - return new TestSuite(ScrambleTest.class); - } - - 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(); - } +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")); + } - public void testRegular() { - assertEquals( - assemble("Enter length of the first edge: " - + "Enter length of the second value: " - + "Enter length of the third value: " - + "The triangle is regular."), - runMain("1", "1", "1")); - } - - public void testSymmetric12() { - assertEquals( - assemble("Enter length of the first edge: " - + "Enter length of the second value: " - + "Enter length of the third value: " - + "The triangle is symmetric."), - runMain("1", "1", "2")); - } - - public void testSymmetric13() { - assertEquals( - assemble("Enter length of the first edge: " - + "Enter length of the second value: " - + "Enter length of the third value: " - + "The triangle is symmetric."), - runMain("1", "2", "1")); - } - - public void testSymmetric23() { - assertEquals( - assemble("Enter length of the first edge: " - + "Enter length of the second value: " - + "Enter length of the third value: " - + "The triangle is symmetric."), - runMain("2", "1", "1")); - } - - public void testIrregular() { - assertEquals( - assemble("Enter length of the first edge: " - + "Enter length of the second value: " - + "Enter length of the third value: " - + "The triangle is irregular."), - runMain("1", "2", "3")); - } } -- GitLab