Skip to content
Snippets Groups Projects
Commit 6b73b71e authored by Sara El Alaoui's avatar Sara El Alaoui
Browse files

Initial files

parents
Branches
No related tags found
No related merge requests found
Showing
with 551 additions and 0 deletions
<?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="output" path="target/classes"/>
</classpath>
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.project 0 → 100755
<?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>
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
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
pom.xml 0 → 100755
<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>
File added
package edu.unl.cse.soft160.conditionals;
import java.util.Scanner;
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].*");
// [write code here]
scanner.close();
}
}
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 = Integer.parseInt(scanner.nextLine());
// [write code here]
scanner.close();
}
}
package edu.unl.cse.soft160.conditionals;
import java.util.Scanner;
public class Scramble {
public static void main(String... arguments) {
// [write code here]
}
}
File added
package edu.unl.cse.soft160.conditionals;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.PrintStream;
import java.io.ByteArrayOutputStream;
public class AutonomousCarTest extends TestCase {
public AutonomousCarTest(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(AutonomousCarTest.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));
AutonomousCar.main();
System.setIn(in);
System.setOut(out);
return collector.toString();
}
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"));
}
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"));
}
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"));
}
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"));
}
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"));
}
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"));
}
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"));
}
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"));
}
}
package edu.unl.cse.soft160.conditionals;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.PrintStream;
import java.io.ByteArrayOutputStream;
public class MembershipTest extends TestCase {
public MembershipTest(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(MembershipTest.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));
Membership.main();
System.setIn(in);
System.setOut(out);
return collector.toString();
}
// LESS THAN 2 YEARS OF MEMBERSHIP
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"));
}
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"));
}
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"));
}
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
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"));
}
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"));
}
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
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
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
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
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"));
}
}
package edu.unl.cse.soft160.conditionals;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.PrintStream;
import java.io.ByteArrayOutputStream;
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();
}
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"));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment