1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2006-2008 Jean Privat <jean@pryen.org>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
19 fun val1
: Int is abstract
20 fun val2
: Int do return val1
26 redef fun val1
: Int do return _a
28 init(i
: Int) do _a
= i
34 redef fun val1
: Int do return _b
/2
35 redef fun val2
: Int do return _b
36 init initelt2
(i
: Int) do _b
= i
41 init(i
: Int) do initelt2
(i
)
48 redef fun val1
: Int do return _c
end
49 redef fun val2
: Int do return _d
end
51 init init2
(i
: Int, j
: Int) do
60 redef fun val1
: Int do return _a
end
61 redef fun val2
: Int do return _b
end
63 init init2
(i
: Int, j
: Int) do
71 redef fun val1
: Int do return 5 end
73 init(i
: Int) do initelt2
(i
)
78 redef type COMPARED: Elt
79 redef fun compare
(a
, b
)
82 return a
.val1
<=> b
.val1
84 return a
.val2
<=> b
.val2
90 _is_val1
= not _is_val1
93 var is_val1
: Bool = false
102 return new A
(10.rand
)
104 return new B
(10.rand
)
106 return new C
.init2
(10.rand
, 10.rand
)
108 return new D
.init2
(10.rand
, 10.rand
)
110 return new E
(10.rand
)
116 if not args
.is_empty
then
120 var array
= new Array[Elt].with_capacity
(n
)
122 array
.push
(generator
)
125 var comparator
= new EltComparator
127 comparator
.sort
(array
)