public void TestAddToEndByItemIdSucceeds()
 {
     var timeline = new ItemPurchaseTimeline();
     timeline.AddToEndByItemId(2009, TimeSpan.Zero);
     timeline.AddToEndByItemId(2009, TimeSpan.Zero);
     timeline.AddToEndByItemId(2009, new TimeSpan(10));
     Assert.AreEqual(3, timeline.Count);
 }
 public void TestIsArrayIndexable()
 {
     var timeline = new ItemPurchaseTimeline();
     timeline.AddToEndByItemId(2009, new TimeSpan(10));
     timeline.AddToEndByItemId(3087, new TimeSpan(20));
     timeline.AddToEndByItemId(3290, new TimeSpan(30));
     Assert.AreEqual(3, timeline.Count);
     Assert.AreEqual(2009, timeline[0].Id);
     Assert.AreEqual(3087, timeline[1].Id);
     Assert.AreEqual(3290, timeline[2].Id);
 }
        public void TestCanBeWrittenToDatabase()
        {
            var timeline = new ItemPurchaseTimeline();
            timeline.AddToEndByItemId(3086, TimeSpan.Zero);
            timeline.AddToEndByItemId(3087, TimeSpan.FromSeconds(14));
            timeline.AddToEndByItemId(3087, TimeSpan.FromSeconds(16));

            var context = new GameContext();
            var proGame = new ProPlayerGame();
            proGame.GameId = 1;
            proGame.SummonerId = 5;
            proGame.ItemPurchaseTimeline = timeline;
            context.Games.Add(proGame);
            context.SaveChanges();
        }
        public void TestAdcStartingItemsAreDistanceOfTwoWithoutTimeGrouping()
        {
            var timeline1 = new ItemPurchaseTimeline();
            var timeline2 = new ItemPurchaseTimeline();

            // potion, doran's blade, then trinket
            timeline1.AddToEndByItemId(2003, TimeSpan.Zero);
            timeline1.AddToEndByItemId(1055, TimeSpan.Zero);
            timeline1.AddToEndByItemId(3340, TimeSpan.Zero);

            // trinket, dblade, then potion
            timeline2.AddToEndByItemId(3340, TimeSpan.Zero);
            timeline2.AddToEndByItemId(1055, TimeSpan.Zero);
            timeline2.AddToEndByItemId(2003, TimeSpan.Zero);

            var comparer = new ItemPurchaseTimelineComparer(groupItemsByTime: false);
            Assert.AreEqual(2, comparer.DistanceBetween(timeline1, timeline2));
        }
        public void TestIfReorderingResultsInWorseDistanceWeDontReorderInMoreSubtleCase()
        {
            var timeline1 = new ItemPurchaseTimeline();
            var timeline2 = new ItemPurchaseTimeline();

            timeline1.AddToEndByItemId(3340, TimeSpan.Zero);
            timeline1.AddToEndByItemId(2003, TimeSpan.Zero + TimeSpan.FromSeconds(16));
            timeline1.AddToEndByItemId(1055, TimeSpan.Zero + TimeSpan.FromSeconds(32));
            timeline1.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(48));

            timeline2.AddToEndByItemId(3340, TimeSpan.Zero);
            timeline2.AddToEndByItemId(2003, TimeSpan.Zero);
            timeline2.AddToEndByItemId(1055, TimeSpan.Zero);
            timeline2.AddToEndByItemId(3048, TimeSpan.Zero);

            // reordering would be very bad here, as they were already only a distance of 1
            var comparer = new ItemPurchaseTimelineComparer(false);
            Assert.AreEqual(1, comparer.DistanceBetween(timeline1, timeline2));
        }
        public void TestAdcStartingItemsAreDistanceOfTwoWithTimeGroupingButPurchasedFarApart()
        {
            var timeline1 = new ItemPurchaseTimeline();
            var timeline2 = new ItemPurchaseTimeline();

            // potion, doran's blade, then trinket
            timeline1.AddToEndByItemId(2003, TimeSpan.Zero);
            timeline1.AddToEndByItemId(1055, TimeSpan.Zero + TimeSpan.FromSeconds(16));
            timeline1.AddToEndByItemId(3340, TimeSpan.Zero + TimeSpan.FromSeconds(32));

            // trinket, dblade, then potion
            timeline2.AddToEndByItemId(3340, TimeSpan.Zero);
            timeline2.AddToEndByItemId(1055, TimeSpan.Zero);
            timeline2.AddToEndByItemId(2003, TimeSpan.Zero);

            // don't ignore consumables
            var comparer = new ItemPurchaseTimelineComparer(false);
            Assert.AreEqual(2, comparer.DistanceBetween(timeline1, timeline2));
        }
