Exemple #1
0
        /// <summary>
        ///Ein Test für "CalculateTargetValue"
        ///</summary>
        public void CalculateTargetValueTestHelper()
        {
            // test for absolute tween
            var tweener = new SimpleTweenerImpl <int>();
            var param0  = new PrivateObject(tweener);
            var target  = new SimpleTweener_Accessor <int>(param0);

            var obj = new TweeningTestObject();

            tweener.Create(obj, new PropertyOps("SomeValue", 200, false));
            tweener.Value = 100;
            int expected = 200;
            int actual   = target.CalculateTargetValue();

            Assert.AreEqual(expected, actual);

            // test for relative tween
            tweener = new SimpleTweenerImpl <int>();
            param0  = new PrivateObject(tweener);
            target  = new SimpleTweener_Accessor <int>(param0);

            obj = new TweeningTestObject();
            tweener.Create(obj, new PropertyOps("SomeValue", 200, true));
            tweener.Value = 100;
            expected      = 300;
            actual        = target.CalculateTargetValue();
            Assert.AreEqual(expected, actual);
        }
Exemple #2
0
        /// <summary>
        ///Ein Test für "Ease"
        ///</summary>
        public void EaseTestHelper2 <TValueType>()
        {
            var target  = new SimpleTweenerImpl <TValueType>();
            var obj     = new TweeningTestObject();
            var propOps = new PropertyOps("FloatValue", 100, false).EaseEx(EaseEx.InElastic, new object[] { 0.3F, 0.3F });

            target.Create(obj, propOps);

            var param0   = new PrivateObject(target);
            var accessor = new SimpleTweener_Accessor <TValueType>(param0);

            // assert that only the EaseFunc is set and not EaseEx
            Assert.IsNull(accessor.EaseFunc);
            Assert.IsNotNull(accessor.EaseExFunc);
            Assert.IsNotNull(accessor.EaseExParams);

            var startValue = 100F;
            var deltaValue = 200F;

            Console.WriteLine("ret " + accessor.Ease(0F, startValue, deltaValue).GetType());
            var actual = accessor.Ease(0F, startValue, deltaValue);

            Assert.AreEqual(100, actual);

            actual = accessor.Ease(1F, startValue, deltaValue);
            Assert.AreEqual(300, actual);
        }
