Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / example_sorter.nit
index e82282c..7f43b63 100644 (file)
 # limitations under the License.
 
 
-class BackIntSorter
-special AbstractSorter[Int]
-       redef meth compare(a: Int, b: Int): Int
+class BackIntComparator
+       super Comparator
+       redef type COMPARED: Int is fixed
+       redef fun compare(a: Int, b: Int): Int
        do
                return b <=> a
        end
@@ -25,9 +26,10 @@ special AbstractSorter[Int]
        init do end
 end
 
-class DecimalSorter
-special AbstractSorter[Int]
-       redef meth compare(a: Int, b: Int): Int
+class DecimalComparator
+       super Comparator
+       redef type COMPARED: Int is fixed
+       redef fun compare(a: Int, b: Int): Int
        do
                return (a%10) <=> (b%10)
        end
@@ -35,7 +37,7 @@ special AbstractSorter[Int]
        init do end
 end
 
-meth get_an_array(nb: Int): Array[Int]
+fun get_an_array(nb: Int): Array[Int]
 do
        var res = new Array[Int].with_capacity(nb)
        var j = 64
@@ -51,11 +53,11 @@ end
 
 var q = get_an_array(50)
 print(q.join(" "))
-(new ComparableSorter[Int]).sort(q)
+(default_comparator).sort(q)
 print(q.join(" "))
-(new DecimalSorter).sort(q)
+(new DecimalComparator).sort(q)
 print(q.join(" "))
-(new BackIntSorter).sort(q)
+(new BackIntComparator).sort(q)
 print(q.join(" "))
-(new DecimalSorter).sort(q)
+(new DecimalComparator).sort(q)
 print(q.join(" "))