mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
Issue #252 adding Sort module in Carp using Heap.Heapsort
This commit is contained in:
parent
24e8cee18f
commit
1543fac3fb
@ -19,3 +19,4 @@
|
||||
(load "Random.carp")
|
||||
(load "Map.carp")
|
||||
(load "Heap.carp")
|
||||
(load "Sort.carp")
|
||||
|
12
core/Sort.carp
Normal file
12
core/Sort.carp
Normal file
@ -0,0 +1,12 @@
|
||||
(use Heap)
|
||||
|
||||
(defmodule Sort
|
||||
(doc sort! "Perform an in-place heapsort of a given array.")
|
||||
(defn sort! [arr]
|
||||
(HeapSort.sort! arr))
|
||||
|
||||
(doc sort "Perform a heapsort in a new copy of given array.")
|
||||
(defn sort [arr]
|
||||
(HeapSort.sort arr))
|
||||
)
|
||||
|
25
test/sort.carp
Normal file
25
test/sort.carp
Normal file
@ -0,0 +1,25 @@
|
||||
(use Sort)
|
||||
|
||||
(load "Test.carp")
|
||||
(use Test)
|
||||
|
||||
(defn main []
|
||||
(with-test test
|
||||
(let-do [arr [1 3 4 2 6 1]
|
||||
exp [1 1 2 3 4 6]]
|
||||
(Sort.sort! &arr)
|
||||
(assert-equal test
|
||||
&exp
|
||||
&arr
|
||||
"Sort.sort! works"))
|
||||
|
||||
(let-do [arr [1 3 4 2 6 1]
|
||||
exp [1 1 2 3 4 6]
|
||||
res (Sort.sort &arr)]
|
||||
(assert-equal test
|
||||
&exp
|
||||
&res
|
||||
"Sort.sort works"))
|
||||
|
||||
(print-test-results test)))
|
||||
|
Loading…
Reference in New Issue
Block a user