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(); }
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); }
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); }
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 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); }
public static void WriteToBacklog(string message, bool newline) { if (!newline) { _backlogLine += message; } if (newline && _backlogLine == "") { _consoleBacklog.Add(message); } else { _consoleBacklog.Add(_backlogLine + message); _backlogLine = ""; } }
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()); }
public void Remove_Passes_WhenItemExists() { // Arrange var list = new LimitedList <string>(2); list.Add("1"); var result2 = list.Add("2"); // Act var removeFirst = list.Remove("1"); // Assert Assert.IsTrue(removeFirst, "remove returns true"); //Assert.AreNotEqual("1", list[0], "first item is not 1"); Assert.AreEqual("2", list[0], "1:st item becomes 0:th"); //Assert.AreEqual(1, list.Count); }
public string PickUp(Item item) { if (Backpack.Add(item)) { item.RemoveFromCell = true; return($"You pick up the {item.Name}."); } return($"The backpack is full, so you couldn't pick up the {item.Name}."); }
public void IndexOfTest() { // Arrange LimitedList <object> list = new LimitedList <object>(2); var obj1 = new Object(); var obj2 = new Object(); list.Add(obj1); list.Add(obj2); // Act int i1 = list.IndexOf(obj1); int i2 = list.IndexOf(obj2); // Assert Assert.AreEqual(0, i1); Assert.AreEqual(1, i2); }
public void AddTest() { // Arrange var list = new LimitedList <string>(2); list.Add("1"); // Act var result2 = list.Add("2"); var result3 = list.Add("3"); var count = list.Count; result3 = false; // Assert Assert.IsTrue(result2, "added last viable item"); //DÅLIGT ATT TESTA FLERA SAKER I SAMMA METOD Assert.IsFalse(result3, "added when at capacity"); Assert.AreEqual(2, count, "count should be 2"); }
public void RemoveAtTest() { // Arrange int capacity = 3; LimitedList <object> list = new LimitedList <object>(capacity); var obj1 = new object(); var obj2 = new object(); var obj3 = new object(); list.Add(obj1); list.Add(obj2); list.Add(obj3); // Act list.RemoveAt(1); // Assert Assert.AreEqual(2, list.Count); Assert.AreEqual(obj3, list[1]); }
public void IsFull_False_Test() { // Arrange LimitedList <object> list = new LimitedList <object>(2); // Act list.Add(new object()); // Assert Assert.IsFalse(list.IsFull); }
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); }
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]); }
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); }
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); }
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); }
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. } }
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); }
public void Foreach_Returns_Contents() { //arrange object obj1 = 1; object obj2 = 2; var list = new LimitedList <object>(2); list.Add(obj1); list.Add(obj2); //act var result = new List <object>(); //foreach (var item in (IEnumerable) list) //testar GetEnumerator() i LimitedList foreach (var item in list) { result.Add(item); } //assert - test att de pekar på samma referens Assert.AreEqual(obj1, result[0]); Assert.AreEqual(obj2, result[1]); }
public void Remove_NonExisting_Fails() { //arrange var obj1 = new object(); var obj2 = new object(); var list = new LimitedList <object>(1); list.Add(obj1); //act var removed = list.Remove(obj2); //assert Assert.IsFalse(removed); }
// [Ignore] public void Add_WithZeroCapasity_0() { //Arrange const int expected = 0; //var list = new LimitedList<int>(expected); //Act var tryToAdd = list.Add(1); int count = list.Count; var actual = list.Capacity; //Assert Assert.IsFalse(tryToAdd); Assert.AreEqual(count, expected); Assert.AreEqual(actual, expected); }
public void Contains_True_Test() { // Arrange int capacity = 1; LimitedList <object> list = new LimitedList <object>(capacity); var obj = new object(); list.Add(obj); // Act bool contains = list.Contains(obj); // Assert Assert.IsTrue(contains); }
public void Remove_Success_Test() { // Arrange int capacity = 1; LimitedList <object> list = new LimitedList <object>(capacity); var obj = new object(); list.Add(obj); // Act bool removed = list.Remove(obj); // Assert Assert.IsTrue(removed); Assert.IsFalse(list.Contains(obj)); }
public void Add_WithNegativeCapacity_CreatesListWithZeroCapacity() { //Arrange const int expected = 0; const int capacity = -10; var list = new LimitedList <int>(capacity); //Act var tryToAdd = list.Add(1); int count = list.Count; var actual = list.Capacity; //Assert Assert.IsFalse(tryToAdd); Assert.AreEqual(count, expected); Assert.AreEqual(actual, expected); }
public void Insert_Success_Test() { // Arrange int capacity = 2; LimitedList <object> list = new LimitedList <object>(capacity); var obj = new object(); list.Add(new object()); // Act bool inserted = list.Insert(0, obj); // Assert Assert.IsTrue(inserted); Assert.AreEqual(obj, list[0]); Assert.AreEqual(2, list.Count); }
public void Insert_When_Full_Test() { // Arrange int capacity = 1; LimitedList <object> list = new LimitedList <object>(capacity); var obj = new object(); list.Add(new object()); // Act bool inserted = list.Insert(0, obj); // Assert Assert.IsFalse(inserted); Assert.AreNotEqual(obj, list[0]); Assert.AreEqual(1, list.Count); }
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]); }
public void Remove_Existing_Suceeds() { //arrange var obj = new object(); var list = new LimitedList <object>(1); list.Add(obj); //act var removed = list.Remove(obj); //assert Assert.IsTrue(removed); foreach (var item in list) //inget obj ska vara samma som det borttagna { Assert.AreNotEqual(obj, item); } }
async Task ISaveSinglePlayerClass.SaveSimpleSinglePlayerGameAsync <T>(T thisObject) { if (_thisData.CanAutoSave == false) { return; } if (thisObject == null) { throw new BasicBlankException("Cannot save null object. Rethink"); } //fs.SaveObject(_gamePath, thisObject); //string content = JsonConvert.SerializeObject(thisObject, Formatting.Indented); ////i guess i can't do the serializing that way anymore. //WriteAllText(_gamePath, content); //await Task.CompletedTask; bool repeat; if (_previousObject != null) { //bool rets = _previousObject.Equals(thisObject); string oldstr = JsonConvert.SerializeObject(_previousObject); string newStr = JsonConvert.SerializeObject(thisObject); repeat = oldstr == newStr; _previousObject = thisObject.AutoMap <T>(); } else { _previousObject = thisObject.AutoMap <T>(); repeat = false; } if (_list == null) { _list = new LimitedList <IMappable>(); } if (repeat == false) { _list.Add(_previousObject); await fs.SaveObjectAsync(_gamePath, _list); //hopefully okay. } }