Example #1
0
        public void GetEnumeratorTest()
        {
            // Arrange
            LimitedList <object> list = new LimitedList <object>(3);

            object[] objs = new object[] {
                new object(), new object(), new object(),
            };
            foreach (var item in objs)
            {
                list.Add(item);
            }

            // Act
            IEnumerator <object> enumerator = list.GetEnumerator();

            // Assert
            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual(objs[0], enumerator.Current);
            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual(objs[1], enumerator.Current);
            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual(objs[2], enumerator.Current);
            Assert.IsFalse(enumerator.MoveNext());
        }
        async Task <T> ISaveSinglePlayerClass.RetrieveSinglePlayerGameAsync <T>()
        {
            if (_thisData.CanAutoSave == false)
            {
                throw new BasicBlankException("Should not have autosaved.  Should have first called CanOpenSavedSinglePlayerGameAsync To See");
            }


            //here, get the list.
            //_list = await fs.RetrieveSavedObjectAsync<LimitedList<IMappable>>(_gamePath); //hopefully no problem (?)

            LimitedList <T> temps = await fs.RetrieveSavedObjectAsync <LimitedList <T> >(_gamePath);

            _list = new LimitedList <IMappable>();
            _list.PopulateSavedList(temps);

            if (_data.GamePackageMode == EnumGamePackageMode.Production || RecentOne == 0)
            {
                _previousObject = _list.MostRecent.AutoMap <T>();
                return((T)_list.MostRecent !); //take a risk here too.
            }
            //in production, can add to history though.
            _previousObject = _list[RecentOne].AutoMap <T>();
            return((T)_list[RecentOne] !);

            //await Task.CompletedTask;
            //return fs.RetrieveSavedObject<T>(_gamePath);
            //return await fs.RetrieveSavedObjectAsync<T>(_gamePath);
        }
Example #3
0
        static void Main(string[] args)
        {
            var list = new LimitedList <string>(capacity: 3);

            Console.WriteLine(list.Add("first"));
            Console.WriteLine(list.Add("second"));
            Console.WriteLine(list.Add("third"));
            Console.WriteLine(list.Add("fourth"));

            //list.Remove("first");

            //for (int i = 0; i < list.Count; i++)
            //{
            //    Console.WriteLine(list[i]);
            //}

            //foreach (var item in list)
            //{
            //    Console.WriteLine(item);
            //}

            foreach (var item in GetEvenNumbers())
            {
                Console.WriteLine(item);
                if (item > 100)
                {
                    break;
                }
            }

            Console.WriteLine("hit any key");
            Console.ReadKey();
        }
Example #4
0
        public override int Visit(ResurrectSpecificCreatureSpellAbility spellAbility)
        {
            Log(OwnerCard.Name + " used ResurrectSpecificCreatureSpellAbility");
            LimitedList <CreatureCard> reborn = new LimitedList <CreatureCard>((AmaruConstants.OUTER_MAX_SIZE - GameManager.UserDict[Owner].Player.Outer.Count) < 3 ? (AmaruConstants.OUTER_MAX_SIZE - GameManager.UserDict[Owner].Player.Outer.Count) : 3);

            try
            {
                foreach (CreatureCard c in GameManager.Graveyard)
                {
                    if (c.CardEnum.Equals(Amaru.BodyGuardian) || c.CardEnum.Equals(Amaru.SoulGuardian))
                    {
                        reborn.Add((CreatureCard)c.Original);
                    }
                }
            }
            catch (LimitedListOutOfBoundException) { }
            finally
            {
                foreach (CreatureCard card in reborn)
                {
                    Log(OwnerCard.Name + " used ResurrectSpecificCreatureSpellAbility, resurrected " + card.Name);
                    GameManager.Graveyard.Remove(card);
                    GameManager.UserDict[Owner].Player.Outer.Add(card);
                    foreach (CharacterEnum ch in GameManager.UserDict.Keys)
                    {
                        AddResponse(ch, new ResurrectResponse(Owner, card, Place.OUTER));
                    }
                }
            }
            return(0);
        }
