Robot Framework冒泡排序9 5 8 3 6
时间: 2024-02-29 17:54:30 浏览: 99
以下是使用Robot Framework编写的针对输入列表 [9, 5, 8, 3, 6] 的冒泡排序算法示例:
*** Test Cases ***
Bubble Sort Test
[Documentation] Bubble Sort Algorithm Test
[Tags] Bubble Sort
${list} Create List 9 5 8 3 6
Log Original List: ${list}
${sorted_list} Bubble Sort ${list}
Log Sorted List: ${sorted_list}
List Should Be Equal ${sorted_list} 3 5 6 8 9
*** 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}