# 软件工程第二次作业

https://edu.cnblogs.com/campus/sau/Computer1701-1705/homework/10583

## 二. 代码与代码运行结果

#include <iostream>
using namespace std;

int main()
{
int n,i,a[10],sum1=0,sum2=0,mod=0;
cout << "请输入数组数量"<<endl;
cin >> n;
cout << "请输入数组" << endl;
for (i = 0; i < n; i++)
{
cin >> a[i];
}
for (i = 0; i < n; i++)
{
sum1 = sum1 + a[i];
if (sum1 < 0)
{
sum1 = 0;
}
if (sum1 > sum2)
{
sum2 = sum1;
}
}
cout << "最大子段和为" << endl;
cout << sum2;
return 0;
}



github链接code

## 三. 单元测试工具

#include "CppUnitTest.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace UnitTest2
{
TEST_CLASS(UnitTest2)
{
public:

TEST_METHOD(TestMethod1)
{
}
};
}


## 四. 判定条件覆盖

i处于累加的状态，可以不用考虑，所以判定一不用考虑真假

#include "CppUnitTest.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace UnitTest1
{
TEST_CLASS(UnitTest1)
{
public:
TEST_METHOD(TestMethod1)
{
int n = 6, i, sum1 = 0, sum2 = 0, mod = 0;
int a[6] = { -2,6,-5,8,-7,9 };
for (i = 0; i < n; i++)
{
sum1 = sum1 + a[i];
if (sum1 < 0)
{
sum1 = 0;
}
if (sum1 > sum2)
{
sum2 = sum1;
}
}
}
TEST_METHOD(TestMethod2)
{
int n = 0, i, sum1 = 0, sum2 = 0, mod = 0;
for (i = 0; i < n; i++)
{
sum1 = sum1;
if (sum1 < 0)
{
sum1 = 0;
}
if (sum1 > sum2)
{
sum2 = sum1;
}
}
}

};
}


2020/4/2

17:30

18:10

25

0

## 六. 心得

posted @ 2020-04-03 19:42  你会不会觉得我很菜  阅读(162)  评论(0编辑  收藏  举报