问题 问答题

阅读下列说明,回答问题1至问题3,将解答填入答题纸的对应栏内。【说明】逻辑覆盖法是设计白盒测试用例的主要方法之一,它是通过对程序逻辑结构的遍历实现程序的覆盖。针对以下由C语言编写的程序,按要求回答问题。

【问题1】请给出满足100%DC(判定覆盖)所需的逻辑条件。

【问题2】请画出上述程序的控制流图,并计算其控制流图的环路复杂度V(G)。

【问题3】请给出【问题2】中控制流图的线性无关路径。

答案

参考答案:

【问题1】

【问题2】

控制流图

https://img.ixiawen.com/uploadfile/2017/0802/20170802093802294.gif

环路复杂度V(G)=7

【问题3】

线性无关路径:

1)1-2-3-4-2…

2)1-2-3-5-6-2…

3)1-2-3-5-7-13

4)1-2-8-9-10-11-13

5)1-2-8-9-10-12-13

6)1-2-8-9-12-13

7)1-2-8-12-13

解析:

本题考查白盒测试技术,属于比较传统的题目,考查点也与往年类似。

【问题1】本题考查白盒测试方法中的判定覆盖法。判定覆盖指设计足够的测试用例,使得被测程序中每个判定表达式至少获得一次“真”值和“假”值,从而使程序的每一个分支至少都通过一次。本题中程序一共有5个判定,所以满足判定覆盖一共就需要10个逻辑条件,这些条件详见参考答案:。

【问题2】本题考查白盒测试方法中的基本路径法。涉及到的知识点包括:根据代码绘制控制流图、计算环路复杂度。控制流图是描述程序控制流的一种图示方法。其

基本符号有圆圈和箭线:圆圈为控制流图中的一个结点,表示一个或多个无分支的语句;带箭头的线段称为边或连接,表示控制流。基本结构如下所示:

根据题中程序绘制的控制流图如下所示。其中要特别注意的是,如果判断中的条件表达式是复合条件,即条件表达式是由一个或多个逻辑运算符连接的逻辑表达式,则需要改变复合条件的判断为一系列之单个条件的嵌套的判断。本题程序中,if(ranges【start】.start_value<=value&&value<(int)(fanges【start】.start_value+range_size)这条判断语句中的判定由两个条件组成,因此在画控制流图的时候需要拆开成两条判断语句。控制流图详见参考答案:。环路复杂度用来衡量一个程序模块所包含的判定结构的复杂程度,数量上表现为独立路径的条数,即合理地预防错误所需测试的最少路径条数。环路复杂度等于图中判定节点的个数加1,图中判定节点个数为6,所以V(G)=7。

【问题3】本题考查白盒测试方法中的基本路径法。涉及到的知识点包括根据控制流图和环路复杂度确定线性无关路径。线性无关路径是指包括一组以前没有处理的语句或条件的一条路径。从控制流图来看,一条线性无关路径是至少包含有一条在其他线性无关路径中从未有过的边的路径。

对问题2中的控制流图,其线性无关路径的集合为:(1)1-2-3-4-2...(2)1-2-3-5-6-2..(3)1-2-3-5-7-13(4)1-2-8-9-10-11-13(5)1-2-8-9-10-12-13(6)1-2-8-9-12-13(7)1-2-8-12-13这7条路径组成了问题2中控制流图的一个基本路径集。只要设计出的测试用例能确保这些基本路径的执行,就可以使程序中的每个可执行语句至少执行一次,每个条件的取真和取假分支也能得到测试。需要注意的是,基本路径集不是唯一的,对于给定的控制流图,可以得到不同的基本路径集。

阅读理解

There are a lot of differences in life in the US that you can only learn by living here. However, we will try to introduce you to some of the more important cultural differences.

Personal Space

When two people are talking to each other, they tend to stand a distance apart. Each person has an invisible boundary (界限) around their body into which other people may not come.

Interestingly,the average personal distance varies from culture to culture. Americans tend to require more personal space than in other cultures. So if you try to get too close to an American during your conversation, he or she will feel that you are “in their face” and will try to back away.

Try to avoid physical contact while you are speaking, since this may also lead to discomfort.

Tipping(小费)

Restaurants do not include a service charge in the bill, so you should tip the waiter 15% of the total bill. If service is slow or particular bad, some Americans will tip only 10%. If service is particularly good, it is appropriate to tip 20%. If service is so bad that you will never eat in the restaurant again, leave two cents. It tells the waiter that you haven’t forgotten to leave a tip. Tipping is only appropriate in restaurants which offer table service. You do not tip the cashier in a fast food restaurant.

Gestures

To wave goodbye or hello to someone, raise your hand and wave it from side to side, not front to back. Wave the whole hand, not just the fingers. Waving the hand front to back or the fingers up and down means “no”, “stop”, or “go away’. Holding your hand up with the palm facing forward but no movement means “stop”.

If you want to point at an object, extend the index finger and use it to point at the object. It is not polite to point at people.

Although showing your fist with the thumb up or your open hand with the tips of the thumb and index finger together forming an “O” means “OK”, these are stereotypes (老套). Americans understand these gestures, but they are mainly used by actors in movies, not in real life.

小题1: If an American to whom you are speaking backs away a little, you’d better __________.

A.not try to close the gap

B.stop talking with him or her

C.back away too

D.ask him or her what happened小题2:Which of the following statements is TRUE when you eat out in the US?

A.The tip always ranges from 10% to 20% of the total bill.

B.You needn’t leave a tip if you will never eat in the restaurant.

C.It’s unnecessary to tip the waiter in a restaurant.

D.Tipping is not necessary in fast food restaurants.小题3:Which of the following gestures is not used in Americans’ daily life?

A               B.             C.               D.

.         

小题4:We can learn from the passage that in the US ___________________.

A.it’s natural to touch each other in a conversation.

B.it’s polite to leave a tip though the service is bad.

C.there is only one gesture meaning “stop”.

D.Americans use the same gesture to point at people and objects.

填空题