zoukankan      html  css  js  c++  java
  • 四则运算测试

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

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

      

      (2)编写测试代码:

      此代码是对四则运算求值测试

    #include "stdafx.h"
    
    using namespace System;
    using namespace System::Text;
    using namespace System::Collections::Generic;
    using namespace Microsoft::VisualStudio::TestTools::UnitTesting;
    
    namespace TestProject2
    {
        struct Number
        {
            double a;
            bool b;//0数字 1字符 
        };
        Number s3[100];
    
        [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 
            double qiuzhi()
            {
                //stack<Number>s3;
                //stack<double>s4;
                int tou1 = 2;
                double s4[100];
                int tou2 = 0;
                //while (!s3.empty())
                while (tou1 != -1)
                {
                    //Number c1 = s3.top();
                    Number c1 = s3[tou1--];
                    //s3.pop();
                    if (c1.b == 0)
                        s4[tou2++] = c1.a;
                    //s4.push(c1.a);
                    else
                    {
                        //double c2 = s4.top();
                        double c2 = s4[--tou2];
                        //s4.pop();
                        //double c3 = s4.top();
                        ///s4.pop();
                        double c3 = s4[--tou2];
                        double c4;
                        switch ((int)c1.a)
                        {
                        case '+':c4 = c3 + c2; break;
                        case '-':c4 = c3 - c2; break;
                        case '*':c4 = c3*c2; break;
                        case '/':c4 = c3 / c2; break;
                        }
                        s4[tou2] = c4;
                    }
                }
                return s4[tou2];
            }
    
    
            
                
            [TestMethod]
            void TestMethod1()
            {
                //
                // TODO:  在此处添加测试逻辑
                //
                s3[0].a = 43;
                s3[0].b = 1;
    
                s3[1].a = 1;
                s3[1].b = 0;
    
                s3[2].a = 2;
                s3[2].b = 0;
                double s = qiuzhi();
                Assert::AreEqual(s, 3.0);
    
            };
        };
    }

    结果为:

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

    https://git.coding.net/ziyoujay/sizeyunsuanceshi.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

  • 相关阅读:
    solr初步了解
    jieba初步了解
    情感计算emokit
    常用命令
    java跨域访问问题记录
    mysql 免安装版配置
    Android 图片缩放方法
    spring android http
    sql join 与where的区别
    android activitygroup 使用
  • 原文地址:https://www.cnblogs.com/ziyoujay/p/5917539.html
Copyright © 2011-2022 走看看