Example #1
0
        public void CreateWithOneObject()
        {
            Cons cons = new Cons(1);

            Assert.AreEqual(1, cons.First());
            Assert.IsNull(cons.Next());
        }
Example #2
0
        public void CreateWithNullMetadata()
        {
            Cons cons = new Cons(1, new Cons(2));
            IObject iobj = cons.WithMetadata(null);

            Assert.IsNotNull(iobj);
            Assert.IsInstanceOfType(iobj, typeof(Cons));
            Assert.IsTrue(iobj == cons);
        }
Example #3
0
        public void CopyToSubarray()
        {
            Cons cons = new Cons(1, new Cons(2, new Cons(3)));
            object[] array = new object[4];

            cons.CopyTo(array, 1);

            Assert.AreEqual(1, array[1]);
            Assert.AreEqual(2, array[2]);
            Assert.AreEqual(3, array[3]);
        }
Example #4
0
        public void CreateWithOneObjectAndRest()
        {
            Cons cons = new Cons(1, new Cons(2));

            Assert.AreEqual(1, cons.First());

            ISequence rest = cons.Next();

            Assert.IsNotNull(rest);
            Assert.IsInstanceOfType(rest, typeof(Cons));

            Assert.AreEqual(2, rest.First());
            Assert.IsNull(rest.Next());
        }
Example #5
0
        public void CreateWithMetadata()
        {
            Cons cons = new Cons(1, new Cons(2));
            IObject iobj = cons.WithMetadata(FakePersistentMap.Instance);

            Assert.IsNotNull(iobj);
            Assert.IsInstanceOfType(iobj, typeof(Cons));
            Assert.IsTrue(iobj != cons);
            Assert.IsTrue(FakePersistentMap.Instance == iobj.Metadata);
            Assert.AreEqual(2, cons.Count);
            Assert.AreEqual(1, cons.First());
            Assert.AreEqual(2, cons.Next().First());
            Assert.IsNull(cons.Next().Next());
        }
Example #6
0
 public void GetFirstElementByIndex()
 {
     Cons cons = new Cons(1, new Cons(2));
     Assert.AreEqual(1, cons[0]);
 }
Example #7
0
        public void TwoConsWithSameElementsHaveSameHashCode()
        {
            Cons cons1 = new Cons(1, new Cons(2, new Cons(3)));
            Cons cons2 = new Cons(1, new Cons(2, new Cons(3)));

            Assert.AreEqual(cons1.GetHashCode(), cons2.GetHashCode());
        }
Example #8
0
        public void TwoConsWithSameElementsAreEqual()
        {
            Cons cons1 = new Cons(1, new Cons(2, new Cons(3)));
            Cons cons2 = new Cons(1, new Cons(2, new Cons(3)));

            Assert.IsTrue(cons1.Equals(cons2));
            Assert.IsTrue(cons2.Equals(cons1));
        }
Example #9
0
        public void TwoConsWithDifferentElementsAreNotEqual()
        {
            Cons cons1 = new Cons(1, new Cons(2, new Cons(3)));
            Cons cons2 = new Cons(3, new Cons(2, new Cons(1)));

            Assert.IsFalse(cons1.Equals(cons2));
            Assert.IsFalse(cons2.Equals(cons1));
        }
Example #10
0
 public void RaiseWhenTryingToSetElementByIndex()
 {
     Cons cons = new Cons(1, new Cons(2));
     cons[0] = 0;
 }
Example #11
0
 public void GetSecondElementByIndex()
 {
     Cons cons = new Cons(1, new Cons(2));
     Assert.AreEqual(2, cons[1]);
 }