Example #5
0
 public override void Write(Utf8JsonWriter writer, LimitedList <IMappable> value, JsonSerializerOptions options)
 {
     writer.WriteStartArray();
     foreach (var item in value)
     {
         JsonSerializer.Serialize(writer, item, options);
     }
     writer.WriteEndArray();
 }
Example #6
0
        private void Run(object o)
        {
            string itemCode = (string)o;

            string lastPrice = "";

            LimitedList <double> ll3 = new LimitedList <double>(3);
            LimitedList <double> ll5 = new LimitedList <double>(5);
            LimitedList <double> ll7 = new LimitedList <double>(7);

            int rnd = ItemCodeSet.GetItemRoundNum(itemCode);

            while (true)
            {
                if (!SiseStorage.Instance.Prices.ContainsKey(itemCode))
                {
                    System.Threading.Thread.Sleep(1000);
                    continue;
                }

                var priceQueue = SiseStorage.Instance.Prices[itemCode];

                if (priceQueue.Count == 0)
                {
                    System.Threading.Thread.Sleep(100);
                    continue;
                }
                CurrentPrice price;
                var          isDequeue = priceQueue.TryDequeue(out price);
                if (isDequeue)
                {
                    if (lastPrice == price.price)
                    {
                        continue;
                    }
                    lastPrice = price.price;

                    double d = Math.Round(Convert.ToDouble(lastPrice), rnd);
                    ll3.Insert(d);
                    ll5.Insert(d);
                    ll7.Insert(d);
                    price.price3 = ll3.Count == 3 ? Math.Round(ll3.Average(), rnd) : 0;
                    price.price5 = ll3.Count == 5 ? Math.Round(ll5.Average(), rnd) : 0;
                    price.price7 = ll3.Count == 7 ? Math.Round(ll7.Average(), rnd) : 0;

                    SiseEvents.Instance.OnSiseHandler(itemCode, price);

                    PPStorage.Instance.Add(itemCode, price.DTime, (Single)Math.Round(Convert.ToSingle(price.price), rnd));

                    if (isSiseBinding)
                    {
                        BindSise(itemCode, price);
                    }
                }
            }
        }
Example #7
0
        public void Instatiate_Keeps_Capacity()  // Constructor
        {
            //arrange
            int capacity = 4;
            //act
            LimitedList <object> limitedList = new LimitedList <object>(capacity);

            //assert
            Assert.AreEqual(capacity, limitedList.Capacity);
        }
Example #8
0
        public void Add_When_Not_Full_Succeds()
        {
            //arrange
            var list = new LimitedList <object>(1);

            //act
            var added = list.Add(new object());

            //assert
            Assert.IsTrue(added);
        }
