zoukankan      html  css  js  c++  java
  • 词频统计测试

    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] != '')
    
                {
    
                    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] = '';
    
                    if (text[i] == '')
    
                        break;
    
                    else
    
                        i++;
    
                }
    
            };
            [TestMethod]
            void TestMethod2()
            {
                //
                // TODO:  在此处添加测试逻辑
                //
                char text[1000] = { "Hello,My name is jay" };
    
                int i = 0;
    
                while (text[i] != '')
    
                {
    
                    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] = '';
    
                    if (text[i] == '')
    
                        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
  • 相关阅读:
    Z-stack之OSAL初始化流程
    回调函数
    VCC,VDD,VEE,VSS,VPP 表示的意义
    ARM内核全解析,从ARM7,ARM9到Cortex-A7,A8,A9,A12,A15到Cortex-A53,A57
    SQL Server 2005 版本的操作系统兼容性详细列表
    Windows Xp Home Edition 安装IIS组件
    MySql 5.7中添加用户,新建数据库,用户授权,删除用户,修改密码
    AtCoder Beginner Contest 077(ABC)
    Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)(A B C D)
    B. Which floor?
  • 原文地址:https://www.cnblogs.com/ziyoujay/p/5917054.html
Copyright © 2011-2022 走看看