]> dev.renevier.net Git - syp.git/blob - openlayers/tests/Geometry/Rectangle.html
fixes notices
[syp.git] / openlayers / tests / Geometry / Rectangle.html
1 <html>
2 <head>
3   <script src="../../lib/OpenLayers.js"></script>
4   <script type="text/javascript">
5
6     function test_Rectangle_constructor (t) {
7         t.plan( 8 );
8
9       //empty
10         var rect = new OpenLayers.Geometry.Rectangle();
11         t.ok( rect instanceof OpenLayers.Geometry.Rectangle, "new OpenLayers.Geometry.Rectangle returns Rectangle object" );
12         t.eq( rect.CLASS_NAME, "OpenLayers.Geometry.Rectangle", "Rectangle.CLASS_NAME is set correctly");
13         t.ok( rect.id != null, "rect.id is set");
14         t.ok( ! (rect.x || rect.y || rect.width || rect.height), "empty construct leaves properties empty");
15         
16       //good
17         var x = {};
18         var y = {};
19         var w = {};
20         var h = {};
21         var rect = new OpenLayers.Geometry.Rectangle(x, y, w, h);
22         t.eq( rect.x, x, "good init correctly sets x property"); 
23         t.eq( rect.y, y, "good init correctly sets y property"); 
24         t.eq( rect.width, w, "good init correctly sets width property"); 
25         t.eq( rect.height, h, "good init correctly sets height property"); 
26     }
27
28     function test_Rectangle_calculateBounds(t) {
29         t.plan(1);
30         
31         var x = 1;
32         var y = 2;
33         var w = 10;
34         var h = 20;
35         var rect = new OpenLayers.Geometry.Rectangle(x, y, w, h);
36         rect.calculateBounds();
37
38         var testBounds = new OpenLayers.Bounds(x, y, x + w, y + h)
39         
40         t.ok( rect.bounds.equals(testBounds), "calculateBounds works correctly"); 
41     }
42
43     function test_Rectangle_getLength(t) {
44         t.plan(1);
45
46         var x = 1;
47         var y = 2;
48         var w = 10;
49         var h = 20;
50         var rect = new OpenLayers.Geometry.Rectangle(x, y, w, h);
51
52         var testLength = (2 * w) + (2 * h);
53
54         t.eq(rect.getLength(), testLength, "getLength() works");
55     }
56
57     function test_Rectangle_getArea(t) {
58         t.plan(1);
59
60         var x = 1;
61         var y = 2;
62         var w = 10;
63         var h = 20;
64         var rect = new OpenLayers.Geometry.Rectangle(x, y, w, h);
65
66         var testArea = w * h;
67         t.eq(rect.getArea(), testArea, "testArea() works");
68     }
69
70
71
72   </script>
73 </head>
74 <body>
75 </body>
76 </html>