robot framework冒泡排序
时间: 2023-07-10 12:27:01 浏览: 172
冒泡排序(Bubble Sort)是一种基本的比较排序算法 冒泡法排序c语言程序
以下是使用Robot Framework编写的冒泡排序算法示例:
*** Test Cases ***
Bubble Sort Test
[Documentation] Bubble Sort Algorithm Test
[Tags] Bubble Sort
${list} Create List 5 2 8 1 3
Log Original List: ${list}
${sorted_list} Bubble Sort ${list}
Log Sorted List: ${sorted_list}
List Should Be Equal ${sorted_list} 1 2 3 5 8
*** Keywords ***
Bubble Sort
[Arguments] ${list}
${length} Get Length ${list}
FOR ${i} IN RANGE 0 ${length}-1
FOR ${j} IN RANGE 0 ${length}-${i}-1
${current_item} Get From List ${list} ${j}
${next_item} Get From List ${list} ${j+1}
Run Keyword If ${current_item}>${next_item} Swap Items ${list} ${j} ${j+1}
[Return] ${list}
Swap Items
[Arguments] ${list} ${index1} ${index2}
${item1} Get From List ${list} ${index1}
${item2} Get From List ${list} ${index2}
Set List Value ${list} ${index1} ${item2}
Set List Value ${list} ${index2} ${item1}
阅读全文