Пример #1
0
        public static void Either3Creation()
        {
            var cache    = new EitherCache(20);
            var expected = new Either <int, List <bool>, FuncList <string> >(Either.One(14));
            var actual   = (Either <int, List <bool>, FuncList <string> >)cache.RetrieveOrCacheCreate(new List <Type> {
                typeof(int), typeof(List <bool>), typeof(FuncList <string>)
            }, 0, 14);

            Assert.Equal(expected, actual);

            var list = new List <bool> {
                false, false, true
            };

            expected = new Either <int, List <bool>, FuncList <string> >(Either.Two(list));
            actual   = (Either <int, List <bool>, FuncList <string> >)cache.RetrieveOrCacheCreate(new List <Type> {
                typeof(int), typeof(List <bool>), typeof(FuncList <string>)
            }, 1, list);

            Assert.Equal(expected, actual);

            expected = new Either <int, List <bool>, FuncList <string> >(Either.Three(new FuncList <string> {
                "a", "b", "c"
            }));
            actual = (Either <int, List <bool>, FuncList <string> >)cache.RetrieveOrCacheCreate(new List <Type> {
                typeof(int), typeof(List <bool>), typeof(FuncList <string>)
            }, 2, new FuncList <string> {
                "a", "b", "c"
            });

            Assert.Equal(expected, actual);
        }
Пример #2
0
        public static void ErrorTest()
        {
            var cache = new EitherCache(20);

            Assert.Throws <ArgumentException>(() => cache.RetrieveOrCacheCreate(null, 0, 5));
            Assert.Throws <ArgumentException>(() => cache.RetrieveOrCacheCreate(Enumerable.Repeat(typeof(int), 9).ToList(), 0, 5));
            Assert.Throws <IndexOutOfRangeException>(() => cache.RetrieveOrCacheCreate(Enumerable.Repeat(typeof(int), 5).ToList(), 5, 5));
            Assert.Throws <IndexOutOfRangeException>(() => cache.RetrieveOrCacheCreate(Enumerable.Repeat(typeof(int), 5).ToList(), -1, 5));
        }
Пример #3
0
        public static void Either7Creation()
        {
            var cache    = new EitherCache(20);
            var expected = new Either <int, List <bool>, FuncList <string>, float, bool, short, byte>(Either.One(14));
            var actual   = (Either <int, List <bool>, FuncList <string>, float, bool, short, byte>)cache.RetrieveOrCacheCreate(new List <Type> {
                typeof(int), typeof(List <bool>), typeof(FuncList <string>), typeof(float), typeof(bool), typeof(short), typeof(byte)
            }, 0, 14);

            Assert.Equal(expected, actual);
        }
Пример #4
0
        public static void IntEither1Creation()
        {
            var cache    = new EitherCache(20);
            var expected = new Identity <int>(14);
            var actual   = (Identity <int>)cache.RetrieveOrCacheCreate(new List <Type> {
                typeof(int)
            }, 0, 14);

            Assert.Equal(expected, actual);
        }
Пример #5
0
        public static void ListStringEither1Creation()
        {
            var cache = new EitherCache(20);
            var list  = new List <string> {
                "abc"
            };

            var expected = new Identity <List <string> >(list);
            var actual   = (Identity <List <string> >)cache.RetrieveOrCacheCreate(new List <Type> {
                typeof(List <string>)
            }, 0, list);

            Assert.Equal(expected, actual);
        }
Пример #6
0
        public static void IntEither2Creation()
        {
            var cache    = new EitherCache(20);
            var expected = new Either <int, string>(Either.One(14));
            var actual   = (Either <int, string>)cache.RetrieveOrCacheCreate(new List <Type> {
                typeof(int), typeof(string)
            }, 0, 14);

            Assert.Equal(expected, actual);

            expected = new Either <int, string>(Either.Two("abc"));
            actual   = (Either <int, string>)cache.RetrieveOrCacheCreate(new List <Type> {
                typeof(int), typeof(string)
            }, 1, "abc");

            Assert.Equal(expected, actual);
        }
Пример #7
0
        public static void Either8FuncCreation()
        {
            var cache             = new EitherCache(20);
            var expected          = new Either <int, List <bool>, FuncList <string>, float, bool, short, byte, Type>(Either.One(14));
            var actualConstructor = cache.RetrieveOrCacheCreate(new List <Type> {
                typeof(int), typeof(List <bool>), typeof(FuncList <string>), typeof(float), typeof(bool), typeof(short), typeof(byte), typeof(Type)
            });

            var actual = (Either <int, List <bool>, FuncList <string>, float, bool, short, byte, Type>)actualConstructor(0, 14);

            Assert.Equal(expected, actual);

            expected = new Either <int, List <bool>, FuncList <string>, float, bool, short, byte, Type>(Either.Eight(typeof(int)));
            actual   = (Either <int, List <bool>, FuncList <string>, float, bool, short, byte, Type>)actualConstructor(7, typeof(int));

            Assert.Equal(expected, actual);

            Assert.Throws <IndexOutOfRangeException>(() => actualConstructor(8, 4));
        }
Пример #8
0
        public static void ListStringEither2Creation()
        {
            var cache    = new EitherCache(20);
            var expected = new Either <int, FuncList <string> >(Either.One(14));
            var actual   = (Either <int, FuncList <string> >)cache.RetrieveOrCacheCreate(new List <Type> {
                typeof(int), typeof(FuncList <string>)
            }, 0, 14);

            Assert.Equal(expected, actual);

            expected = new Either <int, FuncList <string> >(Either.Two(new FuncList <string> {
                "abc"
            }));
            actual = (Either <int, FuncList <string> >)cache.RetrieveOrCacheCreate(new List <Type> {
                typeof(int), typeof(FuncList <string>)
            }, 1, new FuncList <string> {
                "abc"
            });

            Assert.Equal(expected, actual);
        }