Ejemplo n.º 1
0
 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));
 }
Ejemplo n.º 2
0
 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);
        }
Ejemplo n.º 4
0
        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()));
 }
Ejemplo n.º 6
0
        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();
        }
Ejemplo n.º 8
0
        public void EmptyHasNoElements()
        {
            PersistentList        p = new PersistentList("abc");
            IPersistentCollection c = p.empty();

            Expect(c.count(), EqualTo(0));
        }
Ejemplo n.º 9
0
        public void PeekYieldsFirstElementAndListUnchanged()
        {
            PersistentList p = (PersistentList)PersistentList.create(new object[] { "abc", 1, "def" });

            Expect(p.peek(), EqualTo("abc"));
            Expect(p.count(), EqualTo(3));
        }
Ejemplo n.º 10
0
        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"));
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        public void OneArgCtorConstructsListOfOneElement()
        {
            PersistentList p = new PersistentList("abc");

            Expect(p.first(), EqualTo("abc"));
            Expect(p.next(), Null);
            Expect(p.count(), EqualTo(1));
        }
Ejemplo n.º 14
0
        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));
        }
Ejemplo n.º 15
0
 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");
 }
Ejemplo n.º 16
0
 static void Print(PersistentList<int> pl)
 {
     Node<int> _node = pl.FirstNode;     // puntero nodo 0
     while (_node != null)
     {
         Console.WriteLine(_node);
         _node = _node.Next;
     }
 }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 22
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));
        }
Ejemplo n.º 23
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"));
        }
Ejemplo n.º 26
0
        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));
        }
Ejemplo n.º 27
0
        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));
        }
Ejemplo n.º 28
0
 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());
 }
Ejemplo n.º 29
0
        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);
        }
Ejemplo n.º 30
0
        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);
        }
Ejemplo n.º 31
0
        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);
        }
Ejemplo n.º 32
0
        /// <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);
        }
Ejemplo n.º 33
0
        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);
        }
Ejemplo n.º 34
0
        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));
            }
        }
Ejemplo n.º 35
0
        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);
        }
Ejemplo n.º 36
0
        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();
        }
Ejemplo n.º 37
0
        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);
        }
Ejemplo n.º 38
0
        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);
            }
        }
Ejemplo n.º 40
0
        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);
        }
Ejemplo n.º 41
0
 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");
 }
Ejemplo n.º 42
0
 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");
        }
Ejemplo n.º 44
0
 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");
 }
Ejemplo n.º 45
0
 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);
 }
Ejemplo n.º 46
0
        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;
 }