Commits

Mark Heath committed cd3cf63

fixed some bugs in the wraparound code for the Next button

  • Participants
  • Parent commits 798ad62

Comments (0)

Files changed (2)

MusicRater.Tests/ExtensionMethodsUnitTests.cs

 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using MusicRater;
 using System.Collections.Generic;
+using MusicRater.Model;
 
 namespace MusicRater.Tests
 {
             AssertListsAreEqual(newList, new int[] { 6, 7, 8, 9, 10, 1, 2, 3, 4, 5 });
         }
 
+        [TestMethod]
+        public void OnceRoundStartingAfterWithExclusions()
+        {
+            Rating[] ratings = new Rating[] { };
+            var first = new Track(ratings) { IsExcluded = true, Title="Track 1"};
+            var second = new Track(ratings) { Title="Track 2"};
+            var third = new Track(ratings) { Title="Track 3"};
+            var fourth = new Track(ratings) { IsExcluded = true, Title = "Track 4" };
+            List<Track> tracks = new List<Track>();
+            tracks.AddRange(new Track[] { first, second, third, fourth });
+
+            var newTracks = new List<Track>(tracks.OnceRoundStartingAfter(third));
+
+            var next = tracks.OnceRoundStartingAfter(third).Where(t => !t.IsExcluded).FirstOrDefault();
+            Assert.AreSame(second, next);
+        }
+
+        [TestMethod]
+        public void ListsWithDifferentItemsAreNotEqual()
+        {
+            Assert.IsFalse(AreListsEqual(new int[] { 1, 2, 3 }, new int[] { 1, 2, 4 }));
+        }
+
+        [TestMethod]
+        public void ListsWithDifferentLengthsAreNotEqual()
+        {
+            Assert.IsFalse(AreListsEqual(new int[] { 1, 2, 3 }, new int[] { 1, 2 }));
+        }
+
+        private static bool AreListsEqual<T>(IEnumerable<T> first, IEnumerable<T> second)
+        {
+            var firstList = first.ToList();
+            var secondList = second.ToList();
+            return (firstList.Count == secondList.Count) && firstList.Zip(secondList, (f, s) => EqualityComparer<T>.Default.Equals(f, s)).All((e) => e);
+        }
+
         public static void AssertListsAreEqual<T>(IEnumerable<T> first, IEnumerable<T> second)
-        {
-            bool areEqual = first.Zip(second, (f, s) => EqualityComparer<T>.Default.Equals(f, s)).All((e) => e);
-            if (!areEqual)
+        {            
+            if (!AreListsEqual(first,second))
             {
                 string message = String.Format("{0} != {1}",                    
                     string.Join(",", first.Select(s => s.ToString())),
                     string.Join(",", second.Select(s => s.ToString())));
-                Assert.IsTrue(areEqual, message);
+                Assert.IsTrue(false, message);
             }            
         }
     }

MusicRater/MvvmUtils/ExtensionMethods.cs

             // can't use != if T can be a struct
             // http://stackoverflow.com/questions/390900/cant-operator-be-applied-to-generic-types-in-c
             return list.SkipWhile(t => !EqualityComparer<T>.Default.Equals(t, startAfter)).Skip(1)
-                .Concat(list.TakeWhile(t => !EqualityComparer<T>.Default.Equals(t, startAfter)).Take(1));
+                .Concat(list.TakeWhile(t => !EqualityComparer<T>.Default.Equals(t, startAfter)))
+                .Concat(new T[] { startAfter });
         }
-
     }
 }