Exemple #3
0
        /// <summary>
        ///Ein Test für "CreateAccessor"
        ///</summary>
        public void CreateAccessorTestHelper()
        {
            var           tweener = new GenericTweenerImpl <int>();
            PrivateObject param0  = new PrivateObject(tweener, new PrivateType(typeof(GenericTweener <int>)));
            var           target  = new GenericTweener_Accessor <int>(param0);
            var           obj     = new TweeningTestObject();

            // test creation of field accessor
            var propOps = new PropertyOps("IntValue", 0, false);

            target.CreateAccessor(obj, propOps);
            Console.WriteLine("t " + tweener.GetAccessor());
            Assert.IsInstanceOfType(
                tweener.GetAccessor(),
                typeof(FieldAccessor <int>)
                );

            // test creation of field accessor
            propOps = new PropertyOps("IntProperty", 0, false);
            target.CreateAccessor(obj, propOps);
            Console.WriteLine("t " + tweener.GetAccessor());
            Assert.IsInstanceOfType(
                tweener.GetAccessor(),
                typeof(PropertyAccessor <int>)
                );
        }
        public void TweenedObjectConstructorTest()
        {
            var obj = new TweeningTestObject();
            var registeredPropertyTweens = new Dictionary <string, Type>();
            var target = new TweenedObject(obj, registeredPropertyTweens);

            Assert.AreSame(obj, target.Obj);
            Assert.AreSame(registeredPropertyTweens, target.RegisteredPropertyTweens);
        }
        public void CreateTweenerWithAccessorTest()
        {
            var obj = new TweeningTestObject();
            var registeredPropertyTweens = new Dictionary <string, Type>();

            // register tweener for ints
            registeredPropertyTweens.Add(typeof(SByte).FullName, typeof(SignedByteTweener));
            registeredPropertyTweens.Add(typeof(Int16).FullName, typeof(SignedInt16Tweener));
            registeredPropertyTweens.Add(typeof(Int32).FullName, typeof(SignedInt32Tweener));
            registeredPropertyTweens.Add(typeof(Int64).FullName, typeof(SignedInt64Tweener));
            // register tweener for unsigned ints
            registeredPropertyTweens.Add(typeof(Byte).FullName, typeof(UnsignedByteTweener));
            registeredPropertyTweens.Add(typeof(UInt16).FullName, typeof(UnsignedInt16Tweener));
            registeredPropertyTweens.Add(typeof(UInt32).FullName, typeof(UnsignedInt32Tweener));
            registeredPropertyTweens.Add(typeof(UInt64).FullName, typeof(UnsignedInt64Tweener));
            // register tweener for floats
            registeredPropertyTweens.Add(typeof(Single).FullName, typeof(FloatTweener));
            // register tweener for doubles
            registeredPropertyTweens.Add(typeof(Double).FullName, typeof(DoubleTweener));


            var param0 = new PrivateObject(new TweenedObject(new TweeningTestObject(), registeredPropertyTweens));
            var target = new TweenedObject_Accessor(param0);

            ITweenSharkTweener tweener = target.CreateTweener(new PropertyOps("SbyteValue", 100, false));

            Assert.IsInstanceOfType(tweener, typeof(SignedByteTweener));

            tweener = target.CreateTweener(new PropertyOps("ShortValue", 100, false));
            Assert.IsInstanceOfType(tweener, typeof(SignedInt16Tweener));

            tweener = target.CreateTweener(new PropertyOps("IntValue", 100, false));
            Assert.IsInstanceOfType(tweener, typeof(SignedInt32Tweener));

            tweener = target.CreateTweener(new PropertyOps("LongValue", 100, false));
            Assert.IsInstanceOfType(tweener, typeof(SignedInt64Tweener));

            tweener = target.CreateTweener(new PropertyOps("ByteValue", 100, false));
            Assert.IsInstanceOfType(tweener, typeof(UnsignedByteTweener));

            tweener = target.CreateTweener(new PropertyOps("UshortValue", 100, false));
            Assert.IsInstanceOfType(tweener, typeof(UnsignedInt16Tweener));

            tweener = target.CreateTweener(new PropertyOps("UintValue", 100, false));
            Assert.IsInstanceOfType(tweener, typeof(UnsignedInt32Tweener));

            tweener = target.CreateTweener(new PropertyOps("UlongValue", 100, false));
            Assert.IsInstanceOfType(tweener, typeof(UnsignedInt64Tweener));

            tweener = target.CreateTweener(new PropertyOps("DoubleValue", 100, false));
            Assert.IsInstanceOfType(tweener, typeof(DoubleTweener));

            tweener = target.CreateTweener(new PropertyOps("FloatValue", 100, false));
            Assert.IsInstanceOfType(tweener, typeof(FloatTweener));
        }
        /// <summary>
        ///Ein Test für "GetValue"
        ///</summary>
        public void GetValueTestHelper <TValueType>()
        {
            var obj          = new TweeningTestObject();
            var propertyInfo = obj.GetType().GetProperty("GenericProperty");
            var target       = new PropertyAccessor <TValueType>(obj, propertyInfo);

            var expected = default(TValueType);
            var actual   = target.GetValue();

            Assert.AreEqual(expected, actual);
        }
Exemple #7
0
        /// <summary>
        ///Ein Test für "GetValue"
        ///</summary>
        public void GetValueTestHelper <TValueType>()
        {
            var obj       = new TweeningTestObject();
            var fieldInfo = obj.GetType().GetField("GenericValue");
            var target    = new FieldAccessor <TValueType>(obj, fieldInfo);

            var expected = default(TValueType);
            var actual   = target.GetValue();

            Assert.AreEqual(expected, actual);
        }
        public void AddTweenSharkTest()
        {
            Assert.Inconclusive("needs to be rewritten to prevent runtime errors");

            var obj = new TweeningTestObject();
            var registeredPropertyTweens = new Dictionary <string, Type>();

            registeredPropertyTweens.Add(typeof(SByte).FullName, typeof(SignedByteTweener));

            var target   = new TweenedObject(obj, registeredPropertyTweens);
            var param0   = new PrivateObject(target);
            var accessor = new TweenedObject_Accessor(param0);

            var tweenShark = new TweenShark(obj, 1, new TweenOps().PropTo("DoubleValue", 100).PropTo("FloatValue", 101));

            target.AddTweenShark(tweenShark);


            // check for count of tweens and tweened properties
            Assert.AreEqual(1, accessor._tweens.Count);
            Assert.AreEqual(2, accessor._propertyTweens.Count);
            // check for target values
            Assert.AreEqual(100, ((DoubleTweener)(accessor._propertyTweens["DoubleValue"])).GetTargetValue());
            Assert.AreEqual(101, ((FloatTweener)(accessor._propertyTweens["FloatValue"])).GetTargetValue());

            // when adding a tween on another object the number of tweens must not change, because we do not add the tween
            tweenShark = new TweenShark(new TweeningTestObject(), 1, new TweenOps());
            target.AddTweenShark(tweenShark);
            // check for count of tweens and tweened properties
            Assert.AreEqual(1, accessor._tweens.Count);
            Assert.AreEqual(2, accessor._propertyTweens.Count);

            // when adding a tween on the correct object but with another property the numbers must change
            tweenShark = new TweenShark(obj, 1, new TweenOps().PropTo("IntValue", 102));
            target.AddTweenShark(tweenShark);
            // check for count of tweens and tweened properties
            Assert.AreEqual(2, accessor._tweens.Count);
            Assert.AreEqual(3, accessor._propertyTweens.Count);
            // check for target values
            Assert.AreEqual(100, ((DoubleTweener)(accessor._propertyTweens["DoubleValue"])).GetTargetValue());
            Assert.AreEqual(101, ((FloatTweener)(accessor._propertyTweens["FloatValue"])).GetTargetValue());
            Assert.AreEqual(102, ((SignedInt32Tweener)(accessor._propertyTweens["IntValue"])).GetTargetValue());

            // but when we now add another tween that overrides tweened properties, only the number of tweens may change
            tweenShark = new TweenShark(obj, 1, new TweenOps().PropTo("DoubleValue", 200).PropTo("FloatValue", 201).PropTo("IntValue", 202));
            target.AddTweenShark(tweenShark);
            // check for count of tweens and tweened properties
            Assert.AreEqual(3, accessor._tweens.Count);
            Assert.AreEqual(3, accessor._propertyTweens.Count);
            // check for target values
            Assert.AreEqual(200, ((DoubleTweener)(accessor._propertyTweens["DoubleValue"])).GetTargetValue());
            Assert.AreEqual(201, ((FloatTweener)(accessor._propertyTweens["FloatValue"])).GetTargetValue());
            Assert.AreEqual(202, ((SignedInt32Tweener)(accessor._propertyTweens["IntValue"])).GetTargetValue());
        }
