public void ShouldRoundTripRatingsValues() { for (double s = 0.0; s <= 5.0; s += 0.5) { uint r = TrackRating.FiveStarRatingToRaw(s); double ns = TrackRating.RawRatingToFiveStar(r); Assert.Equal(s, ns); } for (double p = 0.0; p <= 1.0; p = Math.Round(p + 0.01, 2)) { uint r = TrackRating.PercentRatingToRaw(p); double np = TrackRating.RawRatingToPercent(r); Assert.Equal(p, np); } }
void ShouldMergeDefaultAndSuppliedRatings() { var defaultRating = TrackRating.FiveStarRatingToRaw(4.0); var parser = new DanceInfoTagParser(defaultRating, DanceCategories.None, "WC [email protected]", "Foxtrot", "Smooth", "[email protected]", "Swing"); var tdis = parser.GetTagDanceInfo().ToList(); Assert.Equal(4, tdis.Count); var foxtrots = tdis.Where((t) => t.Dance == Dances.Foxtrot); var smooth = foxtrots.Single((t) => (t.Categories & DanceCategories.Smooth) != DanceCategories.None); var social = foxtrots.Single((t) => (t.Categories & DanceCategories.Social) != DanceCategories.None); Assert.Equal(defaultRating, smooth.RawRating); Assert.Equal(3.5, social.FiveStarRating); var swings = tdis.Where((t) => t.Dance == Dances.WestCoastSwing); var swing = swings.Single((t) => (t.Categories & DanceCategories.Swing) != DanceCategories.None); social = swings.Single((t) => (t.Categories & DanceCategories.Social) != DanceCategories.None); Assert.Equal(4.5, swing.FiveStarRating); Assert.Equal(3.5, social.FiveStarRating); }
public void ShouldFilterByRating() { var library = SampleData.GetTestLibrary(); foreach (var rating in SampleData.ExpectedTracksByRating.Keys) { var filter = new TrackDanceFilter() { MinRating = TrackRating.FiveStarRatingToRaw(rating), MaxRating = TrackRating.FiveStarRatingToRaw(5.0), IncludeTracksWithNoRating = false }; var tracks = filter.Apply(library.Tracks); Assert.Equal(SampleData.ExpectedTracksByRating[rating], tracks.Count()); foreach (var track in tracks) { Assert.NotNull(track.Rating); Assert.True(track.Rating.FiveStarRating >= rating); } } }