Example #1
0
        public void TestCircleClass()
        {
            var assert = new TypeAssert <Circle>();

            assert.Extends <TwoDimensionalShape>();
            assert.NonAbstract();
            assert.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param <int>("x"),
                new Param <int>("y"),
                new Param <int>("radius")
                );
            assert.ConstructorCount(1);

            assert.Property <string>(
                "Name",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
                ).Override();

            assert.Property <double>(
                "Area",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
                ).Override();

            assert.Property <int>(
                "Radius",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty |
                BindingFlags.SetProperty
                );

            assert.Method <string>(
                "ToString",
                BindingFlags.Public |
                BindingFlags.Instance
                ).Override();

            assert.Field <int>(
                "Dimension1",
                BindingFlags.NonPublic |
                BindingFlags.Instance
                ).DeclaredIn <TwoDimensionalShape>();

            assert.Field <int>(
                "Dimension2",
                BindingFlags.NonPublic |
                BindingFlags.Instance
                ).DeclaredIn <TwoDimensionalShape>();
        }
        public void TestSphere()
        {
#if !DEBUG
        Assert.Multiple(() => {
#endif
            var assert = new TypeAssert<Sphere>();
            assert.Extends<ThreeDimensionalShape>();
            assert.NonAbstract();
            assert.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<int>("x"),
                new Param<int>("y"),
                new Param<int>("radius")
            );
            assert.ConstructorCount(1);

            assert.Property<string>(
                "Name",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            ).Override();

            assert.Property<double>(
                "Area",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            ).Override();

            assert.Property<double>(
                "Volume",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            ).Override();

            assert.Property<int>(
                "Radius",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty |
                BindingFlags.SetProperty
            );

            assert.Method<string>(
                "ToString",
                BindingFlags.Public |
                BindingFlags.Instance
            ).Override();

            var dimension1 = assert.Field<int>(
                "Dimension1",
                BindingFlags.NonPublic |
                BindingFlags.Instance
            ).DeclaredIn<ThreeDimensionalShape>();

            var dimension2 = assert.Field<int>(
                "Dimension2",
                BindingFlags.NonPublic |
                BindingFlags.Instance
            ).DeclaredIn<ThreeDimensionalShape>();

            var dimension3 = assert.Field<int>(
              "Dimension3",
              BindingFlags.NonPublic |
              BindingFlags.Instance
          ).DeclaredIn<ThreeDimensionalShape>();

            // var obj = new Sphere(1, 2 ,3);
            dynamic obj = assert.New(2, 1, 4);
            Assert.AreEqual("Sphere", obj.Name);
            Assert.AreEqual(2, obj.X);
            Assert.AreEqual(1, obj.Y);
            Assert.AreEqual(4, obj.Radius);
            Assert.AreEqual(4, dimension1.GetValue(obj));
            Assert.AreEqual(4, dimension2.GetValue(obj));
            Assert.AreEqual(4, dimension3.GetValue(obj));
            Assert.AreEqual(201.06192982974676, obj.Area, 1E-10);
            Assert.AreEqual(268.08257310632899, obj.Volume, 1E-10);
            Assert.AreEqual("(2, 1) radius: 4", obj.ToString());

            obj.Radius = 7;
            Assert.AreEqual(7, dimension1.GetValue(obj));
            Assert.AreEqual(7, dimension2.GetValue(obj));
            Assert.AreEqual(615.75216010359941, obj.Area, 1E-10);
            Assert.AreEqual(1436.7550402417321, obj.Volume, 1E-10);
            Assert.AreEqual("(2, 1) radius: 7", obj.ToString());
#if !DEBUG
});
#endif
        }
        public void TestCube()
        {
#if !DEBUG
        Assert.Multiple(() => {
#endif
            var assert = new TypeAssert<Cube>();
            assert.Extends<ThreeDimensionalShape>();
            assert.NonAbstract();
            assert.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<int>("x"),
                new Param<int>("y"),
                new Param<int>("side")
            );
            assert.ConstructorCount(1);

            assert.Property<string>(
                "Name",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            ).Override();

            assert.Property<double>(
                "Area",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            ).Override();

            assert.Property<double>(
                "Volume",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            ).Override();

            assert.Property<int>(
                "Side",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty |
                BindingFlags.SetProperty
            );

            assert.Method<string>(
                "ToString",
                BindingFlags.Public |
                BindingFlags.Instance
            ).Override();

            var dimension1 = assert.Field<int>(
                "Dimension1",
                BindingFlags.NonPublic |
                BindingFlags.Instance
            ).DeclaredIn<ThreeDimensionalShape>();

            var dimension2 = assert.Field<int>(
                "Dimension2",
                BindingFlags.NonPublic |
                BindingFlags.Instance
            ).DeclaredIn<ThreeDimensionalShape>();

            var dimension3 = assert.Field<int>(
                "Dimension3",
                BindingFlags.NonPublic |
                BindingFlags.Instance
            ).DeclaredIn<ThreeDimensionalShape>();

            // var obj = new Sphere(1, 2 ,3);
            dynamic obj = assert.New(3, 5, 2);
            Assert.AreEqual("Cube", obj.Name);
            Assert.AreEqual(3, obj.X);
            Assert.AreEqual(5, obj.Y);
            Assert.AreEqual(2, obj.Side);
            Assert.AreEqual(2, dimension1.GetValue(obj));
            Assert.AreEqual(2, dimension2.GetValue(obj));
            Assert.AreEqual(2, dimension3.GetValue(obj));
            Assert.AreEqual(24, obj.Area, 1E-10);
            Assert.AreEqual(8, obj.Volume, 1E-10);
            Assert.AreEqual("(3, 5) side: 2", obj.ToString());

            obj.Side = 7;
            Assert.AreEqual(7, dimension1.GetValue(obj));
            Assert.AreEqual(7, dimension2.GetValue(obj));
            Assert.AreEqual(294, obj.Area, 1E-10);
            Assert.AreEqual(343, obj.Volume, 1E-10);
            Assert.AreEqual("(3, 5) side: 7", obj.ToString());
#if !DEBUG
});
#endif
        }
        public void TestCircle()
        {
#if !DEBUG
        Assert.Multiple(() => {
#endif
            var assert = new TypeAssert<Circle>();
            assert.Extends<TwoDimensionalShape>();
            assert.NonAbstract();
            assert.Constructor(
                BindingFlags.Public |
                BindingFlags.Instance,
                new Param<int>("x"),
                new Param<int>("y"),
                new Param<int>("radius")
            );
            assert.ConstructorCount(1);

            assert.Property<string>(
                "Name",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            ).Override();

            assert.Property<double>(
                "Area",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty
            ).Override();

            assert.Property<int>(
                "Radius",
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.GetProperty |
                BindingFlags.SetProperty
            );

            assert.Method<string>(
                "ToString",
                BindingFlags.Public |
                BindingFlags.Instance
            ).Override();

            var dimension1 = assert.Field<int>(
                "Dimension1",
                BindingFlags.NonPublic |
                BindingFlags.Instance
            ).DeclaredIn<TwoDimensionalShape>();

            var dimension2 = assert.Field<int>(
                "Dimension2",
                BindingFlags.NonPublic |
                BindingFlags.Instance
            ).DeclaredIn<TwoDimensionalShape>();

            // var obj = new Circle(1, 2 ,3);
            dynamic obj = assert.New(1, 2, 3);
            Assert.AreEqual("Circle", obj.Name);
            Assert.AreEqual(1, obj.X);
            Assert.AreEqual(2, obj.Y);
            Assert.AreEqual(3, obj.Radius);
            Assert.AreEqual(3, dimension1.GetValue(obj));
            Assert.AreEqual(3, dimension2.GetValue(obj));
            Assert.AreEqual(28.274333882308138, obj.Area, 1E-10);
            Assert.AreEqual("(1, 2) radius: 3", obj.ToString());

            obj.Radius = 7;
            Assert.AreEqual(7, dimension1.GetValue(obj));
            Assert.AreEqual(7, dimension2.GetValue(obj));
            Assert.AreEqual(153.93804002589985, obj.Area, 1E-10);
            Assert.AreEqual("(1, 2) radius: 7", obj.ToString());
#if !DEBUG
});
#endif
        }