Exemple #9
0
        public void TweenSharkConstructorTest()
        {
            var         obj      = new TweeningTestObject();
            const float duration = 1F;
            var         tweenOps = new TweenOps();

            var tweenShark = new TweenShark(obj, duration, tweenOps);

            Assert.AreSame(obj, tweenShark.Obj);
            Assert.AreEqual(duration, tweenShark.Duration);
            Assert.AreSame(tweenOps, tweenShark.TweenOps);
        }
Exemple #10
0
        /// <summary>
        ///Ein Test für "GetSubPropertyName"
        ///</summary>
        public void GetSubPropertyNameTestHelper <TValueType>()
        {
            var target  = new SimpleTweenerImpl <TValueType>();
            var obj     = new TweeningTestObject();
            var propOps = new PropertyOps("FloatValue", 100, false);

            target.Create(obj, propOps);
            string       actual   = target.GetSubPropertyName();
            const string expected = "";

            Assert.AreEqual(expected, actual);
        }
Exemple #11
0
        /// <summary>
        ///Ein Test für "GetTweenedObject"
        ///</summary>
        public void GetTweenedObjectTestHelper <TValueType>()
        {
            var           tweener = new SimpleTweenerImpl <TValueType>();
            PrivateObject param0  = new PrivateObject(tweener);
            SimpleTweener_Accessor <TValueType> target = new SimpleTweener_Accessor <TValueType>(param0);
            var expected = new TweeningTestObject();

            tweener.Create(expected, new PropertyOps("IntValue", 100, false));
            TweeningTestObject actual;

            actual = target.GetTweenedObject <TweeningTestObject>();
            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        ///Ein Test für "SetValue"
        ///</summary>
        public void SetValueTestHelper <TValueType>()
        {
            var obj          = new TweeningTestObject();
            var propertyInfo = obj.GetType().GetProperty("GenericProperty");
            var target       = new PropertyAccessor <TValueType>(obj, propertyInfo);

            const int containedValue = 100;
            var       value          = (TValueType)Convert.ChangeType(new GenericParameterHelper(containedValue), typeof(TValueType));

            target.SetValue(value);
            var expected = (TValueType)Convert.ChangeType(obj.GenericProperty, typeof(TValueType));

            Assert.AreEqual(expected, value);
            Assert.AreEqual(obj.GenericProperty.Data, containedValue);
        }
Exemple #13
0
        /// <summary>
        ///Ein Test für "Setup"
        ///</summary>
        public void SetupTestHelperAbsoluteTweening()
        {
            var obj = new TweeningTestObject();
            SimpleTweenerImpl <int> target = CreateSimpleTweener <int>();

            target.Value = 100;
            // Create Calls Setup() and Init()
            target.Create(obj, new PropertyOps("SomeName", 200, false));
            // after setup start and target value must be set on the tweener

            PrivateObject param0 = new PrivateObject(target);
            SimpleTweener_Accessor <int> accessor = new SimpleTweener_Accessor <int>(param0);

            Assert.AreEqual(100, accessor.StartValue);
            Assert.AreEqual(200, accessor.TargetValue);
        }
        public void CalculateAndSetValueTest()
        {
            FloatTweener       target;
            TweeningTestObject obj;
            float deltaTime;

            // test absolute tweening
            target = new FloatTweener();

            obj = new TweeningTestObject {
                FloatValue = 10f
            };
            target.Create(obj, new PropertyOps("FloatValue", 10f, false));

            deltaTime = 0f;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(obj.FloatValue, 10f);

            deltaTime = 0.5f;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(obj.FloatValue, 10f);

            deltaTime = 1f;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(obj.FloatValue, 10f);

            // test relative tweening
            target = new FloatTweener();

            obj = new TweeningTestObject {
                FloatValue = 10f
            };
            target.Create(obj, new PropertyOps("FloatValue", 10f, true));

            deltaTime = 0f;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(obj.FloatValue, 10f);

            deltaTime = 0.5f;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(obj.FloatValue, 15f);

            deltaTime = 1f;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(obj.FloatValue, 20f);
        }
Exemple #15
0
        public void CalculateAndSetValueTest()
        {
            DoubleTweener      target;
            TweeningTestObject obj;
            float deltaTime;

            // test absolute tweening
            target = new DoubleTweener();

            obj = new TweeningTestObject {
                DoubleValue = 10F
            };
            target.Create(obj, new PropertyOps("DoubleValue", 10F, false));

            deltaTime = 0F;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(10F, obj.DoubleValue);

            deltaTime = 0.5F;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(10F, obj.DoubleValue);

            deltaTime = 1F;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(10F, obj.DoubleValue);

            // test relative tweening
            target = new DoubleTweener();

            obj = new TweeningTestObject {
                DoubleValue = 10F
            };
            target.Create(obj, new PropertyOps("DoubleValue", 10F, true));

            deltaTime = 0F;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(10F, obj.DoubleValue);

            deltaTime = 0.5F;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(15F, obj.DoubleValue);

            deltaTime = 1F;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(20F, obj.DoubleValue);
        }
        public void CalculateAndSetValueTest()
        {
            UnsignedInt64Tweener target;
            TweeningTestObject   obj;
            float deltaTime;

            // test absolute tweening
            target = new UnsignedInt64Tweener();

            obj = new TweeningTestObject {
                UlongValue = 10
            };
            target.Create(obj, new PropertyOps("UlongValue", 10f, false));

            deltaTime = 0f;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(10UL, obj.UlongValue);

            deltaTime = 0.5f;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(10UL, obj.UlongValue);

            deltaTime = 1f;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(10UL, obj.UlongValue);

            // test relative tweening
            target = new UnsignedInt64Tweener();

            obj = new TweeningTestObject {
                UlongValue = 10
            };
            target.Create(obj, new PropertyOps("UlongValue", 10, true));

            deltaTime = 0f;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(10UL, obj.UlongValue);

            deltaTime = 0.5f;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(15UL, obj.UlongValue);

            deltaTime = 1f;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(20UL, obj.UlongValue);
        }
Exemple #17
0
        public void CalculateAndSetValueTest()
        {
            SignedByteTweener  target;
            TweeningTestObject obj;
            float deltaTime;

            // test absolute tweening
            target = new SignedByteTweener();

            obj = new TweeningTestObject {
                SbyteValue = 10
            };
            target.Create(obj, new PropertyOps("SbyteValue", 10f, false));

            deltaTime = 0f;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(obj.SbyteValue, 10);

            deltaTime = 0.5f;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(obj.SbyteValue, 10);

            deltaTime = 1f;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(obj.SbyteValue, 10);

            // test relative tweening
            target = new SignedByteTweener();

            obj = new TweeningTestObject {
                SbyteValue = 10
            };
            target.Create(obj, new PropertyOps("SbyteValue", 10, true));

            deltaTime = 0f;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(obj.SbyteValue, 10);

            deltaTime = 0.5f;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(obj.SbyteValue, 15);

            deltaTime = 1f;
            target.CalculateAndSetValue(deltaTime);
            Assert.AreEqual(obj.SbyteValue, 20);
        }
        public void CreateTweenerTest()
        {
            var obj = new TweeningTestObject();
            var registeredPropertyTweens = new Dictionary <string, Type>();

            registeredPropertyTweens.Add(typeof(SByte).FullName, typeof(SignedByteTweener));

            var param0 = new PrivateObject(new TweenedObject(new TweeningTestObject(), registeredPropertyTweens));
            var target = new TweenedObject_Accessor(param0);

            // when we give a tweener we must get one returned
            ITweenSharkTweener tweener = target.CreateTweener(new PropertyOps("SbyteValue", 100, new GenericTweenerImpl <SByte>(), false));

            Assert.IsInstanceOfType(tweener, typeof(GenericTweenerImpl <SByte>));

            // when we dont give a tweener CreateTweener will try to create it
            tweener = target.CreateTweener(new PropertyOps("SbyteValue", 100, false));
            Assert.IsInstanceOfType(tweener, typeof(SignedByteTweener));
        }
Exemple #19
0
        /// <summary>
        ///Ein Test für "Create"
        ///</summary>
        public void CreateTestHelper <TValueType>()
        {
            var          target               = CreateSimpleTweener <TValueType>();
            var          obj                  = new TweeningTestObject();
            const string propertyName         = "GenericValue";
            const int    targetValueContained = 100;
            var          targetValue          = new GenericParameterHelper(targetValueContained);
            const bool   isRelative           = true;
            var          propOps              = new PropertyOps(propertyName, targetValue, isRelative);

            target.Create(obj, propOps);

            var param0   = new PrivateObject(target);
            var accessor = new SimpleTweener_Accessor <TValueType>(param0);

            Assert.AreEqual(propertyName, accessor.PropOps.PropertyName);
            Assert.AreEqual(targetValue, accessor.PropOps.TargetValue);
            Assert.AreEqual(targetValueContained, ((GenericParameterHelper)accessor.PropOps.TargetValue).Data);
            Assert.AreEqual(isRelative, accessor.PropOps.IsRelative);
        }
        private TweenSharkCore SetupCoreWithTweens()
        {
            var core = new TweenSharkCore(new TweenSharkTickImpl());

            core.RegisterPropertyTweener(typeof(DoubleTweener), typeof(Double));
            core.RegisterPropertyTweener(typeof(FloatTweener), typeof(Single));

            // short tweens (one second)
            var duration = 1;
            var to       = new TweeningTestObject {
                DoubleValue = 100, FloatValue = 100
            };
            var tween = new TweenShark(to, duration, new TweenOps().PropTo("DoubleValue", 200));

            core.To(tween);
            tween = new TweenShark(to, duration, new TweenOps().PropTo("FloatValue", 200));
            core.To(tween);

            // medium duration tweens (3 seconds)
            duration = 3;
            to       = new TweeningTestObject {
                DoubleValue = 100
            };
            tween = new TweenShark(to, duration, new TweenOps().PropTo("DoubleValue", 200));
            core.To(tween);
            tween = new TweenShark(to, duration, new TweenOps().PropTo("FloatValue", 200));
            core.To(tween);

            // medium duration tweens (5 seconds)
            duration = 5;
            to       = new TweeningTestObject {
                DoubleValue = 100
            };
            tween = new TweenShark(to, duration, new TweenOps().PropTo("DoubleValue", 200));
            core.To(tween);
            tween = new TweenShark(to, duration, new TweenOps().PropTo("FloatValue", 200));
            core.To(tween);

            return(core);
        }
Exemple #21
0
        //
        //Sie können beim Verfassen Ihrer Tests die folgenden zusätzlichen Attribute verwenden:
        //
        //Mit ClassInitialize führen Sie Code aus, bevor Sie den ersten Test in der Klasse ausführen.
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Mit ClassCleanup führen Sie Code aus, nachdem alle Tests in einer Klasse ausgeführt wurden.
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Mit TestInitialize können Sie vor jedem einzelnen Test Code ausführen.
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Mit TestCleanup können Sie nach jedem einzelnen Test Code ausführen.
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///Ein Test für "Create"
        ///</summary>
        public void CreateTestHelper <TValueType>()
        {
            var          target               = CreateGenericTweener <TValueType>();
            var          obj                  = new TweeningTestObject();
            const string propertyName         = "GenericValue";
            const int    targetValueContained = 100;
            var          targetValue          = new GenericParameterHelper(targetValueContained);
            const bool   isRelative           = true;
            var          propOps              = new PropertyOps(propertyName, targetValue, isRelative);

            target.Create(obj, propOps);

            PrivateObject param0 = new PrivateObject(target);
            GenericTweener_Accessor <TValueType> accessor = new GenericTweener_Accessor <TValueType>(param0); // TODO: Passenden Wert initialisieren


//            Assert.AreEqual(propertyName, accessor.PropertyName);
//            Assert.AreEqual(targetValue, accessor.TargetValue);
//            Assert.AreEqual(targetValueContained, ((GenericParameterHelper) accessor.TargetValue).Data);
//            Assert.AreEqual(isRelative, accessor.IsRelative);
//            Assert.AreEqual(createAccessor, accessor.CreateAccessor);
        }
Exemple #22
0
        /// <summary>
        ///Ein Test für "GetValue"
        ///</summary>
        public void GetValueTestHelper()
        {
            var           tweener = new GenericTweenerImpl <int>();
            PrivateObject param0  = new PrivateObject(tweener, new PrivateType(typeof(GenericTweener <int>)));
            var           target  = new GenericTweener_Accessor <int>(param0);
            var           obj     = new TweeningTestObject()
            {
                IntValue = 100, IntProperty = 200
            };

            var propOps = new PropertyOps("IntValue", 0, false);

            target.CreateAccessor(obj, propOps);
            int actual = target.GetValue();

            Assert.AreEqual(100, actual);

            propOps = new PropertyOps("IntProperty", 0, false);
            target.CreateAccessor(obj, propOps);
            actual = target.GetValue();
            Assert.AreEqual(200, actual);
        }
        /// <summary>
        /// We are testing three tweens, that endure 1, 3 and 5 seconds. Ever Tween has onStart, onComplete, onUpdate callbacks set.
        /// To ensure that ticks is working the way it should we count how oftern the callbacks are called for each Tweens.
        /// In the end we check if the the values where tweened correctly.
        /// </summary>
        private void TestSimpleTickScenario()
        {
            var obj = new TweeningTestObject();
            var registeredPropertyTweens = new Dictionary <string, Type>();

            // register tweener for ints
            registeredPropertyTweens.Add(typeof(SByte).FullName, typeof(SignedByteTweener));
            registeredPropertyTweens.Add(typeof(Int16).FullName, typeof(SignedInt16Tweener));
            registeredPropertyTweens.Add(typeof(Int32).FullName, typeof(SignedInt32Tweener));
            registeredPropertyTweens.Add(typeof(Int64).FullName, typeof(SignedInt64Tweener));
            // register tweener for unsigned ints
            registeredPropertyTweens.Add(typeof(Byte).FullName, typeof(UnsignedByteTweener));
            registeredPropertyTweens.Add(typeof(UInt16).FullName, typeof(UnsignedInt16Tweener));
            registeredPropertyTweens.Add(typeof(UInt32).FullName, typeof(UnsignedInt32Tweener));
            registeredPropertyTweens.Add(typeof(UInt64).FullName, typeof(UnsignedInt64Tweener));
            // register tweener for floats
            registeredPropertyTweens.Add(typeof(Single).FullName, typeof(FloatTweener));
            // register tweener for doubles
            registeredPropertyTweens.Add(typeof(Double).FullName, typeof(DoubleTweener));

            var target = new TweenedObject(obj, registeredPropertyTweens); // TODO: Passenden Wert initialisieren

            var onStartTweens          = new Dictionary <TweenShark, int>();
            TweenSharkCallback onStart = tween => onStartTweens[tween]++;

            var onUpdateTweens          = new Dictionary <TweenShark, int>();
            TweenSharkCallback onUpdate = tween => onUpdateTweens[tween]++;

            var onCompleteTweens          = new Dictionary <TweenShark, int>();
            TweenSharkCallback onComplete = tween => onCompleteTweens[tween]++;

            // first tween takes ONE second
            var tween1 = new TweenShark(obj, 1, new TweenOps()
                                        .PropTo("DoubleValue", 100).PropTo("FloatValue", 200)
                                        .OnStart(onStart).OnUpdate(onUpdate).OnComplete(onComplete));

            onStartTweens[tween1]    = 0;
            onUpdateTweens[tween1]   = 0;
            onCompleteTweens[tween1] = 0;
            target.AddTweenShark(tween1);

            // second tween takes THREE seconds
            var tween2 = new TweenShark(obj, 3, new TweenOps()
                                        .PropTo("IntValue", 300).PropTo("UintValue", 400)
                                        .OnStart(onStart).OnUpdate(onUpdate).OnComplete(onComplete));

            onStartTweens[tween2]    = 0;
            onUpdateTweens[tween2]   = 0;
            onCompleteTweens[tween2] = 0;
            target.AddTweenShark(tween2);

            // third tween takes FIVE seconds
            var tween3 = new TweenShark(obj, 5, new TweenOps()
                                        .PropTo("LongValue", 500).PropTo("UlongValue", 600)
                                        .OnStart(onStart).OnUpdate(onUpdate).OnComplete(onComplete));

            onStartTweens[tween3]    = 0;
            onUpdateTweens[tween3]   = 0;
            onCompleteTweens[tween3] = 0;
            target.AddTweenShark(tween3);

            //////////////////////////////////////////////////////////////////////////////////////////
            // do one tick now
            long currentTicks = DateTime.Now.Ticks;
            bool actual       = target.Tick(currentTicks);

            Assert.AreEqual(true, actual);

            // oStart must be called 3 times now, each one time
            Assert.AreEqual(3, onStartTweens.Values.Sum());
            Assert.AreEqual(1, onStartTweens[tween1]);
            Assert.AreEqual(1, onStartTweens[tween2]);
            Assert.AreEqual(1, onStartTweens[tween3]);
            // onUpdate must also be called that often
            Assert.AreEqual(3, onUpdateTweens.Values.Sum());
            Assert.AreEqual(1, onUpdateTweens[tween1]);
            Assert.AreEqual(1, onUpdateTweens[tween2]);
            Assert.AreEqual(1, onUpdateTweens[tween3]);
            // onComplete must not have been called yet
            Assert.AreEqual(0, onCompleteTweens.Values.Sum());
            Assert.AreEqual(0, onCompleteTweens[tween1]);
            Assert.AreEqual(0, onCompleteTweens[tween2]);
            Assert.AreEqual(0, onCompleteTweens[tween3]);

            //////////////////////////////////////////////////////////////////////////////////////////
            System.Threading.Thread.Sleep(200);
            //////////////////////////////////////////////////////////////////////////////////////////

            //////////////////////////////////////////////////////////////////////////////////////////
            // do one tick now
            currentTicks = DateTime.Now.Ticks;
            actual       = target.Tick(currentTicks);
            Assert.AreEqual(true, actual);

            // oStart must not be changed
            Assert.AreEqual(3, onStartTweens.Values.Sum());
            Assert.AreEqual(1, onStartTweens[tween1]);
            Assert.AreEqual(1, onStartTweens[tween2]);
            Assert.AreEqual(1, onStartTweens[tween3]);
            // onUpdate must be called again for every tween
            Assert.AreEqual(3 + 3, onUpdateTweens.Values.Sum());
            Assert.AreEqual(1 + 1, onUpdateTweens[tween1]);
            Assert.AreEqual(1 + 1, onUpdateTweens[tween2]);
            Assert.AreEqual(1 + 1, onUpdateTweens[tween3]);
            // onComplete must not have been called yet
            Assert.AreEqual(0, onCompleteTweens.Values.Sum());
            Assert.AreEqual(0, onCompleteTweens[tween1]);
            Assert.AreEqual(0, onCompleteTweens[tween2]);
            Assert.AreEqual(0, onCompleteTweens[tween3]);

            //////////////////////////////////////////////////////////////////////////////////////////
            System.Threading.Thread.Sleep(1000);
            //////////////////////////////////////////////////////////////////////////////////////////

            //////////////////////////////////////////////////////////////////////////////////////////
            // do one tick now
            currentTicks = DateTime.Now.Ticks;
            actual       = target.Tick(currentTicks);
            Assert.AreEqual(true, actual);

            // oStart must not be changed
            Assert.AreEqual(3, onStartTweens.Values.Sum());
            Assert.AreEqual(1, onStartTweens[tween1]);
            Assert.AreEqual(1, onStartTweens[tween2]);
            Assert.AreEqual(1, onStartTweens[tween3]);
            // onUpdate must be called again for every tween
            Assert.AreEqual(3 + 3 + 3, onUpdateTweens.Values.Sum());
            Assert.AreEqual(1 + 1 + 1, onUpdateTweens[tween1]);
            Assert.AreEqual(1 + 1 + 1, onUpdateTweens[tween2]);
            Assert.AreEqual(1 + 1 + 1, onUpdateTweens[tween3]);
            // onComplete be called for the first and second tween
            Assert.AreEqual(1, onCompleteTweens.Values.Sum());
            Assert.AreEqual(1, onCompleteTweens[tween1]);
            Assert.AreEqual(0, onCompleteTweens[tween2]);
            Assert.AreEqual(0, onCompleteTweens[tween3]);

            //////////////////////////////////////////////////////////////////////////////////////////
            System.Threading.Thread.Sleep(2000);
            //////////////////////////////////////////////////////////////////////////////////////////

            //////////////////////////////////////////////////////////////////////////////////////////
            // do one tick now
            currentTicks = DateTime.Now.Ticks;
            actual       = target.Tick(currentTicks);
            Assert.AreEqual(true, actual);

            // oStart must not be changed
            Assert.AreEqual(3, onStartTweens.Values.Sum());
            Assert.AreEqual(1, onStartTweens[tween1]);
            Assert.AreEqual(1, onStartTweens[tween2]);
            Assert.AreEqual(1, onStartTweens[tween3]);
            // onUpdate must be called again for every tween, but the first one
            Assert.AreEqual(3 + 3 + 3 + 2, onUpdateTweens.Values.Sum());
            Assert.AreEqual(1 + 1 + 1, onUpdateTweens[tween1]);
            Assert.AreEqual(1 + 1 + 1 + 1, onUpdateTweens[tween2]);
            Assert.AreEqual(1 + 1 + 1 + 1, onUpdateTweens[tween3]);
            // onComplete be called for all tweens
            Assert.AreEqual(2, onCompleteTweens.Values.Sum());
            Assert.AreEqual(1, onCompleteTweens[tween1]);
            Assert.AreEqual(1, onCompleteTweens[tween2]);
            Assert.AreEqual(0, onCompleteTweens[tween3]);

            //////////////////////////////////////////////////////////////////////////////////////////
            System.Threading.Thread.Sleep(2000);
            //////////////////////////////////////////////////////////////////////////////////////////

            //////////////////////////////////////////////////////////////////////////////////////////
            // do one tick now
            currentTicks = DateTime.Now.Ticks;
            actual       = target.Tick(currentTicks);
            // there is no pending tween left, so we expect false as return value of Tick()
            Assert.AreEqual(false, actual);

            // oStart must not be changed
            Assert.AreEqual(3, onStartTweens.Values.Sum());
            Assert.AreEqual(1, onStartTweens[tween1]);
            Assert.AreEqual(1, onStartTweens[tween2]);
            Assert.AreEqual(1, onStartTweens[tween3]);
            // onUpdate must be called again for every tween, but the first and second one
            Assert.AreEqual(3 + 3 + 3 + 2 + 1, onUpdateTweens.Values.Sum());
            Assert.AreEqual(1 + 1 + 1, onUpdateTweens[tween1]);
            Assert.AreEqual(1 + 1 + 1 + 1, onUpdateTweens[tween2]);
            Assert.AreEqual(1 + 1 + 1 + 1 + 1, onUpdateTweens[tween3]);
            // onComplete be called for all tweens
            Assert.AreEqual(3, onCompleteTweens.Values.Sum());
            Assert.AreEqual(1, onCompleteTweens[tween1]);
            Assert.AreEqual(1, onCompleteTweens[tween2]);
            Assert.AreEqual(1, onCompleteTweens[tween3]);

            //////////////////////////////////////////////////////////////////////////////////////////
            // test the results
            Assert.AreEqual(obj.DoubleValue, 100);
            Assert.AreEqual(obj.FloatValue, 200);
            Assert.AreEqual(obj.IntValue, 300);
            Assert.AreEqual(obj.UintValue, 400U);
            Assert.AreEqual(obj.LongValue, 500L);
            Assert.AreEqual(obj.UlongValue, 600UL);

            //////////////////////////////////////////////////////////////////////////////////////////
            System.Threading.Thread.Sleep(1000);
            //////////////////////////////////////////////////////////////////////////////////////////

            //////////////////////////////////////////////////////////////////////////////////////////
            // the last tick... nothing can change, since there is no tween left
            currentTicks = DateTime.Now.Ticks;
            actual       = target.Tick(currentTicks);
            // there is no pending tween left, so we expect false as return value of Tick()
            Assert.AreEqual(false, actual);

            // oStart must not be changed
            Assert.AreEqual(3, onStartTweens.Values.Sum());
            Assert.AreEqual(1, onStartTweens[tween1]);
            Assert.AreEqual(1, onStartTweens[tween2]);
            Assert.AreEqual(1, onStartTweens[tween3]);
            // onUpdate must not be changed
            Assert.AreEqual(3 + 3 + 3 + 2 + 1, onUpdateTweens.Values.Sum());
            Assert.AreEqual(1 + 1 + 1, onUpdateTweens[tween1]);
            Assert.AreEqual(1 + 1 + 1 + 1, onUpdateTweens[tween2]);
            Assert.AreEqual(1 + 1 + 1 + 1 + 1, onUpdateTweens[tween3]);
            // onUpdate must not be changed
            Assert.AreEqual(3, onCompleteTweens.Values.Sum());
            Assert.AreEqual(1, onCompleteTweens[tween1]);
            Assert.AreEqual(1, onCompleteTweens[tween2]);
            Assert.AreEqual(1, onCompleteTweens[tween3]);
        }
Exemple #24
0
        //
        //Sie können beim Verfassen Ihrer Tests die folgenden zusätzlichen Attribute verwenden:
        //
        //Mit ClassInitialize führen Sie Code aus, bevor Sie den ersten Test in der Klasse ausführen.
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Mit ClassCleanup führen Sie Code aus, nachdem alle Tests in einer Klasse ausgeführt wurden.
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Mit TestInitialize können Sie vor jedem einzelnen Test Code ausführen.
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Mit TestCleanup können Sie nach jedem einzelnen Test Code ausführen.
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///Ein Test für "FieldAccessor`1-Konstruktor"
        ///</summary>
        public void FieldAccessorConstructorTestHelper <TValueType>()
        {
            var       obj       = new TweeningTestObject();
            FieldInfo fieldInfo = obj.GetType().GetField("GenericValue");
            var       target    = new FieldAccessor <TValueType>(obj, fieldInfo);
        }
        //
        //Sie können beim Verfassen Ihrer Tests die folgenden zusätzlichen Attribute verwenden:
        //
        //Mit ClassInitialize führen Sie Code aus, bevor Sie den ersten Test in der Klasse ausführen.
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Mit ClassCleanup führen Sie Code aus, nachdem alle Tests in einer Klasse ausgeführt wurden.
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Mit TestInitialize können Sie vor jedem einzelnen Test Code ausführen.
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Mit TestCleanup können Sie nach jedem einzelnen Test Code ausführen.
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///Ein Test für "PropertyAccessor`1-Konstruktor"
        ///</summary>
        public void PropertyAccessorConstructorTestHelper <TValueType>()
        {
            var obj          = new TweeningTestObject();
            var propertyInfo = obj.GetType().GetProperty("GenericValue");
            var target       = new PropertyAccessor <TValueType>(obj, propertyInfo);
        }