Exemple #1
0
        public void TestCasts()
        {
            // C# can't go straight from the function to a ContinuousMap, because technically it's already a cast to
            // become a Func (or any delegate type), double implicit casts are not considered when looking for
            // conversion operators, and there's no way to specify "method set" as the source for an implicit cast.
            // Oh well. Still, if we explicitly cast to Func, our conversion works:
            ContinuousMap <int, int> c = (Func <int, int>)TimesTwo;

            Assert.NotNull(c);
            Assert.Equal(10, c.GetValueAt(5));
            Assert.IsAssignableFrom <FunctionBackedContinuousMap <int, int> >(c);
            Assert.Equal(4, ((FunctionBackedContinuousMap <int, int>)c).F(2));

            FunctionBackedContinuousMap <int, int> d = (Func <int, int>)TimesTwo;

            Assert.NotNull(d);
            Assert.Equal(10, d.GetValueAt(5));
            Assert.Equal(4, d.F(2));
            Assert.IsAssignableFrom <ContinuousMap <int, int> >(d);

            var e = (ContinuousMap <int, int>)TimesTwo;

            Assert.NotNull(e);
            Assert.Equal(10, e.GetValueAt(5));
            Assert.IsAssignableFrom <FunctionBackedContinuousMap <int, int> >(e);
            Assert.Equal(4, ((FunctionBackedContinuousMap <int, int>)e).F(2));
        }
Exemple #2
0
        public void TestBasicFunctionality()
        {
            var c = new FunctionBackedContinuousMap <int, int>(x => x + 1);

            Assert.NotNull(c);
            Assert.Equal(5, c.GetValueAt(4));
            Assert.Equal(3, c.F(2));
            Assert.IsAssignableFrom <ContinuousMap <int, int> >(c);
        }