词频统计测试

1.上网查询关于VS2015对程序进行单元测试的教程,学习了测试的方法。

  (1)首先打开VS2015新建一个测试项目,如图:

  

  (2)编写测试代码:

  此代码是对MAP映射存储单词进行测试

#include "stdafx.h"

using namespace System;
using namespace System::Text;
using namespace System::Collections::Generic;
using namespace Microsoft::VisualStudio::TestTools::UnitTesting;

namespace TestProject1
{
    [TestClass]
    public ref class UnitTest
    {
    private:
        TestContext^ testContextInstance;

    public: 
        /// <summary>
        ///获取或设置测试上下文,该上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        property Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ TestContext
        {
            Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ get()
            {
                return testContextInstance;
            }
            System::Void set(Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ value)
            {
                testContextInstance = value;
            }
        };

        #pragma region Additional test attributes
        //
        // 编写测试时,可以使用以下附加特性: 
        //
        // 在运行类中的第一个测试之前使用 ClassInitialize 运行代码
        //[ClassInitialize()]
        //static void MyClassInitialize(TestContext^ testContext) {};
        //
        // 在类中的所有测试都已运行之后使用 ClassCleanup 运行代码
        //[ClassCleanup()]
        //static void MyClassCleanup() {};
        //
        //在运行每个测试之前,使用 TestInitialize 来运行代码
        //[TestInitialize()]
        //void MyTestInitialize() {};
        //
        //在每个测试运行完之后,使用 TestCleanup 来运行代码
        //[TestCleanup()]
        //void MyTestCleanup() {};
        //
        #pragma endregion 

        [TestMethod]
        void TestMethod1()
        {
            //
            // TODO:  在此处添加测试逻辑
            //
            char text[1000] = { "My English is very very pool" };

            int i = 0;

            while (text[i] != '\0')

            {

                char s[30];

                int j = 0;

                while ((text[i] >= 'a'&&text[i] <= 'z') || (text[i] >= 'A'&&text[i] <= 'Z') || text[i] == '-')

                {

                    if (text[i] >= 'A'&&text[i] <= 'Z')

                        text[i] += 'a' - 'A';

                    s[j++] = text[i++];

                }

                Assert::IsNotNull(s[j]);

                s[j] = '\0';

                if (text[i] == '\0')

                    break;

                else

                    i++;

            }

        };
        [TestMethod]
        void TestMethod2()
        {
            //
            // TODO:  在此处添加测试逻辑
            //
            char text[1000] = { "Hello,My name is jay" };

            int i = 0;

            while (text[i] != '\0')

            {

                char s[30];

                int j = 0;

                while ((text[i] >= 'a'&&text[i] <= 'z') || (text[i] >= 'A'&&text[i] <= 'Z') || text[i] == '-')

                {

                    if (text[i] >= 'A'&&text[i] <= 'Z')

                        text[i] += 'a' - 'A';

                    s[j++] = text[i++];

                }

                Assert::IsNotNull(s[j]);

                s[j] = '\0';

                if (text[i] == '\0')

                    break;

                else

                    i++;

            }

        };
    };
}

  测试结果:

https://git.coding.net/ziyoujay/cipintongjiceshi.git

git@git.coding.net:ziyoujay/cipintongjiceshi.git

单元测试psp:

C(类别) C(内容) S(开始时间) ST(结束时间) I(耽误时间) △(实际时间)
分析 查资料 8:00 9:00 0 60
编码 代码实现 9:30   12:30  30 150
调试 调试程序并实现 14:00 15:00 20 40
文档 撰写说明书 15:30 16:00 0 30
posted on 2016-09-28 16:56  自由jay  阅读(222)  评论(1编辑  收藏  举报