Skip to content

ham #15

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

ham #15

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
21 changes: 20 additions & 1 deletion src/main/java/HamletParser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Created by thook on 10/7/15.
Expand All @@ -10,6 +12,7 @@ public class HamletParser {
private String hamletData;

public HamletParser(){

this.hamletData = loadFile();
}

Expand All @@ -23,7 +26,6 @@ private String loadFile(){
String line = scanner.nextLine();
result.append(line).append("\n");
}

scanner.close();
}catch(IOException e){
e.printStackTrace();
Expand All @@ -36,4 +38,21 @@ public String getHamletData(){
return hamletData;
}

public void horatioToTariq(){
Pattern pattern = Pattern.compile("(H)(oratio|ORATIO)");
Matcher matcher = pattern.matcher(this.hamletData);
hamletData = matcher.replaceAll("Tariq");
}
public void hamletToLeon(){
Pattern pattern = Pattern.compile("(H)(amlet|AMLET)");
Matcher matcher = pattern.matcher(this.hamletData);
hamletData = matcher.replaceAll("Leon");
}

public static void main(String[] args) {
HamletParser hamletParser = new HamletParser();
hamletParser.hamletToLeon();
hamletParser.horatioToTariq();
System.out.println(hamletParser.getHamletData());
}
}
21 changes: 21 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,37 @@ public void setUp() {

@Test
public void testChangeHamletToLeon() {
HamletParser hamletParser = new HamletParser();
String beforeAnyChangesMade = hamletParser.getHamletData();
hamletParser.hamletToLeon();
String afterChangesMade = hamletParser.getHamletData();
Assert.assertNotEquals(beforeAnyChangesMade, afterChangesMade);
}

@Test
public void testChangeHoratioToTariq() {
HamletParser hamletParser = new HamletParser();
String beforeAnyChangesMade = hamletParser.getHamletData();
hamletParser.horatioToTariq();
String afterChangesMade = hamletParser.getHamletData();
Assert.assertNotEquals(beforeAnyChangesMade, afterChangesMade);
}

@Test
public void testFindHoratio() {
HamletParser hamletParser = new HamletParser();
String beforeAnyChangesMade = "Hello Horatio hello HORATIO";
hamletParser.horatioToTariq();
String actual = "Hello Tariq hello Tariq";
Assert.assertNotEquals(beforeAnyChangesMade, actual);
}

@Test
public void testFindHamlet() {
HamletParser hamletParser = new HamletParser();
String beforeAnyChangesMade = "Hello Hamlet hello HAMLET";
hamletParser.horatioToTariq();
String actual = "Hello Leon hello Leon";
Assert.assertNotEquals(beforeAnyChangesMade, actual);
}
}
Loading