Exemplo n.º 7
0
        public void TestSetup()
        {
            timeline1 = new ItemPurchaseTimeline();
            timeline1.AddToEndByItemId(3340, TimeSpan.Zero);
            timeline1.AddToEndByItemId(2003, TimeSpan.Zero + TimeSpan.FromSeconds(16));
            timeline1.AddToEndByItemId(1055, TimeSpan.Zero + TimeSpan.FromSeconds(32));
            timeline1.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(48));
            timeline1.AddToEndByItemId(1054, TimeSpan.Zero + TimeSpan.FromSeconds(64));

            // timeline 2 will be similar to item 1, but not identical
            timeline2 = new ItemPurchaseTimeline();
            timeline2.AddToEndByItemId(3340, TimeSpan.Zero);
            timeline2.AddToEndByItemId(2003, TimeSpan.Zero + TimeSpan.FromSeconds(16));
            timeline2.AddToEndByItemId(1055, TimeSpan.Zero + TimeSpan.FromSeconds(32));
            timeline2.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(48));
            timeline2.AddToEndByItemId(2049, TimeSpan.Zero + TimeSpan.FromSeconds(64));

            // timeline 3 is the same as game 1 but is longer. it should be included
            // in their cluster because it is so close (0 distance) to 1
            timeline3 = new ItemPurchaseTimeline();
            timeline3.AddToEndByItemId(3340, TimeSpan.Zero);
            timeline3.AddToEndByItemId(2003, TimeSpan.Zero + TimeSpan.FromSeconds(16));
            timeline3.AddToEndByItemId(1055, TimeSpan.Zero + TimeSpan.FromSeconds(32));
            timeline3.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(48));
            timeline3.AddToEndByItemId(1054, TimeSpan.Zero + TimeSpan.FromSeconds(64));
            timeline3.AddToEndByItemId(2049, TimeSpan.Zero + TimeSpan.FromSeconds(80));
            timeline3.AddToEndByItemId(1037, TimeSpan.Zero + TimeSpan.FromSeconds(96));
            timeline3.AddToEndByItemId(1036, TimeSpan.Zero + TimeSpan.FromSeconds(112));
            timeline3.AddToEndByItemId(1039, TimeSpan.Zero + TimeSpan.FromSeconds(128));
            timeline3.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(144));

            // timeline 4 is a new build
            timeline4 = new ItemPurchaseTimeline();
            timeline4.AddToEndByItemId(3041, TimeSpan.Zero);
            timeline4.AddToEndByItemId(3181, TimeSpan.Zero + TimeSpan.FromSeconds(16));
            timeline4.AddToEndByItemId(3042, TimeSpan.Zero + TimeSpan.FromSeconds(32));
            timeline4.AddToEndByItemId(3301, TimeSpan.Zero + TimeSpan.FromSeconds(48));
            timeline4.AddToEndByItemId(1052, TimeSpan.Zero + TimeSpan.FromSeconds(64));

            // timeline 5 is a duplicate of build 4
            timeline5 = new ItemPurchaseTimeline();
            timeline5.AddToEndByItemId(3041, TimeSpan.Zero);
            timeline5.AddToEndByItemId(3181, TimeSpan.Zero + TimeSpan.FromSeconds(16));
            timeline5.AddToEndByItemId(3042, TimeSpan.Zero + TimeSpan.FromSeconds(32));
            timeline5.AddToEndByItemId(3301, TimeSpan.Zero + TimeSpan.FromSeconds(48));
            timeline5.AddToEndByItemId(1052, TimeSpan.Zero + TimeSpan.FromSeconds(64));

            // timeline 6 is just too different to be in anything and should be noise
            timeline6 = new ItemPurchaseTimeline();
            timeline6.AddToEndByItemId(3041, TimeSpan.Zero);
            timeline6.AddToEndByItemId(3340, TimeSpan.Zero + TimeSpan.FromSeconds(16));
            timeline6.AddToEndByItemId(2003, TimeSpan.Zero + TimeSpan.FromSeconds(32));
            timeline6.AddToEndByItemId(1055, TimeSpan.Zero + TimeSpan.FromSeconds(48));
            timeline6.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(64));
            timeline6.AddToEndByItemId(1054, TimeSpan.Zero + TimeSpan.FromSeconds(80));
            timeline6.AddToEndByItemId(2049, TimeSpan.Zero + TimeSpan.FromSeconds(96));
            timeline6.AddToEndByItemId(1037, TimeSpan.Zero + TimeSpan.FromSeconds(112));
            timeline6.AddToEndByItemId(1036, TimeSpan.Zero + TimeSpan.FromSeconds(128));
            timeline6.AddToEndByItemId(1039, TimeSpan.Zero + TimeSpan.FromSeconds(144));
            timeline6.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(160));
            timeline6.AddToEndByItemId(3181, TimeSpan.Zero + TimeSpan.FromSeconds(176));
            timeline6.AddToEndByItemId(3042, TimeSpan.Zero + TimeSpan.FromSeconds(192));
            timeline6.AddToEndByItemId(3301, TimeSpan.Zero + TimeSpan.FromSeconds(208));
            timeline6.AddToEndByItemId(1052, TimeSpan.Zero + TimeSpan.FromSeconds(224));
        }
        public void TestOutOfOrderItemsIsDistanceOfTwo()
        {
            var timeline1 = new ItemPurchaseTimeline();
            var timeline2 = new ItemPurchaseTimeline();

            // statikk shiv then biscuit
            timeline1.AddToEndByItemId(3087, TimeSpan.Zero);
            timeline1.AddToEndByItemId(2009, TimeSpan.Zero);

            // biscuit, then statikk shiv
            timeline2.AddToEndByItemId(2009, TimeSpan.Zero);
            timeline2.AddToEndByItemId(3087, TimeSpan.Zero);

            var comparer = new ItemPurchaseTimelineComparer(false, false);
            Assert.AreEqual(2, comparer.DistanceBetween(timeline1, timeline2));
        }
 public void TestAddToEndByItemIdExceptionsWithInvalidTime()
 {
     var timeline = new ItemPurchaseTimeline();
     timeline.AddToEndByItemId(2009, new TimeSpan(10));
     timeline.AddToEndByItemId(2009, TimeSpan.Zero);
 }
