int i, jk, t.n; n=a.length; for (i-0; ¡<n-1; i++) { k=i; for (j-it1; j<n; j++) { if (alif<a[k]) { k=i: } if (il=k) Farkl; ak=alil; alj-t; 要求: ①计算此程序段的圈复杂度。 ② 用基本路径测试法给出测试路径。 ③ 为各测试路径设计测试用例。

时间: 2023-12-02 07:02:31 浏览: 75
ZIP

OSC2.2editer.zip_oscommerce_oscommerce-2.2_中文编辑器

这段代码有一些语法错误,我先做一些纠正: ``` int i, j, k; n = a.length; for (i = 0; i < n-1; i++) { k = i; for (j = i+1; j < n; j++) { if (a[j] < a[k]) { k = j; } } if (k != i) { int temp = a[i]; a[i] = a[k]; a[k] = temp; } } ``` ①此程序段的圈复杂度为n(n-1)/2,即O(n^2)。 ②基本路径测试法基于程序的控制流图,找出所有可能的独立路径,并为每个独立路径设计测试用例。以下是此程序段的控制流图和基本路径: 控制流图: ``` ---------(1)---------- | for i=0 to n-1 | / \ | ----(2)------ (6) | | k=i; | | | | for j=i+1|to n | | | if a[j] |< a[k]| | | k=j; | | | ------------ | | if k!=i then (3) | | ------------ | | return ----------------------- ``` 基本路径: 1. 1-2-6 2. 1-2-3-6 3. 1-2-3-4-6 4. 1-2-3-5-6 ③为每个基本路径设计测试用例: 1. 最好情况:输入数组已经有序,例如:[1,2,3,4,5] 2. 最坏情况:输入数组逆序,例如:[5,4,3,2,1] 3. 覆盖第3条基本路径的测试用例:[3,2,1,4,5] 4. 覆盖第4条基本路径的测试用例:[1,3,2,5,4]
阅读全文

相关推荐

#include "spi.h" #include "stm32f10x.h" #include "delay.h" void MAX6675_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; SPI_InitTypeDef SPI_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); //pb13,pb14 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOB, &GPIO_InitStructure); SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI2, &SPI_InitStructure); SPI_Cmd(SPI2, ENABLE); } unsigned int TEMP_ReadReg(void) { unsigned char i; unsigned int Temp_2=0; CS=1; SCK=0; __NOP(); __NOP(); CS=0; for(i=0;i<16;i++) { Temp_2<<=1; __NOP(); __NOP(); SCK=1; __NOP(); __NOP(); if(SO==1) { Temp_2=Temp_2|0x01; } else Temp_2=Temp_2|0x00; __NOP(); SCK=0; __NOP(); __NOP(); } SCK =0; __NOP(); __NOP(); CS=1; Temp_2<<=1; Temp_2>>=4;//λÒÆ»ØÀ´²¹Ò»Î» È¡Öµ3-14λ return Temp_2; }