Search in sources :

Example 1 with PlaylistItem

use of com.github.hakko.musiccabinet.domain.model.aggr.PlaylistItem in project musiccabinet by hakko.

the class PlaylistGeneratorServiceTest method noAdjacentArtistsInPlaylist.

@Test
public void noAdjacentArtistsInPlaylist() {
    List<PlaylistItem> ts = new ArrayList<>();
    ts.add(new PlaylistItem(1, 1));
    ts.add(new PlaylistItem(1, 2));
    ts.add(new PlaylistItem(1, 3));
    ts.add(new PlaylistItem(2, 4));
    ts.add(new PlaylistItem(2, 5));
    ts.add(new PlaylistItem(2, 6));
    ts.add(new PlaylistItem(3, 7));
    ts.add(new PlaylistItem(3, 8));
    ts.add(new PlaylistItem(3, 9));
    ts.add(new PlaylistItem(4, 10));
    ts.add(new PlaylistItem(4, 11));
    ts.add(new PlaylistItem(4, 12));
    ts.add(new PlaylistItem(5, 13));
    ts.add(new PlaylistItem(5, 14));
    ts.add(new PlaylistItem(5, 15));
    ts.add(new PlaylistItem(6, 16));
    ts.add(new PlaylistItem(6, 17));
    ts.add(new PlaylistItem(6, 18));
    ts.add(new PlaylistItem(7, 19));
    ts.add(new PlaylistItem(7, 20));
    ts.add(new PlaylistItem(7, 21));
    ts.add(new PlaylistItem(8, 22));
    ts.add(new PlaylistItem(8, 23));
    ts.add(new PlaylistItem(8, 24));
    Random rnd = new Random(1258114665843L);
    for (int i = 0; i < 1000; i++) {
        Collections.shuffle(ts, rnd);
        playlistGeneratorService.distributeArtists(ts);
        for (int j = 1; j < ts.size(); j++) {
            if (ts.get(j).getArtistId() == ts.get(j - 1).getArtistId()) {
                Assert.fail("Found adjacent artists in list!");
            }
        }
    }
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) PlaylistItem(com.github.hakko.musiccabinet.domain.model.aggr.PlaylistItem) Test(org.junit.Test)

Example 2 with PlaylistItem

use of com.github.hakko.musiccabinet.domain.model.aggr.PlaylistItem in project musiccabinet by hakko.

the class JdbcPlaylistGeneratorDaoTest method addCherSimilarTracksAndGetPlaylist.

@Test
public void addCherSimilarTracksAndGetPlaylist() throws ApplicationException {
    TrackSimilarityParser tsParser = new TrackSimilarityParserImpl(new ResourceUtil(CHER_SIMILAR_TRACKS).getInputStream());
    trackRelationDao.createTrackRelations(tsParser.getTrack(), tsParser.getTrackRelations());
    List<File> files = new ArrayList<>();
    for (TrackRelation tr : tsParser.getTrackRelations()) {
        String artistName = tr.getTarget().getArtist().getName();
        if ("Madonna".equals(artistName)) {
            files.add(getFile(artistName, null, tr.getTarget().getName()));
        }
    }
    UnittestLibraryUtil.submitFile(additionDao, files);
    int trackId = musicDao.getTrackId(tsParser.getTrack().getArtist().getName(), tsParser.getTrack().getName());
    playlistGeneratorDao.updateSearchIndex();
    List<PlaylistItem> ts = playlistGeneratorDao.getPlaylistForTrack(trackId);
    Assert.assertNotNull(ts);
    Assert.assertEquals(2, ts.size());
}
Also used : TrackSimilarityParserImpl(com.github.hakko.musiccabinet.parser.lastfm.TrackSimilarityParserImpl) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) TrackSimilarityParser(com.github.hakko.musiccabinet.parser.lastfm.TrackSimilarityParser) TrackRelation(com.github.hakko.musiccabinet.domain.model.music.TrackRelation) ArrayList(java.util.ArrayList) UnittestLibraryUtil.getFile(com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile) File(com.github.hakko.musiccabinet.domain.model.library.File) PlaylistItem(com.github.hakko.musiccabinet.domain.model.aggr.PlaylistItem) Test(org.junit.Test)

Aggregations

PlaylistItem (com.github.hakko.musiccabinet.domain.model.aggr.PlaylistItem)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 File (com.github.hakko.musiccabinet.domain.model.library.File)1 TrackRelation (com.github.hakko.musiccabinet.domain.model.music.TrackRelation)1 TrackSimilarityParser (com.github.hakko.musiccabinet.parser.lastfm.TrackSimilarityParser)1 TrackSimilarityParserImpl (com.github.hakko.musiccabinet.parser.lastfm.TrackSimilarityParserImpl)1 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)1 UnittestLibraryUtil.getFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile)1 Random (java.util.Random)1