public void Given_zero_items() { var input = new List<string>(); var persistentList = new PersistentList<string>(input); // should not throw if no items persistentList.Sort((x, y) => String.Compare(x, y, StringComparison.Ordinal)); }
public void Given_one_item() { var input = new[] { "a" }; var persistentList = new PersistentList<string>(input); // should not throw if only one item persistentList.Sort((x, y) => String.Compare(x, y, StringComparison.Ordinal)); }
public void PersistentListTests() { IPersistentList <int> target = new PersistentList <int>(); target = target.Cons(1); target = target.Cons(5); target = target.Cons(10); Assert.AreEqual(3, target.Count); Assert.AreEqual(10, target.Peek()); target = target.Pop(); Assert.AreEqual(2, target.Count); Assert.AreEqual(5, target.Peek()); var init = new List <int> { 5, 1 }; IPersistentList <int> target2 = new PersistentList <int>(init); Assert.AreEqual(target, target2); Assert.AreEqual(target, target2); Assert.AreEqual(target.GetHashCode(), target2.GetHashCode()); Assert.AreNotSame(target, target2); target = target.Without(1); Assert.AreEqual(1, target.Count); Assert.AreEqual(5, target.Peek()); target = target.Empty(); Assert.AreEqual(0, target.Count); }
public void PopOnSingletonListYieldsEmptyList() { PersistentList p = new PersistentList("abc"); IPersistentStack s = p.pop(); Expect(s.count(), EqualTo(0)); }
public void IncorrectSourceCollectionCountTest() { Assert.Throws <ArgumentException>( () => PersistentList <int> .OfReadonly(new DeficientCollection())); Assert.Throws <ArgumentOutOfRangeException>( () => PersistentList <int> .OfReadonly(new NegativeCountCollection())); }
static void Main(string[] args) { PersistentList<int> pl = new PersistentList<int>(new List<int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })); Console.WriteLine("Añadiendo nodo con valor 22"); Console.WriteLine("Ultimo Nodo: {0}", pl.LastNode); pl.Add(22); Console.WriteLine("Añadiendo nodo con valor 42"); Console.WriteLine("Ultimo Nodo: {0}", pl.LastNode); pl.Add(42); Console.WriteLine("Añadiendo nodo con valor 62"); Console.WriteLine("Ultimo Nodo: {0}", pl.LastNode); pl.Add(62); Console.WriteLine("Añadiendo nodo con valor 82"); Console.WriteLine("Ultimo Nodo: {0}", pl.LastNode); pl.Add(82); Print(pl); Console.WriteLine("Last Node : {0}", pl.LastNode); Console.WriteLine(" ===================================================== "); Console.WriteLine("Deshaciendo ultima operacion ( eliminar nodo con valor 82 )"); pl.Undo(); Console.WriteLine("Ultimo Nodo: {0}", pl.LastNode); Console.WriteLine("Deshaciendo ultima operacion ( eliminar nodo con valor 62 )"); pl.Undo(); Console.WriteLine("Ultimo Nodo: {0}", pl.LastNode); Print(pl); Console.WriteLine("Last Node : {0}", pl.LastNode); Console.ReadLine(); }
public void Post([FromBody] Mensagem mensagem) { var list = PersistentList.Create <Mensagem>(); list.Add(mensagem); list.Save(); }
public void EmptyHasNoElements() { PersistentList p = new PersistentList("abc"); IPersistentCollection c = p.empty(); Expect(c.count(), EqualTo(0)); }
public void PeekYieldsFirstElementAndListUnchanged() { PersistentList p = (PersistentList)PersistentList.create(new object[] { "abc", 1, "def" }); Expect(p.peek(), EqualTo("abc")); Expect(p.count(), EqualTo(3)); }
protected override void OnSave(ConfigNode node) { base.OnSave(node); update_and_checkin(vessel); var workshops = new PersistentList <ProtoWorkshop>(ProtoWorkshops.Values); workshops.Save(node.AddNode("Workshops")); }
public void OneArgCtorConstructsListOfOneElement() { PersistentList p = new PersistentList("abc"); Expect(p.first()).To.Equal("abc"); Expect(p.next()).To.Be.Null(); Expect(p.count()).To.Equal(1); }
public void Construction_Sets_Tail() { const int head = 5; IEnumerable<int> tail = Enumerable.Range(0, 5).ToList(); var list = new PersistentList<int>(head, tail); CollectionAssert.AreEquivalent(tail, list.Tail); }
public void OneArgCtorConstructsListOfOneElement() { PersistentList p = new PersistentList("abc"); Expect(p.first(), EqualTo("abc")); Expect(p.next(), Null); Expect(p.count(), EqualTo(1)); }
public void PopLosesfirstElement() { PersistentList p = (PersistentList)PersistentList.create(new object[] { "abc", 1, "def" }); PersistentList p2 = (PersistentList)p.pop(); Expect(p2.count(), EqualTo(2)); Expect(p2.peek(), EqualTo(1)); }
public void Given__a_b() { var input = new[] { "a", "b" }; var persistentList = new PersistentList<string>(input); persistentList.Sort((x, y) => String.Compare(x, y, StringComparison.Ordinal)); persistentList[0].ShouldBeEqualTo("a"); persistentList[1].ShouldBeEqualTo("b"); }
static void Print(PersistentList<int> pl) { Node<int> _node = pl.FirstNode; // puntero nodo 0 while (_node != null) { Console.WriteLine(_node); _node = _node.Next; } }
public void Construction_Sets_Head() { const int head = 5; IEnumerable<int> tail = Enumerable.Range(0, 5); var list = new PersistentList<int>(head, tail); Assert.AreEqual(list.Head, head); }
public void Construction_Sets_Tail() { const int head = 5; IEnumerable <int> tail = Enumerable.Range(0, 5).ToList(); var list = new PersistentList <int>(head, tail); CollectionAssert.AreEquivalent(tail, list.Tail); }
public void Construction_Sets_Head() { const int head = 5; IEnumerable <int> tail = Enumerable.Range(0, 5); var list = new PersistentList <int>(head, tail); Assert.AreEqual(list.Head, head); }
public void ReduceWithStartIterates() { IFn fn = DummyFn.CreateForReduce(); PersistentList p = (PersistentList)PersistentList.create(new object[] { 1, 2, 3 }); object ret = p.reduce(fn, 20); Expect(ret, EqualTo(26)); }
public void CreateOnEmptyISeqReturnsEmptySet() { object[] items = new object[] { }; ArrayList a = new ArrayList(items); ISeq s = PersistentList.create(a).seq(); IPersistentSet m = PersistentHashSet.create(s); Expect(m.count()).To.Equal(0); }
public void CreateOnEmptyISeqReturnsEmptyMap() { object[] items = new object[] { }; ArrayList a = new ArrayList(items); ISeq s = PersistentList.create(a).seq(); IPersistentMap m = PersistentTreeMap.create(s); Expect(m.count(), EqualTo(0)); }
public void SetItemOutOfRangeTest() { const int count = 10; IPersistentList <int> list = PersistentList <int> .Of(new int[count]); Assert.Throws <IndexOutOfRangeException>(() => list.Set(-1, -1)); Assert.Throws <IndexOutOfRangeException>(() => list.Set(count, -1)); }
public void TestLoadingOfObjectsFromPersitence() { var list = BuildTestList(); list = new PersistentList<IdentifiableForTesting>(editGroup); var i = 1; foreach (var a in list) Assert.AreEqual(a.Id, i++.ToString()); Assert.AreEqual(3, list.Count); }
public void TestLoadingInsertedItemFromPersistence() { var list = BuildTestList(); list.Insert(1, new IdentifiableForTesting("x")); list = new PersistentList<IdentifiableForTesting>(editGroup); Assert.That(list.Count, Is.EqualTo(4)); Assert.That(list[1].Id, Is.EqualTo("x")); }
public void Setup() { PersistentList p1 = new PersistentList("abc"); PersistentList p2 = (PersistentList)p1.cons("def"); _pl = (PersistentList)p2.cons(7); _values = new object[] { 7, "def", "abc" }; _plWithMeta = (PersistentList)_pl.withMeta(PersistentHashMap.create("a", 1)); }
public void RemoveOutOfRangeTest() { const int count = 10; IPersistentList <int> list = PersistentList <int> .Of(new int[count]); Assert.Throws <IndexOutOfRangeException>(() => list.RemoveAt(-1)); Assert.Throws <IndexOutOfRangeException>(() => list.RemoveAt(count)); }
public PersistentListIntegration() { _file = Path.Combine(Path.GetTempPath(), "foo.jss"); File.Delete(_file); Directory.CreateDirectory(Path.GetDirectoryName(_file)); _list = new PersistentList <Tweet>( _store = new FileSystem(_file), new PrettyJsonSerializer(), new SaveOnlyWhenRequested()); }
public void Setup() { IPersistentMap meta = new DummyMeta(); PersistentList p1 = (PersistentList)PersistentList.create(new object[] { "abc", "def" }); _objWithNullMeta = (IObj)p1; _obj = _objWithNullMeta.withMeta(meta); _expectedType = typeof(PersistentList); }
public void ReduceWithStartIterates() { IFn fn = DummyFn.CreateForReduce(); PersistentList p = (PersistentList)PersistentList.create(new object[] { 1, 2, 3 }); object ret = p.reduce(fn, 20); Expect(ret).To.Be.An.Instance.Of <long>(); Expect((long)ret).To.Equal(26); }
public void Can_Enumerate_Through_Items() { const int head = 5; IEnumerable<int> tail = Enumerable.Range(0, 3).ToList(); var list = new PersistentList<int>(head, tail); var equivalent = new[] { 5, 0, 1, 2 }; CollectionAssert.AreEquivalent(equivalent, list); }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { this.InitializeComponent(); this.Suspending += this.OnSuspending; var t = new Tweet(); var list = PersistentList.Create <Tweet>(); list.Add(t); Debug.WriteLine("Size: " + list.Count); }
public void Can_Enumerate_Through_Items() { const int head = 5; IEnumerable <int> tail = Enumerable.Range(0, 3).ToList(); var list = new PersistentList <int>(head, tail); var equivalent = new[] { 5, 0, 1, 2 }; CollectionAssert.AreEquivalent(equivalent, list); }
public void CreateListTest() { const int maxLength = 100; for (int i = 0; i < maxLength; i++) { int[] collection = Enumerable.Range(0, i).ToArray(); CheckListEquality(collection, PersistentList <int> .Of(collection)); CheckListEquality(collection, PersistentList <int> .OfReadonly(collection)); } }
public void CreateOnISeqReturnsMap() { object[] items = new object[] { 1, "a", 2, "b" }; ArrayList a = new ArrayList(items); ISeq s = PersistentList.create(a).seq(); IPersistentMap m = PersistentTreeMap.create(s); Expect(m.count(), EqualTo(2)); Expect(m.valAt(1), EqualTo("a")); Expect(m.valAt(2), EqualTo("b")); Expect(m.containsKey(3), False); }
public void CreateOnISeqReturnsMap() { object[] items = new object[] { 1, "a", 2, "b" }; ArrayList a = new ArrayList(items); ISeq s = PersistentList.create(a).seq(); IPersistentMap m = PersistentHashMap.create(s); Expect(m.count()).To.Equal(2); Expect(m.valAt(1)).To.Equal("a"); Expect(m.valAt(2)).To.Equal("b"); Expect(m.containsKey(3)).To.Be.False(); }
public void CreateOnISeqReturnsSet() { object[] items = new object[] { 1, "a" }; ArrayList a = new ArrayList(items); ISeq s = PersistentList.create(a).seq(); IPersistentSet m = PersistentHashSet.create(s); Expect(m.count(), EqualTo(2)); Expect(m.contains(1)); Expect(m.contains("a")); Expect(m.contains(3), False); }
protected override void OnLoad(ConfigNode node) { base.OnLoad(node); ProtoWorkshops.Clear(); var wnode = node.GetNode("Workshops"); if (wnode != null) { var workshops = new PersistentList <ProtoWorkshop>(); workshops.Load(wnode); workshops.ForEach(add_protoworkshop); } }
protected override void AddToCollection(ICollection collection, Person person) { PersistentList concrete = collection as PersistentList; if (concrete != null) { concrete.Add(person); } else { ((ArrayList)collection).Add(person); } }
public void Setup() { _mocks = new MockRepository(); IPersistentMap meta = _mocks.StrictMock <IPersistentMap>(); _mocks.ReplayAll(); PersistentList p1 = (PersistentList)PersistentList.create(new object[] { "abc", "def" }); _objWithNullMeta = (IObj)p1; _obj = _objWithNullMeta.withMeta(meta); _expectedType = typeof(PersistentList); }
public void TestList() { var a = new PersistentList<string>(); a.Add("one"); a.Store(); a.Add("two"); a.Undo(); Assert.True(a.Count == 1); Assert.True(a[0] == "one"); a.Redo(); Assert.True(a.Count == 2); Assert.True(a[0] == "one"); Assert.True(a[1] == "two"); }
public void TestIgnoreRepetitiveActions() { var list = new PersistentList<string>(); var undoRedo = new UndoRedo<PersistentList<string>>(list); undoRedo.NewAction("add"); list.Add("1"); undoRedo.NewAction("add"); list.Add("2"); undoRedo.Undo(); Assert.True(list.Count == 1); undoRedo.IgnoreRepetitiveActions = true; undoRedo.NewAction("add"); list.Add("2"); undoRedo.Undo(); Assert.True(list.Count == 0); }
public void TestIteratingOverListWithBrokenItems() { var list = BuildTestList(); var storage = SimpleStorage.EditGroup(editGroup); storage.Put("2", "break data with id 2"); list = new PersistentList<IdentifiableForTesting>(editGroup); int count = 0; foreach (var a in list) Assert.AreEqual(a.Id, (++count + (count > 1 ? 1 : 0)).ToString()); Assert.AreEqual(2, count); Assert.AreEqual(2, list.Count); Assert.IsFalse(storage.HasKey("2"), "the broken object should atomaticly be removed"); Assert.AreEqual(2, storage.Get<List<string>>("ids").Count, "the internal object-index should automaticly remove the broken id"); }
public void TestPersistentStructureList() { var a = new PersistentList<Persistent<string>>(); a.Add(new Persistent<string>("one")); a.Store(); a[0].Value = "two"; a.Undo(); Assert.True(a[0].Value == "one"); a.Redo(); Assert.True(a[0].Value == "two"); }
public void TestList3() { var a = new Persistent<string>("one"); var b = new Persistent<string>("two"); var persistent = new PersistentList<Persistent<string>>(); persistent.Add(a); persistent.Add(b); persistent.Store(); a.Value = "1"; b.Value = "2"; persistent.Store(); persistent[0] = b; persistent[1] = a; persistent.Store(); persistent.Undo(); Assert.True(persistent[0] == b); Assert.True(persistent[1] == a); persistent.Undo(); Assert.True(persistent[0] == a); Assert.True(persistent[1] == b); }
private bool HasCycle(PersistentList<IFeatureToggle> visitedToggles = null) { visitedToggles = visitedToggles == null ? new PersistentList<IFeatureToggle>(this, Enumerable.Empty<IFeatureToggle>()) : new PersistentList<IFeatureToggle>(this, visitedToggles); foreach (var toggle in dependencies) { // Verify that this node has not been visited before if (visitedToggles.Contains(toggle)) { return true; } var dependencyToggle = toggle as DependencyToggle; if ((dependencyToggle != null) && dependencyToggle.HasCycle(visitedToggles)) { return true; } } return false; }
PersistentList<IdentifiableForTesting> BuildTestList() { var list = new PersistentList<IdentifiableForTesting>(editGroup); list.Add(new IdentifiableForTesting("1")); list.Add(new IdentifiableForTesting("2")); list.Add(new IdentifiableForTesting("3")); return list; }