Skip to content

passing tests . #29

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 2 commits into
base: master
Choose a base branch
from
Open
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
84 changes: 83 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 @@ -9,10 +11,17 @@ public class HamletParser {

private String hamletData;


public HamletParser(){
this.hamletData = loadFile();
}

public HamletParser(String sentence){
this.hamletData = sentence;
}



private String loadFile(){
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("hamlet.txt").getFile());
Expand All @@ -36,4 +45,77 @@ public String getHamletData(){
return hamletData;
}

}
public String changeHamletToLeon(String sentence){

Pattern pattern = Pattern.compile("(h|H)amlet");

String str = sentence;

Matcher m = pattern.matcher(str);

String str2 = m.replaceAll("Leon");

System.out.println(str2);









return str2;
}

public String changeHoratioToTariq(String sentence){

Pattern pattern = Pattern.compile("(h|H)oratio");

String str = sentence;

Matcher m = pattern.matcher(str);

String str2 = m.replaceAll("Tariq");

System.out.println(str2);

return str2;
}
public boolean findHoratio() {
boolean findHoratio = true;

String hString = "Horatio";
Pattern hPattern = Pattern.compile(hString);
Matcher hMatcher = hPattern.matcher(hamletData);

if (hMatcher.find()) {
findHoratio = true;
} else {
return false;
}
return findHoratio;

}
public boolean findHamlet() {
boolean findHamlet = true;

String hamString = "Hamlet";
Pattern hamPattern = Pattern.compile(hamString);
Matcher hamMatcher = hamPattern.matcher(hamletData);

if (hamMatcher.find()) {
findHamlet = true;
} else {
return false;
}
return findHamlet;
}






}

63 changes: 63 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,79 @@ public void setUp() {

@Test
public void testChangeHamletToLeon() {
//given
String sentence = "Hamlet loves cheese";
HamletParser hamletParser = new HamletParser(sentence);
String expected = "Leon loves cheese";
String actual = hamletParser.changeHamletToLeon(sentence);
Assert.assertEquals(expected,actual);






}
@Test
public void testChangeHamletToLeon2() {
//given
String sentence = "Hamlet loves cheese & hamlet loves milk with cookies";
HamletParser hamletParser = new HamletParser(sentence);
String expected = "Leon loves cheese & Leon loves milk with cookies";
String actual = hamletParser.changeHamletToLeon(sentence);
Assert.assertEquals(expected, actual);
}

@Test
public void testChangeHoratioToTariq() {
String sentence = "Horatio hates cowboy fans and will kill them all";
HamletParser hamletParser = new HamletParser(sentence);
String expected = "Tariq hates cowboy fans and will kill them all";
String actual = hamletParser.changeHoratioToTariq(sentence);
Assert.assertEquals(expected, actual);

}
@Test
public void testChangeHoratioToTariq2() {
String sentence = "Horatio loves the eagles horatio was happy when the eagles won the superbowl";
HamletParser hamletParser = new HamletParser(sentence);
String expected = "Tariq loves the eagles Tariq was happy when the eagles won the superbowl";
String actual = hamletParser.changeHoratioToTariq(sentence);
Assert.assertEquals(expected, actual);
}


@Test
public void testFindHoratio() {
//Given
boolean expected = true;

//when
hamletParser = new HamletParser();
boolean actual = hamletParser.findHoratio();

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








}

@Test
public void testFindHamlet() {
//Given
boolean expected = true;

//when
hamletParser = new HamletParser();
boolean actual = hamletParser.findHoratio();

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