public void ShouldReplaceMappedQueueItem(BiConverter <Converter <TestObj, int>, IComparer <TestObj>, SortedMappedQueue <TestObj> > queueCreator) { // given Converter <TestObj, int> keyExtractor = obj => obj.Id; var comparer = Comparers.CompareBy <TestObj, DateTime>(obj => obj.Date); var queue = queueCreator(keyExtractor, comparer); var obj1 = new TestObj { Id = 1, Date = new DateTime(2015, 6, 17, 13, 30, 0) }; var obj2 = new TestObj { Id = 1, Date = new DateTime(2015, 6, 17, 15, 30, 0) }; var obj3 = new TestObj { Id = 2, Date = new DateTime(2015, 6, 17, 13, 35, 0) }; // when var offer1Accepted = queue.Offer(obj1); var offer2Accepted = queue.Offer(obj2); var offer3Accepted = queue.Offer(obj3); queue.Put(obj2); // then Check.That(offer1Accepted).IsTrue(); Check.That(offer2Accepted).IsFalse(); Check.That(offer3Accepted).IsTrue(); Check.That(queue).ContainsExactly(obj3, obj2); }
public void ShouldCreateComparerWithComparableConverter() { // given Converter <TestObj, int> comparableConverter = obj => obj.Value; var comparer = Comparers.CompareBy(comparableConverter); var list = new List <TestObj> { new TestObj { Value = 5 }, new TestObj { Value = 3 }, new TestObj { Value = 1 }, new TestObj { Value = 4 } }; // when list.Sort(comparer); // then Check.That(list).ContainsExactly( new TestObj { Value = 1 }, new TestObj { Value = 3 }, new TestObj { Value = 4 }, new TestObj { Value = 5 }); }