1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-22 15:58:52 -05:00

SubstringFields and update unit tests

This commit is contained in:
Reinhard Pointner 2016-03-13 13:32:26 +00:00
parent 1fc9048bcc
commit 9bc40eccd4
18 changed files with 52 additions and 100 deletions

View File

@ -196,7 +196,7 @@ public enum EpisodeMetrics implements SimilarityMetric {
protected String[] normalize(Object[] objects) {
String[] names = new String[objects.length];
for (int i = 0; i < objects.length; i++) {
names[i] = normalizeObject(objects[i]).replaceAll("\\s", "");
names[i] = replaceSpace((normalizeObject(objects[i])), " "); // we're only matching between word boundaries
}
return names;
}

View File

@ -1,5 +1,9 @@
package net.filebot;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import net.filebot.format.ExpressionFormatTest;
import net.filebot.hash.VerificationFormatTest;
import net.filebot.media.MediaDetectionTest;
@ -11,10 +15,6 @@ import net.filebot.ui.rename.MatchModelTest;
import net.filebot.util.UtilTestSuite;
import net.filebot.web.WebTestSuite;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ SimilarityTestSuite.class, WebTestSuite.class, ExpressionFormatTest.class, VerificationFormatTest.class, MatchModelTest.class, EpisodeMetricsTest.class, SubtitleReaderTestSuite.class, ReleaseInfoTest.class, MediaDetectionTest.class, UtilTestSuite.class })
public class AllTests {

View File

@ -1,7 +1,6 @@
package net.filebot.format;
import static org.junit.Assert.*;
import javax.script.Bindings;
@ -11,7 +10,6 @@ import javax.script.SimpleBindings;
import org.junit.Test;
public class ExpressionFormatTest {
@Test
@ -26,7 +24,6 @@ public class ExpressionFormatTest {
assertTrue(expression[3] instanceof CompiledScript);
}
@Test
public void format() throws Exception {
assertEquals("X5-452", new TestScriptFormat("X5-{value}").format("452"));
@ -56,17 +53,15 @@ public class ExpressionFormatTest {
assertEquals("Today Is the Day, Part 1", new TestScriptFormat("{value.replacePart(', Part $1')}").format("Today Is the Day: part 1"));
// choice
assertEquals("not to be", new TestScriptFormat("{value ? 'to be' : 'not to be'}").format(null));
assertEquals("default", new TestScriptFormat("{value ?: 'default'}").format(null));
assertEquals("not to be", new TestScriptFormat("{value ? 'to be' : 'not to be'}").format(false));
assertEquals("default", new TestScriptFormat("{value ?: 'default'}").format(false));
}
@Test
public void closures() throws Exception {
assertEquals("[ant, cat]", new TestScriptFormat("{['ant', 'buffalo', 'cat', 'dinosaur'].findAll{ it.size() <= 3 }}").format(null));
}
@Test
public void illegalSyntax() throws Exception {
try {
@ -80,7 +75,6 @@ public class ExpressionFormatTest {
}
}
@Test
public void illegalClosingBracket() throws Exception {
try {
@ -94,34 +88,30 @@ public class ExpressionFormatTest {
}
}
@Test
public void illegalBinding() throws Exception {
TestScriptFormat format = new TestScriptFormat("{xyz}");
format.format(new SimpleBindings());
// check message
assertEquals("BindingException: \"xyz\": undefined", format.caughtScriptException().getMessage());
assertEquals("Binding \"xyz\": undefined", format.caughtScriptException().getMessage());
}
@Test
public void illegalProperty() throws Exception {
TestScriptFormat format = new TestScriptFormat("{value.xyz}");
format.format("test");
// check message
assertEquals("BindingException: \"xyz\": undefined", format.caughtScriptException().getMessage());
assertEquals("Binding \"xyz\": undefined", format.caughtScriptException().getMessage());
}
protected static class TestScriptFormat extends ExpressionFormat {
public TestScriptFormat(String format) throws ScriptException {
super(format);
}
@Override
public Bindings getBindings(Object value) {
Bindings bindings = new SimpleBindings();

View File

@ -7,10 +7,10 @@ import java.io.File;
import java.util.ArrayList;
import java.util.List;
import net.filebot.web.Episode;
import org.junit.Test;
import net.filebot.web.Episode;
public class EpisodeMetricsTest {
@Test
@ -50,7 +50,7 @@ public class EpisodeMetricsTest {
episodes.add(new Episode("Greek", 1, 19, "No Campus for Old Rules"));
SimilarityMetric[] metrics = new SimilarityMetric[] { EpisodeIdentifier, SubstringFields };
List<Match<File, Episode>> m = new Matcher<File, Episode>(files, episodes, true, metrics).match();
List<Match<File, Episode>> m = new Matcher<File, Episode>(files, episodes, false, metrics).match();
assertEquals("Greek - S01E19 - No Campus for Old Rules", m.get(0).getValue().getName());
assertEquals("Greek - 1x19 - No Campus for Old Rules", m.get(0).getCandidate().toString());

View File

@ -8,13 +8,13 @@ import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import net.filebot.util.TestUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import net.filebot.util.TestUtil;
@RunWith(Parameterized.class)
public class NumericSimilarityMetricTest {

View File

@ -3,11 +3,12 @@ package net.filebot.similarity;
import static java.util.Arrays.*;
import static net.filebot.similarity.SeasonEpisodeMatcher.SxE.*;
import static org.junit.Assert.*;
import net.filebot.media.MediaDetection;
import net.filebot.similarity.SeasonEpisodeMatcher.SxE;
import org.junit.Test;
import net.filebot.media.MediaDetection;
import net.filebot.similarity.SeasonEpisodeMatcher.SxE;
public class SeasonEpisodeMatcherTest {
private static SeasonEpisodeMatcher matcher = new SeasonEpisodeMatcher(SeasonEpisodeMatcher.DEFAULT_SANITY, false);

View File

@ -1,13 +1,17 @@
package net.filebot.similarity;
import static org.junit.Assert.*;
import net.filebot.similarity.SeriesNameMatcher.SeriesNameCollection;
import java.util.Locale;
import org.junit.Test;
import net.filebot.media.SmartSeasonEpisodeMatcher;
import net.filebot.similarity.SeriesNameMatcher.SeriesNameCollection;
public class SeriesNameMatcherTest {
SeriesNameMatcher matcher = new SeriesNameMatcher(true);
SeriesNameMatcher matcher = new SeriesNameMatcher(new SmartSeasonEpisodeMatcher(SeasonEpisodeMatcher.DEFAULT_SANITY, true), new DateMatcher(DateMatcher.DEFAULT_SANITY, Locale.ENGLISH));
@Test
public void whitelist() {
@ -28,9 +32,7 @@ public class SeriesNameMatcherTest {
@Test
public void matchBeforeSeasonEpisodePattern() {
assertEquals("The Test", matcher.matchByEpisodeIdentifier("The Test - 1x01"));
// real world test
assertEquals("Mushishi", matcher.matchByEpisodeIdentifier("[niizk]_Mushishi_-_1x01_-_The_Green_Gathering"));
assertEquals("Mushishi", matcher.matchByEpisodeIdentifier("Mushishi_-_1x01_-_The_Green_Gathering"));
}
@Test

View File

@ -1,38 +0,0 @@
package net.filebot.subtitle;
import static org.junit.Assert.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.GZIPInputStream;
import org.junit.Test;
public class SubRipReaderTest {
@Test
public void parse() throws Exception {
List<SubtitleElement> list = new ArrayList<SubtitleElement>();
URL resource = new URL("http://www.opensubtitles.org/en/download/file/1951733951.gz");
InputStream source = new GZIPInputStream(resource.openStream());
SubRipReader reader = new SubRipReader(new InputStreamReader(source, "UTF-8"));
try {
while (reader.hasNext()) {
list.add(reader.next());
}
} finally {
reader.close();
}
assertEquals(501, list.size(), 0);
}
}

View File

@ -1,14 +1,12 @@
package net.filebot.subtitle;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses( { SubRipReaderTest.class, MicroDVDReaderTest.class })
@SuiteClasses({ MicroDVDReaderTest.class })
public class SubtitleReaderTestSuite {
}

View File

@ -8,11 +8,10 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.filebot.similarity.Match;
import org.junit.Test;
import ca.odell.glazedlists.GlazedLists;
import net.filebot.similarity.Match;
public class MatchModelTest {

View File

@ -8,12 +8,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.prefs.Preferences;
import net.filebot.util.PreferencesMap.SimpleAdapter;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import net.filebot.util.PreferencesMap.SimpleAdapter;
public class PreferencesListTest {

View File

@ -11,13 +11,13 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.prefs.Preferences;
import net.filebot.util.PreferencesMap.SerializableAdapter;
import net.filebot.util.PreferencesMap.SimpleAdapter;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import net.filebot.util.PreferencesMap.SerializableAdapter;
import net.filebot.util.PreferencesMap.SimpleAdapter;
public class PreferencesMapTest {

View File

@ -5,7 +5,7 @@ import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ FileUtilitiesTest.class, ByteBufferOutputStreamTest.class, PreferencesMapTest.class, PreferencesListTest.class, TreeIteratorTest.class, FilterIteratorTest.class, StringUtilities.class })
@SuiteClasses({ FileUtilitiesTest.class, ByteBufferOutputStreamTest.class, PreferencesMapTest.class, PreferencesListTest.class, TreeIteratorTest.class, FilterIteratorTest.class, StringUtilitiesTest.class })
public class UtilTestSuite {
}

View File

@ -10,20 +10,22 @@ import org.junit.Test;
public class AnidbClientTest {
static AnidbClient anidb = new AnidbClient("filebot", 6);
/**
* 74 episodes
*/
private static AnidbSearchResult monsterSearchResult;
static AnidbSearchResult monsterSearchResult;
/**
* 45 episodes
*/
private static AnidbSearchResult twelvekingdomsSearchResult;
static AnidbSearchResult twelvekingdomsSearchResult;
/**
* 38 episodes, lots of special characters
*/
private static AnidbSearchResult princessTutuSearchResult;
static AnidbSearchResult princessTutuSearchResult;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
@ -32,8 +34,6 @@ public class AnidbClientTest {
princessTutuSearchResult = new AnidbSearchResult(516, "Princess Tutu", null);
}
private AnidbClient anidb = new AnidbClient("filebot", 6);
@Test
public void getAnimeTitles() throws Exception {
List<AnidbSearchResult> animeTitles = anidb.getAnimeTitles();
@ -87,7 +87,7 @@ public class AnidbClientTest {
public void getEpisodeListAllShortLink() throws Exception {
List<Episode> list = anidb.getEpisodeList(twelvekingdomsSearchResult, SortOrder.Airdate, Locale.ENGLISH);
assertEquals(46, list.size());
assertEquals(47, list.size());
Episode first = list.get(0);
@ -110,7 +110,7 @@ public class AnidbClientTest {
List<Episode> list = anidb.getEpisodeList(monsterSearchResult, SortOrder.Airdate, Locale.JAPANESE);
Episode last = list.get(73);
assertEquals("モンスター", last.getSeriesName());
assertEquals("MONSTER", last.getSeriesName());
assertEquals("2004-04-07", last.getSeriesInfo().getStartDate().toString());
assertEquals("本当の怪物", last.getTitle());
assertEquals("74", last.getEpisode().toString());

View File

@ -4,10 +4,10 @@ import static org.junit.Assert.*;
import java.util.List;
import net.filebot.web.TMDbClient.MovieInfo;
import org.junit.Test;
import net.filebot.web.TMDbClient.MovieInfo;
public class OMDbClientTest {
private final OMDbClient client = new OMDbClient();

View File

@ -8,15 +8,15 @@ import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import net.filebot.web.OpenSubtitlesSubtitleDescriptor.Property;
import net.filebot.web.OpenSubtitlesXmlRpc.Query;
import net.filebot.web.OpenSubtitlesXmlRpc.SubFile;
import net.filebot.web.OpenSubtitlesXmlRpc.TryUploadResponse;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class OpenSubtitlesXmlRpcTest {
private static OpenSubtitlesXmlRpc xmlrpc = new OpenSubtitlesXmlRpc(String.format("%s %s", getApplicationName(), getApplicationVersion()));
@ -77,8 +77,8 @@ public class OpenSubtitlesXmlRpcTest {
OpenSubtitlesSubtitleDescriptor sample = list.get(75);
assertEquals("\"Wonderfalls\" Wound-up Penguin", sample.getProperty(Property.MovieName));
assertEquals("German", sample.getProperty(Property.LanguageName));
assertEquals("\"Wonderfalls\" Safety Canary", sample.getProperty(Property.MovieName));
assertEquals("Czech", sample.getProperty(Property.LanguageName));
assertEquals("imdbid", sample.getProperty(Property.MatchedBy));
// check size
@ -185,7 +185,7 @@ public class OpenSubtitlesXmlRpcTest {
ByteBuffer data = list.get(0).fetch();
// check size
assertEquals(48717, data.remaining(), 0);
assertEquals(48794, data.remaining(), 0);
}
// @Test(expected = IOException.class)

View File

@ -90,8 +90,8 @@ public class TMDbClientTest {
@Test
public void getArtwork() throws Exception {
List<Artwork> artwork = tmdb.getArtwork("tt0418279");
assertEquals("backdrops", artwork.get(0).getCategory());
assertEquals("http://image.tmdb.org/t/p/original/ac0HwGJIU3GxjjGujlIjLJmAGPR.jpg", artwork.get(0).getUrl().toString());
assertEquals("posters", artwork.get(0).getCategory());
assertEquals("http://image.tmdb.org/t/p/original/bgSHbGEA1OM6qDs3Qba4VlSZsNG.jpg", artwork.get(0).getUrl().toString());
}
@Ignore

View File

@ -8,11 +8,11 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.junit.Test;
import net.filebot.web.TheTVDBClient.BannerDescriptor;
import net.filebot.web.TheTVDBClient.MirrorType;
import org.junit.Test;
public class TheTVDBClientTest {
TheTVDBClient thetvdb = new TheTVDBClient("BA864DEE427E384A");