Exemplo n.º 10
0
 public void TestTwoItemBlock()
 {
     var timeline = new ItemPurchaseTimeline();
     timeline.AddToEndByItemId(3086, TimeSpan.Zero);
     timeline.AddToEndByItemId(3087, TimeSpan.FromSeconds(14));
     timeline.AddToEndByItemId(3087, TimeSpan.FromSeconds(16));
     var itemBlocks = timeline.TryToSplitIntoPurchases(15);
     Assert.AreEqual(2, itemBlocks.Count);
     Assert.AreEqual(2, itemBlocks[0].Items.Count);
     Assert.AreEqual("First Purchase", itemBlocks[0].Name);
     Assert.AreEqual(1, itemBlocks[1].Items.Count);
     Assert.AreEqual("Next Purchase", itemBlocks[1].Name);
 }
Exemplo n.º 11
0
 public void TestToString()
 {
     var timeline = new ItemPurchaseTimeline();
     timeline.AddToEndByItemId(3086, new TimeSpan(10));
     timeline.AddToEndByItemId(3087, new TimeSpan(20));
     Assert.AreEqual("Zeal -> Statikk Shiv", timeline.ToString());
 }
Exemplo n.º 12
0
 public void TestOneBigItemBlock()
 {
     var timeline = new ItemPurchaseTimeline();
     timeline.AddToEndByItemId(3086, new TimeSpan(10));
     timeline.AddToEndByItemId(3087, new TimeSpan(20));
     timeline.AddToEndByItemId(3087, new TimeSpan(20));
     var itemBlocks = timeline.TryToSplitIntoPurchases(15);
     Assert.AreEqual(1, itemBlocks.Count);
     Assert.AreEqual("First Purchase", itemBlocks[0].Name);
 }
