Пример #1
0
        public static void ImmutableListAppendMonoidTest()
        {
            var m = Monoid.ImmutableListAppend <int>();

            var xs = new List <int> {
            };
            var ys = new List <int> {
                1, 2, 3
            };
            var zs = new List <int> {
                4, 1, 2
            };

            Assert.Empty(m.Neutral);
            Assert.Empty(Monoid.NeutralUnsafe <IList <int>, Monoid.ListAppendImmutableMonoid <int> >());
            Assert.Equal(new int[] { 1, 2, 3 }, m.Op(xs, ys));
            Assert.Equal(new int[] { 1, 2, 3 }, m.Op(ys, xs));
            Assert.Equal(new int[] { 1, 2, 3, 4, 1, 2 }, m.Op(ys, zs));

            Assert.Empty(xs);
            Assert.Equal(new int[] { 1, 2, 3 }, ys);
            Assert.Equal(new int[] { 4, 1, 2 }, zs);
        }
Пример #2
0
        public static void ImmutableListAppendMonoidTest_String()
        {
            var m = Monoid.ImmutableListAppend <string>();

            var xs = new List <string> {
            };
            var ys = new List <string> {
                "a", "b", "c"
            };
            var zs = new List <string> {
                "d", "a", "b"
            };

            Assert.Empty(m.Neutral);
            Assert.Empty(Monoid.NeutralUnsafe <IList <string>, Monoid.ListAppendImmutableMonoid <string> >());
            Assert.Equal(new string[] { "a", "b", "c", "d", "a", "b" }, Monoid.OpUnsafe <IList <string>, Monoid.ListAppendImmutableMonoid <string> >()(ys, zs));
            Assert.Equal(new string[] { "a", "b", "c" }, m.Op(xs, ys));
            Assert.Equal(new string[] { "a", "b", "c" }, m.Op(ys, xs));
            Assert.Equal(new string[] { "a", "b", "c", "d", "a", "b" }, m.Op(ys, zs));

            Assert.Empty(xs);
            Assert.Equal(new string[] { "a", "b", "c" }, ys);
            Assert.Equal(new string[] { "d", "a", "b" }, zs);
        }