Add a new test case for chapter recognition

This commit is contained in:
inorichi 2015-12-19 16:22:57 +01:00
parent 9a117f0969
commit 0a7f8711ad
2 changed files with 11 additions and 3 deletions

View File

@ -12,7 +12,7 @@ public class ChapterRecognition {
private static Pattern p1 = Pattern.compile("Ch[^0-9]?\\s*(\\d+[\\.,]?\\d*)"); private static Pattern p1 = Pattern.compile("Ch[^0-9]?\\s*(\\d+[\\.,]?\\d*)");
private static Pattern p2 = Pattern.compile("(\\d+[\\.,]?\\d*)"); private static Pattern p2 = Pattern.compile("(\\d+[\\.,]?\\d*)");
private static Pattern p3 = Pattern.compile("(\\d+[\\.,]?\\d*:)"); private static Pattern p3 = Pattern.compile("(\\d+[\\.,]?\\d*\\s*:)");
public static void parseChapterNumber(Chapter chapter, Manga manga) { public static void parseChapterNumber(Chapter chapter, Manga manga) {
if (chapter.chapter_number != -1) if (chapter.chapter_number != -1)
@ -29,8 +29,6 @@ public class ChapterRecognition {
return; return;
} }
name = replaceIrrelevantCharacters(name);
List<Float> occurences; List<Float> occurences;
// If there's only one number, use it // If there's only one number, use it
@ -49,6 +47,8 @@ public class ChapterRecognition {
return; return;
} }
name = replaceIrrelevantCharacters(name);
// Try to remove the manga name from the chapter, and try again // Try to remove the manga name from the chapter, and try again
String mangaName = replaceIrrelevantCharacters(manga.title); String mangaName = replaceIrrelevantCharacters(manga.title);
String nameWithoutManga = difference(mangaName, name); String nameWithoutManga = difference(mangaName, name);

View File

@ -113,4 +113,12 @@ public class ChapterRecognitionTest {
assertThat(c.chapter_number, is(567f)); assertThat(c.chapter_number, is(567f));
} }
@Test
public void testWithVersionBefore() {
// It should be 84, not 2084)
Chapter c = createChapter("Onepunch-Man Punch Ver002 084 : Creeping Darkness");
ChapterRecognition.parseChapterNumber(c, randomManga);
assertThat(c.chapter_number, is(84f));
}
} }