Exemplo n.º 13
0
 public void TestJsonSerialization()
 {
     var timeline = new ItemPurchaseTimeline();
     timeline.AddToEndByItemId(3086, TimeSpan.Zero);
     timeline.AddToEndByItemId(3087, TimeSpan.FromSeconds(14));
     timeline.AddToEndByItemId(3087, TimeSpan.FromSeconds(16));
     var json = JsonConvert.SerializeObject(timeline);
     var enumerable = JsonConvert.DeserializeObject<IEnumerable<Item>>(json);
     var newTimeilne = new ItemPurchaseTimeline(enumerable);
     Assert.AreEqual(3, newTimeilne.Count);
     Assert.AreEqual(3086, newTimeilne[0].Id);
     Assert.AreEqual(3087, newTimeilne[1].Id);
     Assert.AreEqual(3087, newTimeilne[2].Id);
 }
        public void TestShortEqualTimelinesWithDifferentLengthsAreEqual()
        {
            var timeline1 = new ItemPurchaseTimeline();
            var timeline2 = new ItemPurchaseTimeline();

            // statikk shiv
            timeline1.AddToEndByItemId(3087, TimeSpan.Zero);
            // biscuit
            timeline1.AddToEndByItemId(2009, TimeSpan.Zero);

            timeline2.AddToEndByItemId(3087, TimeSpan.Zero);

            var comparer = new ItemPurchaseTimelineComparer(false, false);
            Assert.AreEqual(0, comparer.DistanceBetween(timeline1, timeline2));
        }
        public void TestShortTimelinesWithConsumablesAreNotEqualWhenConsumablesConsidered()
        {
            var timeline1 = new ItemPurchaseTimeline();
            var timeline2 = new ItemPurchaseTimeline();

            // biscuit
            timeline1.AddToEndByItemId(2009, TimeSpan.Zero);
            // statikk shiv
            timeline1.AddToEndByItemId(3087, TimeSpan.Zero);

            timeline2.AddToEndByItemId(3087, TimeSpan.Zero);

            var comparer = new ItemPurchaseTimelineComparer(false);
            Assert.AreEqual(1, comparer.DistanceBetween(timeline1, timeline2));
        }
        public void TestVeryLongLongAndDifferentTimelineDoesNotMatchSubTimeline()
        {
            var timeline1 = new ItemPurchaseTimeline();
            timeline1.AddToEndByItemId(3340, TimeSpan.Zero);
            timeline1.AddToEndByItemId(2003, TimeSpan.Zero + TimeSpan.FromSeconds(16));
            timeline1.AddToEndByItemId(1055, TimeSpan.Zero + TimeSpan.FromSeconds(32));
            timeline1.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(48));
            timeline1.AddToEndByItemId(1054, TimeSpan.Zero + TimeSpan.FromSeconds(64));

            var timeline6 = new ItemPurchaseTimeline();
            timeline6.AddToEndByItemId(3041, TimeSpan.Zero);
            timeline6.AddToEndByItemId(3340, TimeSpan.Zero + TimeSpan.FromSeconds(16));
            timeline6.AddToEndByItemId(2003, TimeSpan.Zero + TimeSpan.FromSeconds(32));
            timeline6.AddToEndByItemId(1055, TimeSpan.Zero + TimeSpan.FromSeconds(48));
            timeline6.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(64));
            timeline6.AddToEndByItemId(1054, TimeSpan.Zero + TimeSpan.FromSeconds(80));
            timeline6.AddToEndByItemId(2049, TimeSpan.Zero + TimeSpan.FromSeconds(96));
            timeline6.AddToEndByItemId(1037, TimeSpan.Zero + TimeSpan.FromSeconds(112));
            timeline6.AddToEndByItemId(1036, TimeSpan.Zero + TimeSpan.FromSeconds(128));
            timeline6.AddToEndByItemId(1039, TimeSpan.Zero + TimeSpan.FromSeconds(144));
            timeline6.AddToEndByItemId(1038, TimeSpan.Zero + TimeSpan.FromSeconds(160));
            timeline6.AddToEndByItemId(3181, TimeSpan.Zero + TimeSpan.FromSeconds(176));
            timeline6.AddToEndByItemId(3042, TimeSpan.Zero + TimeSpan.FromSeconds(192));
            timeline6.AddToEndByItemId(3301, TimeSpan.Zero + TimeSpan.FromSeconds(208));
            timeline6.AddToEndByItemId(1052, TimeSpan.Zero + TimeSpan.FromSeconds(224));

            var comparer = new ItemPurchaseTimelineComparer(false);
            Assert.AreEqual(10, comparer.DistanceBetween(timeline1, timeline6));
        }
        public void TestShortTimelinesWithNoConsumablesAreEqual()
        {
            var timeline1 = new ItemPurchaseTimeline();
            var timeline2 = new ItemPurchaseTimeline();

            // statikk shiv
            timeline1.AddToEndByItemId(3087, TimeSpan.Zero);
            timeline2.AddToEndByItemId(3087, TimeSpan.Zero);

            var comparer = new ItemPurchaseTimelineComparer();
            Assert.AreEqual(0, comparer.DistanceBetween(timeline1, timeline2));
        }
