问题 问答题

[说明]

逻辑覆盖法是设计白盒测试用例的主要方法之一,它是通过对程序逻辑结构的遍历实现程序的覆盖。针对以下由C语言编写的程序,按要求回答问题。

getit( int m)

int i, k;

k=sqrt(m);

for ( i=2; i<=k; i++)

if (m % i=0) break;

if ( i>=k+1 )

printf( "%d is a selected number\n", m);

else

printf( "%d is not a selected number\n", m );

请画出上述程序的控制流程图,并计算其控制流图的环路复杂度V(G)。假设函数getit的参数m取值范围是150〈m〈160,请使用基本路径测试法设计测试用例,将参数m的取值填入下表,使之满足基本路径覆盖要求。

答案

参考答案:

本题考查白盒测试用例设计方法:基本路径法。涉及的知识点包括:根据代码绘制程序流图、计算环路复杂度以及设计测试用例。注意测试用例的数目本应和环路复杂度是一致的,但存在特殊情况。

控制流图:

环路复杂度:

V(G)=4

基本路径覆盖用例:

阅读理解

The world would be a very different place if someone hadn’t invented the lift. There would be few, if any, high-rise buildings because people would refuse to climb many stairs. By the time workers reached their offices on the top floors of a tower building, it would be time to go home – if they were not too tired for the long walk down!

The first lift that we know about was used by the Greek scientist, Archimedes, in about 230 BC. It was a simple place that could be pulled up and down with a rope. A lift like this was used much later in the 12th century by priests who lived on top of a mountain at Metereo in Greece. Because they were afraid of killers, the priests had not built any stairs up the mountain. The only way up was by lift, which priests worked from the top of the mountain.

A few hundred years later, a Frenchman, Villayer, invented a ‘flying chair’ which used a rope and a place. A number of rich people had these ‘flying chairs’ built in their homes, including Queen Anne of England in Windsor Castle and Louis XVI of France at Versailles. Unluckily, Louis’ daughter was badly hurt when using one of the chairs, and Villayer ran away, afraid that he would be punished.

The main problem for lift engineers was that either humans or animals were needed to pull the ropes. This problem was not worked out until the discovery of steam power. But even steam powered lifts were not always safe because they also used ropes which sometimes broke. If the rope broke - which it sometimes did - the lift fell to the ground and people in it were killed or hurt. This problem worked out in 1854 when an American, Elisha Otis, invented something which stopped the lift from falling if the rope broke. At first Otis lifts were used only in factories, then in 1857 he built one in a large New York store. Now lifts use electric power and are completely safe. They also travel very quickly. Some lifts travel faster than 60 kilometers an hour.

小题1:The writer thinks that lifts are important today because __________.

A.people like playing on them

B.they are the best way of using steam power

C.we need them for tall buildings

D.workers are lazy小题2:The 12th century priests had a simple lift instead of stairs because ___________.

A.they thought the stairs were broken

B.they liked having stairs and a lift

C.the lived at the bottom of a mountain

D.they were afraid of killers小题3:Villayer thought he would be punished because ____________.

A.poor people could not afford his ‘flying chair

B.someone was hurt in one of his ‘flying chairs’

C.his ‘flying chair’ did not work at all

D.he ran away with Louis XVI’s daughter小题4:Steam power meant that ________  .

A.they did not need a living thing to pull the ropes

B.Elisha Otis could invent a lift that would not fall

C.the rope always broke

D.they could use lifts in factories

多项选择题