词频统计测试

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:009:00060
编码代码实现9:30  12:30 30150
调试调试程序并实现14:0015:002040
文档撰写说明书15:3016:00030

转载于:https://www.cnblogs.com/ziyoujay/p/5917054.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值