| 1 | component SortExercise |
|---|
| 2 | export Executable |
|---|
| 3 | |
|---|
| 4 | import List.{...} |
|---|
| 5 | import Shuffle.{...} |
|---|
| 6 | |
|---|
| 7 | sort(a: List[\ZZ32\]): List[\ZZ32\] = |
|---|
| 8 | fail("You still need to implement a sort function.") |
|---|
| 9 | |
|---|
| 10 | run(): () = do |
|---|
| 11 | emptylist = <|[\ZZ32\] |> |
|---|
| 12 | zero = <|[\ZZ32\] 0 |> |
|---|
| 13 | zeroes = <|[\ZZ32\] 0 | _ <- 0#10 |> |
|---|
| 14 | zeroOne = <|[\ZZ32\] 0, 1 |> |
|---|
| 15 | oneZero = <|[\ZZ32\] 1, 0 |> |
|---|
| 16 | lots = <|[\ZZ32\] i | i <- 0#100 |> |
|---|
| 17 | shuffled = shuffle(lots) |
|---|
| 18 | doubled = lots || lots |
|---|
| 19 | doubleshuffled = shuffle(doubled) |
|---|
| 20 | sortedDoubled = <|[\ZZ32\] i | i <- lots, _ <- 0#2 |> |
|---|
| 21 | assert(emptylist, sort(emptylist)) |
|---|
| 22 | assert(zero, sort(zero)) |
|---|
| 23 | assert(zeroOne, sort(zeroOne)) |
|---|
| 24 | assert(zeroOne, sort(oneZero)) |
|---|
| 25 | assert(lots, sort(lots)) |
|---|
| 26 | assert(sortedDoubled, sort(doubled)) |
|---|
| 27 | assert(sortedDoubled, sort(doubleshuffled)) |
|---|
| 28 | println("Your sort appears to work.") |
|---|
| 29 | end |
|---|
| 30 | |
|---|
| 31 | end |
|---|