#!/usr/bin/ruby

#
## http://rosettacode.org/wiki/Sorting_algorithms/Selection_sort#Sidef
#

class Array {
    method selectionsort {
        range(0, self.len-2).each { |i|
            var min_idx = i;
            range(i+1, self.len-1).each { |j|
                self[j] < self[min_idx] && (
                    min_idx = j;
                )
            }
            self[i, min_idx] = self[min_idx, i];
        }
        return self;
    }
}

var r = 10.of { .irand }
var arr = r.selectionsort;
assert_eq(arr, r.sort)

say "** Test passed!"
