Skip to content

Commit c3f2ca6

Browse files
authored
Merge pull request #89 from stefanschoon/master
Integration test for UML data types
2 parents 516a3e6 + 742ed07 commit c3f2ca6

File tree

9 files changed

+47
-29
lines changed

9 files changed

+47
-29
lines changed

manual/main.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,14 @@ Data types may be added at the top of the model body.
331331
Example:
332332

333333
The example shows four different data type definitions. The data types
334-
'Rectange' and 'Circle' inherit from abstract data type 'Shape'. 'Shape'
334+
'Rectangle' and 'Circle' inherit from abstract data type 'Shape'. 'Shape'
335335
defines the attribute 'position' which is of type 'Point' in its constructor.
336336
'Point' defines the attributes 'x' and 'y' which are both of primitive type
337337
'Real'. It also defines the operation 'translate()' which takes two parameters
338-
of type 'Real'for shifting 'x' and 'y' with no result type. 'Shape' defines
339-
the two opeartions 'perimeter()' and 'area()'. Since 'Shape' is abstract both
338+
of type 'Real' for shifting 'x' and 'y' with no result type. 'Shape' defines
339+
the two operations 'perimeter()' and 'area()'. Since 'Shape' is abstract both
340340
'Rectangle' and 'Circle' implement their specific logic for these operations.
341-
Note that a constructor canonly have pre- and no postconditions, since it is a
341+
Note that a constructor can only have pre- and no postconditions, since it is a
342342
stateless operation.
343343

344344
dataType Point
@@ -369,7 +369,7 @@ stateless operation.
369369
area() : Real = 3.14 * radius * radius
370370
end
371371

372-
Following examample shows, how to query data types
372+
Following example shows, how to query data types
373373
from the above model 'Shapes' in the shell:
374374

375375
use> ?Point(1, 1)

use-core/src/main/java/org/tzi/use/uml/ocl/expr/operations/StandardOperationsNumber.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -863,17 +863,23 @@ public boolean isInfixOrPrefix() {
863863

864864
@Override
865865
public Type matches(Type params[]) {
866-
return (params.length == 1 && params[0].isTypeOfReal()) ? TypeFactory
867-
.mkReal() : null;
866+
return (params.length == 1 && params[0].isKindOfNumber(VoidHandling.EXCLUDE_VOID)) ? TypeFactory
867+
.mkInteger() : null;
868868
}
869869

870870
@Override
871871
public Value eval(EvalContext ctx, Value[] args, Type resultType) {
872-
double d1 = ((RealValue) args[0]).value();
872+
double d1;
873+
if (args[0].isInteger())
874+
d1 = ((IntegerValue) args[0]).value();
875+
else
876+
d1 = ((RealValue) args[0]).value();
873877
return new RealValue(Math.sqrt(d1));
874878
}
875879
}
876880

