-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
154 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.hightail.util; | ||
|
||
/** | ||
* | ||
* @author Joseph | ||
*/ | ||
public class ProblemNameFormatter { | ||
// gets rid of weird special characters | ||
public static String getFormattedName (String originalName) { | ||
return originalName.replaceAll("[^A-Za-z0-9 ._-]", ""); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
Hightail/test/org/hightail/parsers/task/CodeForcesTaskParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.hightail.parsers.task; | ||
|
||
import org.hightail.Config; | ||
import org.hightail.Problem; | ||
import org.hightail.SupportedSites; | ||
import org.htmlparser.util.ParserException; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* | ||
* @author Joseph | ||
*/ | ||
public class CodeForcesTaskParserTest { | ||
|
||
private final String URL = "http://codeforces.com/problemset/problem/744/E"; | ||
private final String COMPLETE_PROBLEM_NAME = "E. Hongcow Masters the Cyclic Shift"; | ||
private final String SHORT_PROBLEM_NAME = "E"; | ||
|
||
|
||
@BeforeClass | ||
public static void setUpClass() { | ||
Config.fillInUnsetValuesWithDefaults(); | ||
} | ||
|
||
/** | ||
* Putting the first problem's name letter as the name of the problem | ||
*/ | ||
@Test | ||
public void testParseShortName() { | ||
try { | ||
TaskParser parser = SupportedSites.getTaskParser(URL); | ||
Problem problem = parser.parse(URL); | ||
assertEquals(SHORT_PROBLEM_NAME, problem.getName()); | ||
} catch (ParserException ex) { | ||
fail("thrown exception ParserException"); | ||
} catch (InterruptedException ex) { | ||
fail("thrown exception InterruptedException"); | ||
} | ||
} | ||
|
||
/** | ||
* Putting the whole problem's name as the name of the problem | ||
*/ | ||
@Test | ||
public void testParseWholeName() { | ||
try { | ||
Config.setBoolean("putWholeName", true); | ||
TaskParser parser = SupportedSites.getTaskParser(URL); | ||
Problem problem = parser.parse(URL); | ||
assertEquals(COMPLETE_PROBLEM_NAME, problem.getName()); | ||
} catch (ParserException ex) { | ||
fail("thrown exception ParserException"); | ||
} catch (InterruptedException ex) { | ||
fail("thrown exception InterruptedException"); | ||
} | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
Hightail/test/org/hightail/util/ProblemNameFormatterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.hightail.util; | ||
|
||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* | ||
* @author Joseph | ||
*/ | ||
public class ProblemNameFormatterTest { | ||
private final String PROBLEM_NAME_A = "E. 09 - _ .test"; | ||
private final String PROBLEM_NAME_B = "+T?E]S'T"; | ||
private final String PROBLEM_NAME_EXPECTED_B = "TEST"; | ||
|
||
@Test | ||
public void testGetFormattedNameAllowedCharacters() { | ||
String formattedName = ProblemNameFormatter.getFormattedName(PROBLEM_NAME_A); | ||
assertEquals(PROBLEM_NAME_A, formattedName); | ||
} | ||
|
||
@Test | ||
public void testGetFormattedNameNotAllowedCharacters() { | ||
String formattedName = ProblemNameFormatter.getFormattedName(PROBLEM_NAME_B); | ||
assertEquals(PROBLEM_NAME_EXPECTED_B, formattedName); | ||
} | ||
} |