whiley_test_file 0.6.2

An API for manipulating test files for the Whiley Programming Language.
Documentation
original.name="DoWhile_Invalid_6"
======
>>> main.whiley
type pos is (int x) where x >= 1

property sorted(int[] arr, int n) -> bool:
    return (n >= 1 && n <= |arr|) ==>
           all { i in 1..n | arr[i-1] <= arr[i] }

function bubbleSort(int[] items) -> (int[] result)
// Resulting array is sorted
ensures sorted(result,|result|):
    //
    int tmp
    bool clean
    //
    do:
        // reset clean flag
        clean = true
        pos i = 1
        // look for unsorted pairs
        while i < |items|
        // If clean, everything so far sorted
        where clean ==> sorted(items,i):
            if items[i-1] > items[i]:
               // found unsorted pair
               clean = true
               tmp = items[i-1]
               items[i-1] = items[i]
               items[i] = tmp
            i = i + 1
    while !clean
    // If clean, whole array is sorted
    where clean ==> sorted(items,|items|)
    // Done
    return items

public export method test():
    //
    assume bubbleSort([0]) == [0]
    //
    assume bubbleSort([1,0]) == [0,1]
    //
    assume bubbleSort([1,0,4,3]) == [0,1,3,4]
---
E721 main.whiley 21,14:38