881+
// --------------------------------------------------------
882+
877883
/* toString : Number -> String */
878884
final class Op_number_toString extends OpGeneric {
879885
@Override

use-core/src/main/resources/examples/Others/Shapes/Shapes.use use-core/src/main/resources/examples/Documentation/Shapes/Shapes.use

-14
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@ model Shapes
33
dataType Point
44
operations
55
Point(x : Real, y : Real)
6-
pre: x > -1000 and x <= 1000
7-
pre: y > -1000 and y <= 1000
8-
96
translate(dx : Real, dy : Real)(dx) : Point =
107
Point(self.x + dx, self.y + dy)
11-
12-
--move_x(dx:Real):Point = self with {x=self.x + dx}
138
end
149

1510
abstract dataType Shape
@@ -23,27 +18,18 @@ end
2318
dataType Rectangle < Shape
2419
operations
2520
Rectangle(position : Point, width : Real, height : Real)(position)
26-
--Rectangle(x:Real, y:Real, position : Point, width : Real, height : Real)(Point(x, y))
27-
2821
perimeter() : Real = 2.0 * width + 2.0 * height
2922
area() : Real = width * height
30-
3123
contains(p : Point) : Boolean =
3224
self.position.x <= p.x and
3325
self.position.x + width >= p.x and
3426
self.position.y <= p.y and
3527
self.position.y + height >= p.y
36-
37-
--contains_raw(x : Integer, y : Integer) : Boolean =
38-
--self.contains(Point(x, y))
3928
end
4029

4130
dataType Circle < Shape
4231
operations
4332
Circle(position : Point, radius : Real)(position)
44-
4533
perimeter() : Real = 2.0 * 3.14 * radius
4634
area() : Real = 3.14 * radius * radius
47-
48-
foo(r : Real) : Real = radius + Circle(Point(0, 0), r).radius
4935
end

use-core/src/test/java/org/tzi/use/parser/USECompilerTest.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
/*
2121
// $Id: USECompilerTest.java 5574 2015-03-09 15:07:18Z fhilken $
2222
*/
23-
2423
package org.tzi.use.parser;
2524

2625
import java.io.BufferedReader;
@@ -179,11 +178,11 @@ public void testExpression() throws IOException {
179178
}
180179
continue;
181180
}
182-
if (line.length() == 0 || line.startsWith("#")) {
181+
if (line.isEmpty() || line.startsWith("#")) {
183182
continue;
184183
}
185184

186-
String expStr = line;
185+
StringBuilder expStr = new StringBuilder(line);
187186
while (true) {
188187
line = in.readLine();
189188
lineNr++;
@@ -195,15 +194,15 @@ public void testExpression() throws IOException {
195194
if (line.startsWith("-> ")) {
196195
break;
197196
}
198-
expStr += " " + line.trim();
197+
expStr.append(" ").append(line.trim());
199198
}
200199
String resultStr = line.substring(3);
201200

202201
if (VERBOSE) {
203202
System.out.println("expression: " + expStr);
204203
}
205204

206-
InputStream stream = new ByteArrayInputStream(expStr.getBytes());
205+
InputStream stream = new ByteArrayInputStream(expStr.toString().getBytes());
207206

208207
Expression expr =
209208
OCLCompiler.compileExpression(
@@ -227,8 +226,7 @@ private File getFailFileFromUseFile(String specFileName) {
227226
// check for a failure file
228227
String failFileName =
229228
specFileName.substring(0, specFileName.length() - 4) + ".fail";
230-
File failFile = new File(TEST_PATH, failFileName);
231-
return failFile;
229+
return new File(TEST_PATH, failFileName);
232230
}
233231

234232

use-gui/src/it/resources/testfiles/shell/t001.in

+12
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@
158158
? oclUndefined(Real) = oclUndefined(Integer)
159159
*-> true : Boolean
160160

161+
? 3.pow(2)
162+
*-> 9.0 : Real
163+
164+
? 3.0.pow(2)
165+
*-> 9.0 : Real
166+
167+
? 9.sqrt
168+
*-> 3.0 : Real
169+
170+
? 9.0.sqrt
171+
*-> 3.0 : Real
172+
161173
#
162174
## Operations on Booleans
163175
#

use-gui/src/it/resources/testfiles/shell/t002.in

+6
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,10 @@
135135
? Set{a1}->iterate(v; result : A = oclUndefined(A) | v)
136136
*-> a1 : A
137137

138+
? D(1, 1)
139+
*-> D{a=1, b=1} : D
140+
141+
? E(1, 1, 2)
142+
*-> E{a=1, b=1, c=2} : E
143+
138144
exit

use-gui/src/it/resources/testfiles/shell/t002.use

+10
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,13 @@ association A_B between
3030
A[*]
3131
B[0..1]
3232
end
33+
34+
dataType D
35+
operations
36+
D(a : Integer, b : Integer)
37+
end
38+
39+
dataType E < D
40+
operations
41+
E(a : Integer, b : Integer, c : Integer)(a, b)
42+
end

0 commit comments

Comments
 (0)