Skip to content

lab #30

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

lab #30

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
<groupId>com.zipcodewilmington</groupId>
<artifactId>regex</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/HamletParser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import java.util.regex.*;

/**
* Created by thook on 10/7/15.
Expand Down Expand Up @@ -36,4 +37,54 @@ public String getHamletData(){
return hamletData;
}

public String changeHamletToLeon(String string) {
Pattern lowerCase = Pattern.compile("Hamlet");
Matcher match1 = lowerCase.matcher(string);
String result1 = match1.replaceAll("Leon");

Pattern upperCase = Pattern.compile("HAMLET");
Matcher match2 = upperCase.matcher(result1);
String result2 = match2.replaceAll("LEON");

return result2;
}

public String changeHoratioToTariq(String string) {
Pattern lowerCase = Pattern.compile("Horatio");
Matcher match1 = lowerCase.matcher(string);
String result1 = match1.replaceAll("Tariq");

Pattern upperCase = Pattern.compile("HORATIO");
Matcher match2 = upperCase.matcher(result1);
String result2 = match2.replaceAll("TARIQ");

return result2;
}

public boolean findHamlet(String input){
if ( hamletData.contains("Hamlet") || hamletData.contains("HAMLET")) {
}
return true;
}

public boolean findHoratio(String input){
if ( hamletData.contains("Horatio") || hamletData.contains("HORATIO")) {
}
return true;
}

}
/*
REGEX

Directions

Make a project that will go through the hamlet file provided and
using regex replace every instance of "Hamlet" with "Leon" and every instance of Horatio with "Tariq".

Beginning with tests, you are to program all the steps it will take to complete that process.
Some tests have been stubbed out for you but
these will not cover all the methods you should have in your project.

IMPORTANT: You are not to use String Utilities to simply replace words. You must use Pattern and Matcher.
*/
27 changes: 27 additions & 0 deletions src/test/java/HamletParserTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -15,17 +16,43 @@ public void setUp() {

@Test
public void testChangeHamletToLeon() {
// Given
HamletParser testHamletParser = new HamletParser();
String string = "Hamlet. HAMLET. Hamlet!";

// When
String expected = "Leon. LEON. Leon!";
String actual = testHamletParser.changeHamletToLeon(string);

// Then
Assert.assertEquals(expected, actual);
}

@Test
public void testChangeHoratioToTariq() {
// Given
HamletParser testHamletParser = new HamletParser();
String string = "Horatio. HORATIO. Horatio!";

// When
String expected = "Tariq. TARIQ. Tariq!";
String actual = testHamletParser.changeHoratioToTariq(string);

// Then
Assert.assertEquals(expected, actual);
}

@Test
public void testFindHoratio() {
boolean expected = true;
boolean actual = hamletParser.findHoratio("Horatio found");
assertEquals(expected, actual);
}

@Test
public void testFindHamlet() {
boolean expected = true;
boolean actual = hamletParser.findHamlet("Hamlet found");
assertEquals(expected, actual);
}
}
Loading