Exemplo n.º 18
0
        public void TestIsEnumerableInOrder()
        {
            var timeline = new ItemPurchaseTimeline();
            timeline.AddToEndByItemId(2009, new TimeSpan(10));
            timeline.AddToEndByItemId(3087, new TimeSpan(20));
            timeline.AddToEndByItemId(3290, new TimeSpan(30));
            Assert.AreEqual(3, timeline.Count);

            var previousItemId = 0;
            var previousTimestamp = TimeSpan.Zero;
            foreach(var item in timeline)
            {
                Assert.IsTrue(item.Id > previousItemId);
                Assert.IsTrue(item.TimeOfPurchase > previousTimestamp);

                previousItemId = item.Id;
                previousTimestamp = item.TimeOfPurchase;
            }
        }
        public void TestItemChangeIsDistanceOfOne()
        {
            var timeline1 = new ItemPurchaseTimeline();
            var timeline2 = new ItemPurchaseTimeline();

            // statikk shiv then biscuit
            timeline1.AddToEndByItemId(3087, TimeSpan.Zero);
            timeline1.AddToEndByItemId(2009, TimeSpan.Zero);

            // statikk shiv then warmogs
            timeline2.AddToEndByItemId(3087, TimeSpan.Zero);
            timeline2.AddToEndByItemId(3083, TimeSpan.Zero);

            var comparer = new ItemPurchaseTimelineComparer(false, false);
            Assert.AreEqual(1, comparer.DistanceBetween(timeline1, timeline2));
        }