Example #9
0
        public static bool IsMatchedUpDownPattern(LimitedList <double> yList, double upPrice, double downPrice, UpDownPatternEnum pattern)
        {
            string pattStr = EnumUtil.GetUpDownPatternToChars(pattern);

            if (pattStr.Length == 0)
            {
                return(false);
            }
            var list = yList.ToList();

            if (list.Count < 3)
            {
                return(false);
            }

            string result     = "";
            string lastResult = "";

            int idx = 0;

            try
            {
                if (list[0] < upPrice && list[0] > downPrice)
                {
                    return(false);
                }

                for (; idx < list.Count; idx++)
                {
                    if (upPrice <= list[idx] && lastResult != "U")
                    {
                        result    += "U";
                        lastResult = "U";
                    }
                    else if (downPrice >= list[idx] && lastResult != "D")
                    {
                        result    += "D";
                        lastResult = "D";
                    }


                    if (result.Length == pattStr.Length)
                    {
                        break;
                    }
                }
                result = ReverseXor(result);
                return(result == pattStr);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #10
0
        public void IsFull_False_Test()
        {
            // Arrange
            LimitedList <object> list = new LimitedList <object>(2);

            // Act
            list.Add(new object());

            // Assert
            Assert.IsFalse(list.IsFull);
        }
Example #11
0
        public void LimitedList_Create_Test()
        {
            // Arrange
            int capacity = 4;

            // Act
            LimitedList <object> list = new LimitedList <object>(capacity);

            // Assert
            Assert.AreEqual(capacity, list.Capacity);
        }
 public void SetUp()
 {
     if (TestContext.TestName.EndsWith('0'))
     {
         list = new LimitedList <int>(0);
     }
     else
     {
         list = new LimitedList <int>(6);
     }
 }
        public void CreateList_WithCapacity_ReturnsCapacity()
        {
            //Arrange
            const int expected = 10;
            var       list     = new LimitedList <string>(expected);
            //Act
            var actual = list.Capacity;

            //Assert
            Assert.AreEqual(expected, actual);
        }
Example #14
0
        public MixViewModel(MixModel mix)
            : base(mix)
        {
            mix.PropertyChanged += HandleMixModelPropertyChanged;

            RootEvaluator = MixEntryModelToMixEvaluator(mix.RootMixEntry);

            _currentSongs = new LimitedList <SongViewModel>(new SongSortGenericOrder(MixSortOrderToSongProperty(mix.SortType), MixSortOrderToIsAscending(mix.SortType)), mix.Limit, mix.HasLimit);

            ResetLength();
        }
    public void PopulateSavedList <R>(LimitedList <R> oldList)
    {
        int x = 0;

        foreach (var item in oldList)
        {
            _values[x] = (T)item;
            _upTo++;
            x++;
        }
    }
 async Task ISaveSinglePlayerClass.DeleteSinglePlayerGameAsync()
 {
     if (_thisData.CanAutoSave == false)
     {
         return;
     }
     if (_list != null)
     {
         _list = new LimitedList <IMappable>(); //i think
     }
     await DeleteFileAsync(_gamePath);
 }
        public void Add_ToNotFullList_ReturnsTrue()
        {
            const int expected = 2;
            var       list     = new LimitedList <int>(expected);

            list.Add(2);

            var added = list.Add(5);

            Assert.AreEqual(true, added);
            Assert.AreEqual(expected, list.Count);
        }
Example #18
0
        //public Hero() : base( name:"Roger HjƤlte",symbol: "@", color: ConsoleColor.White) //- simplare tecken anvƤnt
        public Hero()   : base(name: "Roger HjƤlte",
                               symbol: "ā˜»",
                               color: ConsoleColor.White)  //- paras med att i Games lƤgga till:
                                                           //- Console.OutputEncoding = System.Text.Encoding.UTF8;
        {
            //Color = ConsoleColor.Cyan; //- flyttat till basklassen
            //Symbol = "@";              //- flyttat till basklassen

            Health   = 5;
            Damage   = 1;
            BackPack = new LimitedList <Item>(3);
        }
 public void tt() {
     var b = new LimitedList<int>(5);
     foreach (var i in Enumerable.Range(0, 1000))
         b.Add(i);
     var a = b.ToArray();
     Assert.AreEqual(5, a.Length);
     Assert.AreEqual(999, a[0]);
     Assert.AreEqual(998, a[1]);
     Assert.AreEqual(997, a[2]);
     Assert.AreEqual(996, a[3]);
     Assert.AreEqual(995, a[4]);
 }
Example #20
0
        async Task <string> IMultiplayerSaveState.SavedDataAsync <T>()
        {
            if (_game.CanAutoSave == false)
            {
                return("");
            }
            if (_test.SaveOption == EnumTestSaveCategory.NoSave)
            {
                return("");
            }

            string pathUsed = "";

            if (_data.MultiPlayer == false)
            {
                if (FileExists(_localPath) == false)
                {
                    return("");
                }
                pathUsed = _localPath;
                //return await AllTextAsync(_localPath); //they have to deseriaize it later.
            }

            if (_data.MultiPlayer == true && FileExists(_multiPath) == false)
            {
                return("");
            }
            if (_data.MultiPlayer)
            {
                pathUsed = _multiPath;
            }

            LimitedList <T> temps = await fs.RetrieveSavedObjectAsync <LimitedList <T> >(pathUsed);

            _list = new LimitedList <IMappable>();
            _list.PopulateSavedList(temps);
            //looks like i have to do generics after all.
            //if i did as string, then even if i could get it to work eventually, the problem is i can't easily debug anymore.
            //can't deserialize as string or even imappable.
            //if i made it more picky, then later causes other issues.


            if (_test.StatePosition == 0)
            {
                _previousObject = _list.MostRecent;
            }
            else
            {
                _previousObject = _list[_test.StatePosition];
            }
            return(JsonConvert.SerializeObject(_previousObject));
        }
Example #21
0
        public void IsFull_Is_False_When_Is_Full()
        {
            //arrange
            var list = new LimitedList <object>(1);

            list.Add(new object());

            //act
            bool isFull = list.IsFull;

            //assert
            Assert.IsTrue(isFull);
        }
Example #22
0
        public void Add_When_Full_Test()
        {
            // Arrange
            int capacity = 0;
            LimitedList <object> list = new LimitedList <object>(capacity);

            // Act
            bool added = list.Add(new object());

            // Assert
            Assert.IsFalse(added);
            Assert.AreEqual(capacity, list.Count);
        }
Example #23
0
        public void Contains_False_Test()
        {
            // Arrange
            int capacity = 1;
            LimitedList <object> list = new LimitedList <object>(capacity);
            var obj = new object();

            // Act
            bool contains = list.Contains(obj);

            // Assert
            Assert.IsFalse(contains);
        }
        public void CreateList_WithZeroCapacity_Works()
        {
            const int expected = 0;
            var       list     = new LimitedList <string>(expected);

            var  actual = list.Capacity;
            bool added  = list.Add("No");
            int  count  = list.Count;

            Assert.AreEqual(expected, actual);
            Assert.IsFalse(added);
            Assert.AreEqual(expected, count);
        }
Example #25
0
        public void Add_When_Full_Fails()
        {
            //arrange
            var list = new LimitedList <object>(1);

            list.Add(new object());

            //act
            var added = list.Add(new object());

            //assert
            Assert.IsFalse(added);
        }
Example #26
0
        public void NewLimitedList_Succeeds_WhenCapacityIsPositive()
        {
            // Arrange

            // Act
            var list     = new LimitedList <string>(2);
            var capacity = list.Capacity;

            // Assert
            var expected = 2;

            Assert.AreEqual(expected, capacity, "list.Capacity after instanciation");
        }
Example #27
0
        private async Task PrivateSaveStateAsync <T>(T payLoad)
            where T : IMappable, new()
        {
            if (CanChange() == false)
            {
                return;
            }
            if (_data.MultiPlayer == true && _showCurrent == false && _data.IsXamarinForms)
            {
                await WriteAllTextAsync(_lastPath, _game.GameName); //since we have ui friendly, then when reaches the server, the server has to do the proper thing (do the parsing).

                _showCurrent = true;                                //because already shown.
            }
            string pathUsed;

            if (_data.MultiPlayer == false)
            {
                pathUsed = _localPath;
            }
            else
            {
                pathUsed = _multiPath;
            }

            bool repeat;

            if (_previousObject != null)
            {
                string oldstr = JsonConvert.SerializeObject(_previousObject);
                string newStr = JsonConvert.SerializeObject(payLoad);
                repeat          = oldstr == newStr;
                _previousObject = payLoad.AutoMap <T>();
            }
            else
            {
                _previousObject = payLoad.AutoMap <T>();
                repeat          = false;
            }
            if (_list == null)
            {
                _list = new LimitedList <IMappable>();
            }


            if (repeat == false)
            {
                _list.Add(_previousObject);
                await fs.SaveObjectAsync(pathUsed, _list); //hopefully okay.
            }
        }
Example #28
0
        public void TestLimitedList()
        {
            var list = new LimitedList <string>(10);

            foreach (var i in Enumerable.Range(0, 10))
            {
                Assert.IsTrue(list.TryAdd(i.ToString()));
            }
            Assert.AreEqual(10, list.Count);
            list.TryAdd("11");
            Assert.AreEqual(10, list.Count);
            Assert.AreEqual("1", list.First());
            Assert.AreEqual("11", list.Last());
        }
Example #29
0
        public void NewLimitedList_HasCapacity0_WhenInstancedWithNegativeCapacity()
        {
            // Arrange

            // Act
            var list = new LimitedList <string>(0);

            //var capacity = list.Capacity;

            // Assert
            //var expected = 2;
            //Assert.AreEqual(expected, capacity, "list.Capacity after instanciation");
            Assert.AreEqual(0, list.Capacity, "list.Capacity");
        }
        public void CreateList_WithNegativeCapacity_CreatesListWithZero()
        {
            const int capacity = -20;
            const int expected = 0;
            var       list     = new LimitedList <string>(capacity);

            var  actual = list.Capacity;
            bool added  = list.Add("No");
            int  count  = list.Count;

            Assert.AreEqual(expected, actual, "Capacity is not zero");
            Assert.IsFalse(added);
            Assert.AreEqual(expected, count);
        }
Example #31
0
        public void Remove_ReturnsTrue_WhenItemDoensntExists()
        {
            // Arrange
            var list = new LimitedList <string>(2);

            list.Add("1");
            list.Add("2");

            // Act
            var remove = list.Remove("3");

            // Assert
            Assert.IsFalse(remove, "remove returns false");
        }
        public PictureManager(Config config)
        {
            this.Config = config;
            lock (PicturesLock)
            {
                this.Pictures = new LockedPictureList(new PictureInfoComparer(), this.LoadExistingPictures(config.ImagesFolder, config.FileExtension));
            }

            this.Commercials = new Queue<PictureInfo>(this.LoadExistingPictures(config.CommercialsFolder, config.FileExtension));

            this.PictureHistory = new LimitedList<PictureInfo>(this.Config.MinimumImageCycle - 1);

            FileSystemWatcher imagesWatcher = new FileSystemWatcher(config.ImagesFolder, config.FileExtension);

            imagesWatcher.IncludeSubdirectories = true;
            imagesWatcher.Created += new FileSystemEventHandler(this.OnImageAdded);
            imagesWatcher.Deleted += new FileSystemEventHandler(this.OnImageRemoved);

            imagesWatcher.EnableRaisingEvents = true;
        }
 public MemoryLogger(int capacity) {
     entries = new LimitedList<LogEntry>(capacity);
 }
Example #34
0
 /// <summary>
 /// Constructor
 /// </summary>
 public EventRecorder(int pLimit)
 {
     _events = new LimitedList<iEventObject>(pLimit);
     _counters = new Dictionary<eEVENT_SEVERITY, int>();
 }
        public bool SwitchToNextPicture()
        {
            if (this.PictureHistory.List.Count >= this.Pictures.Count)
            {
                this.PictureHistory = new LimitedList<PictureInfo>(this.Config.MinimumImageCycle - 1);
            }

            PictureInfo next = this.Pictures.GetFirstExcept(this.PictureHistory.List);
            if (next != null)
            {
                this.PictureChanged(Path.Combine(this.Config.ImagesFolder, next.FilePath), Color.Black);
                next.TimesShown++;

                this.PictureHistory.Add(next);

                return true;
            }
            return false;
        }
 public EnumerableCacheTests()
 {
     _sut = new LimitedList<int>(2);
 }