在Form1中测试自定义函数

时间:2018-12-09 02:09:21

标签: c# unit-testing

我有一些单元测试可以成功测试添加到整个项目中的其他类中的功能。我似乎无法“看到”我在Form1中添加的任何函数,这些函数是部分类From1:form的任何其他文件中。

我要测试的功能已修改internal。我已将[assembly: InternalsVisibleTo("Tests")]添加到文件Properties-> AssemblyInfo.cs

我在做什么错了?

我要测试的功能:

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows.Forms;
using Accord.Collections;
using System.IO;
using Accord.Math;
using g = GeometRi;
using msf = System.Math;


namespace ProcessPointsCSharp
{
    public partial class Form1 : Form
    {

    internal List<Point> FindPointsInCapsule(
        List<NodeDistance<KDTreeNode<Point>>> points,
        Point searchPoint,
        Axis axis,
        double width = 0,
        double radius = 0.03,
        double bandwidth = 0.005
        )
    {
        g.Point3d lowerPoint = new Point();
        g.Point3d upperPoint = new Point();
        g.Segment3d centerLine;
        double innerRadius = radius - bandwidth;

        switch (axis)
        {
            case Axis.x:
                lowerPoint = new Point(searchPoint.X - (width / 2), searchPoint.Y, searchPoint.Z);
                upperPoint = new Point(searchPoint.X + (width / 2), searchPoint.Y, searchPoint.Z);
                break;
            case Axis.y:
                lowerPoint = new Point(searchPoint.X, searchPoint.Y - (width / 2), searchPoint.Z);
                upperPoint = new Point(searchPoint.X, searchPoint.Y + (width / 2), searchPoint.Z);
                break;
            case Axis.z:
                lowerPoint = new Point(searchPoint.X, searchPoint.Y, searchPoint.Z - (width / 2));
                upperPoint = new Point(searchPoint.X, searchPoint.Y, searchPoint.Z + (width / 2));
                break;
        }

        centerLine = new g.Segment3d(lowerPoint, upperPoint);

        List<Point> results = new List<Point>();
        foreach(NodeDistance<KDTreeNode<Point>> kv in points)
        {
            if(centerLine.DistanceTo(kv.Node.Value) > innerRadius && centerLine.DistanceTo(kv.Node.Value) < radius)
            {
                results.Add(kv.Node.Value);
            }
        }
        return results;
    }

}

我的测试文件:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using g = GeometRi;
using Accord.Collections;
using ProcessPointsCSharp;
using Helpers;

namespace Tests
{
    [TestClass]
    public class CapsuleTest
    {
        [TestMethod]
        public void TestMethod1()
        {

            KDTree<Point> tree = new KDTree<Point>(3);

            tree.Add(
                new double[] { -0.30652008, 0.39502587, 0.00 },
                new Point(-0.30652008, 0.39502587, 0.00)
                );

            tree.Add(
                new double[] { 0, 0, 0, },
                new Point(0, 0, 0)
                );

            tree.Add(
                new double[] { 0.45, 0.31819805, 0.31819805 },
                new Point( 0.45, 0.31819805, 0.31819805 )
                );

            tree.Add(
                new double[] { 2.00723708, 0.37538366, 0.33028338 },
                new Point(2.00723708, 0.37538366, 0.33028338)
                );

            tree.Add(
                new double[] { 0.25, 0.1767767, 0.1767767 },
                new Point(0.25, 0.1767767, 0.1767767)
                );

            tree.Add(
                new double[] { 3.59315974, 1.32408059, 0.00 },
                new Point(3.59315974, 1.32408059, 0.00)
                );

            tree.Add(
                new double[] { 5.41553352 , -0.23012364 , 0.00 },
                new Point(5.41553352, -0.23012364, 0.00)
                );

            var points = tree.Nearest(new double[] { 0,0,0}, 100);

            Assert.AreEqual(7, points.Count);
        }
    }
}

0 个答案:

没有答案