summaryrefslogtreecommitdiffstats
path: root/java/rasj/test/TestRasPoint.java
blob: 6402bf0c90ff92bf103b01a97acbbe6b1dc5cf3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
*/
/** ***********************************************************
 * <pre>
 *
 * PURPOSE:
 * test rasj class RasPoint.
 *
 *
 * COMMENTS:
 * - testing philosophy is to run all tests and report. no exit code / exception
 *   is used for error indication; look into the output for ERROR_TAG instead.
 * - unexpected exceptions are not caught, hence will make gmake fail and show the error
 * - every test that fails must print a line containing ERROR_TAG
 * </pre>
 *********************************************************** */

import java.util.StringTokenizer;
import java.lang.Integer;
import java.lang.Long;
import rasj.*;
import rasj.odmg.*;

public class TestRasPoint
  {
    /**
    * constants used in this test
    **/
    // prefixes for test output
    static final String PREFIX_PROGRAM  = "+++ +++ +++ ";
    static final String PREFIX_TESTSET  = "+++ +++ ";
    static final String PREFIX_TESTCASE = "+++ ";

    static final int COORD_1 = 11;
    static final int COORD_2 = 22;
    static final int COORD_3 = 33;
    static final int COORD_4 = 44;
    static final int COORD_5 = 55;

    /**
    * std error tag printed if a test fails
    **/
    static final String ERROR_TAG = "ERROR: ";

    /**
    * main program for testing
    * on error, an exception is thrown (java main() knows no exit status)
    **/
    public static void main(String argv[]) throws Exception
      {
        System.out.println( "rasdaman system test v5.1revC: testing class RasPoint." );
        System.out.println( PREFIX_PROGRAM + "system test started." );

        // -- START test cases -------------------------------------------------
        testConstructor();
        // testcomparedWith();
        // testEquals();
        // testStream();
        // testSetItem();
        // testSetTo();
        testAdd();
        // testmult();
        // -- END test cases ---------------------------------------------------

        System.out.println( PREFIX_PROGRAM + "system test done." );
        return;
      }

    /**
    * test the RasPoint class constructor
    * any eventual exception that is not caught here is an error, and will cause an abort
    **/
    static void testConstructor() throws RasDimensionMismatchException, RasIndexOutOfBoundsException
      {
        System.out.println( PREFIX_TESTSET + "testing constructor started." );

        // default constructor
        System.out.print( PREFIX_TESTCASE + "default constructor..." );
        RasPoint p_default = new RasPoint();
        if (p_default == null)
            System.out.println( ERROR_TAG + "result is null." );
        else if (! p_default.equals( p_default ) )
            System.out.println( ERROR_TAG + "point notEqual to itself." );
        else
            System.out.println( "OK, result=" + p_default + ", dimension is " + p_default.dimension() );

        // stream constructor
        // ------------------

        System.out.print( PREFIX_TESTCASE + "stream constructor, illegal dimension -1..." );
        try
          {
            RasPoint p_stream_m1 = new RasPoint( -1 );
            if (p_stream_m1 != null)
                System.out.println( ERROR_TAG + "result is not null." );
            else
                System.out.println( "OK." );
          }
        catch(NegativeArraySizeException e)
          {
            System.out.println( "OK: " + e.getMessage() );
          }

        System.out.print( PREFIX_TESTCASE + "stream constructor, dimension 0..." );
        RasPoint p_stream_0 = new RasPoint( 0 );
        if (p_stream_0.dimension() != 0)
            System.out.println( ERROR_TAG + "wrong dimension." );
        else
            System.out.println( "OK." );

        // --- easy-to-use constructor -------------------------------------------------------

        // 2-D constructor
        System.out.print( PREFIX_TESTCASE + "2D easy to use constructor..." );
        RasPoint p_2d_easy = new RasPoint( COORD_1, COORD_2 );
        if (p_2d_easy == null)
            System.out.println( ERROR_TAG + "result is null." );
        else if (p_2d_easy.dimension() != 2)
            System.out.println( ERROR_TAG + "dimension is not 2 but " + p_2d_easy.dimension() );
        else if (p_2d_easy.item(0) != COORD_1)
            System.out.println( ERROR_TAG + "item(0) returns wrong component " + p_2d_easy.item(0) );
        else if (p_2d_easy.item(1) != COORD_2)
            System.out.println( ERROR_TAG + "item(1) returns wrong component " + p_2d_easy.item(0) );
        else if (! p_2d_easy.equals( p_2d_easy ) )
            System.out.println( ERROR_TAG + "point not equal to itself." );
        else if ( p_2d_easy.notEquals( p_2d_easy ) )
            System.out.println( ERROR_TAG + "point notEqual to itself." );
        else
            System.out.println( "OK, result=" + p_2d_easy );

        // 3-D constructor
        System.out.print( PREFIX_TESTCASE + "3D easy to use constructor..." );
        RasPoint p_3d_easy= new RasPoint( COORD_1, COORD_2, COORD_3 );
        if (p_3d_easy== null)
            System.out.println( ERROR_TAG + "result is null." );
        else if (p_3d_easy.dimension() != 3)
            System.out.println( ERROR_TAG + "dimension is not 3 but " + p_3d_easy.dimension() );
        else if (p_3d_easy.item(2) != COORD_3)
            System.out.println( ERROR_TAG + "item(2) returns wrong component " + p_3d_easy.item(0) );
        else if (! p_3d_easy.equals( p_3d_easy) )
            System.out.println( ERROR_TAG + "point not equal to itself." );
        else if ( p_3d_easy.notEquals( p_3d_easy) )
            System.out.println( ERROR_TAG + "point notEqual to itself." );
        else
            System.out.println( "OK, result=" + p_3d_easy);

        // 4-D constructor
        System.out.print( PREFIX_TESTCASE + "4D easy to use constructor..." );
        RasPoint p_4d_easy = new RasPoint( COORD_1, COORD_2, COORD_3, COORD_4 );
        if (p_4d_easy == null)
            System.out.println( ERROR_TAG + "result is null." );
        else if (p_4d_easy.dimension() != 4)
            System.out.println( ERROR_TAG + "dimension is not 4 but " + p_4d_easy.dimension() );
        else if (p_4d_easy.item(3) != COORD_4)
            System.out.println( ERROR_TAG + "item(3) returns wrong component " + p_4d_easy.item(0) );
        else if (! p_4d_easy.equals( p_4d_easy ) )
            System.out.println( ERROR_TAG + "point not equal to itself." );
        else if ( p_4d_easy.notEquals( p_4d_easy ) )
            System.out.println( ERROR_TAG + "point notEqual to itself." );
        else
            System.out.println( "OK, result=" + p_4d_easy );

        // 5-D constructor
        System.out.print( PREFIX_TESTCASE + "5D easy to use constructor..." );
        RasPoint p_5d_easy = new RasPoint( COORD_1, COORD_2, COORD_3, COORD_4, COORD_5 );
        if (p_5d_easy == null)
            System.out.println( ERROR_TAG + "result is null." );
        else if (p_5d_easy.dimension() != 5)
            System.out.println( ERROR_TAG + "dimension is not 5 but " + p_5d_easy.dimension() );
        else if (p_5d_easy.item(4) != COORD_5)
            System.out.println( ERROR_TAG + "item(4) returns wrong component " + p_5d_easy.item(0) );
        else if (! p_5d_easy.equals( p_5d_easy ) )
            System.out.println( ERROR_TAG + "point not equal to itself." );
        else if ( p_5d_easy.notEquals( p_5d_easy ) )
            System.out.println( ERROR_TAG + "point notEqual to itself." );
        else
            System.out.println( "OK, result=" + p_5d_easy );

        // --- string constructor -------------------------------------------------------

        // illegal string format
        // FIXME: bug PB4
        System.out.println( ERROR_TAG + "PB4: string constructor, illegal string formats." );

        // System.out.print( PREFIX_TESTCASE + "string constructor, illegal string format (no [)..." );
        // RasPoint p_si = new RasPoint( COORD_1 + "," + COORD_2 + "]" );
        // System.out.println( "point is: " + p_si );
        // if (! p_si.equals( new RasPoint( "[" +  COORD_1 + "," + COORD_2 + "]" ) ) )
            // System.out.println( ERROR_TAG + "wrong point value." );

        // System.out.print( PREFIX_TESTCASE + "string constructor, illegal string format (no ])..." );
        // p_si = new RasPoint( "[" + COORD_1 + "," + COORD_2 );
        // System.out.println( "point is: " + p_si );
        // if (! p_si.equals( new RasPoint( "[" +  COORD_1 + "," + COORD_2 + "]" ) ) )
            // System.out.println( ERROR_TAG + "wrong point value." );

        // System.out.print( PREFIX_TESTCASE + "string constructor, illegal string format (no ,)..." );
        // p_si = new RasPoint( "[" + COORD_1 + " " + COORD_2 + "]" );
        // System.out.println( "point is: " + p_si );
        // if (! p_si.equals( new RasPoint( "[" + COORD_1 + "," + COORD_2 + "]" ) ) )
            // System.out.println( ERROR_TAG + "wrong point value." );

        // System.out.print( PREFIX_TESTCASE + "string constructor, illegal string format (bad int)..." );
        // p_si = new RasPoint( "[" + "abc" + "," + "xyz" + "]" );
        // System.out.println( "point is: " + p_si );
        // if (! p_si.equals( p_si ) )
            // System.out.println( ERROR_TAG + "point not equal to itself." );

        // System.out.print( PREFIX_TESTCASE + "string constructor, illegal string format (missing int)..." );
        // p_si = new RasPoint( "[" + "," + "]" );
        // System.out.println( "point is: " + p_si );
        // if (! p_si.equals( p_si ) )
            // System.out.println( ERROR_TAG + "point not equal to itself." );

        // 2-D constructor
        System.out.print( PREFIX_TESTCASE + "2D string constructor..." );
        RasPoint p_2d = new RasPoint( "[" + COORD_1 + "," + COORD_2 + "]" );
        if (p_2d == null)
            System.out.println( ERROR_TAG + "result is null." );
        else if (p_2d.dimension() != 2)
            System.out.println( ERROR_TAG + "dimension is not 2 but " + p_2d.dimension() );
        else if (p_2d.item(0) != COORD_1)
            System.out.println( ERROR_TAG + "item(0) returns wrong component " + p_2d.item(0) );
        else if (p_2d.item(1) != COORD_2)
            System.out.println( ERROR_TAG + "item(1) returns wrong component " + p_2d.item(0) );
        else if (! p_2d.equals( p_2d ) )
            System.out.println( ERROR_TAG + "point not equal to itself." );
        else if ( p_2d.notEquals( p_2d ) )
            System.out.println( ERROR_TAG + "point notEqual to itself." );
        else
            System.out.println( "OK, result=" + p_2d );

        // 3-D constructor
        System.out.print( PREFIX_TESTCASE + "3D string constructor..." );
        RasPoint p_3d = new RasPoint( "[" + COORD_1 + "," + COORD_2 + "," + COORD_3 + "]" );
        if (p_3d == null)
            System.out.println( ERROR_TAG + "result is null." );
        else if (p_3d.dimension() != 3)
            System.out.println( ERROR_TAG + "dimension is not 3 but " + p_3d.dimension() );
        else if (p_3d.item(2) != COORD_3)
            System.out.println( ERROR_TAG + "item(2) returns wrong component " + p_3d.item(0) );
        else if (! p_3d.equals( p_3d ) )
            System.out.println( ERROR_TAG + "point not equal to itself." );
        else if ( p_3d.notEquals( p_3d ) )
            System.out.println( ERROR_TAG + "point notEqual to itself." );
        else
            System.out.println( "OK, result=" + p_3d );

        // 4-D constructor
        System.out.print( PREFIX_TESTCASE + "4D string constructor..." );
        RasPoint p_4d = new RasPoint( "[" + COORD_1 + "," + COORD_2 + "," + COORD_3 + "," + COORD_4 + "]" );
        if (p_4d == null)
            System.out.println( ERROR_TAG + "result is null." );
        else if (p_4d.dimension() != 4)
            System.out.println( ERROR_TAG + "dimension is not 4 but " + p_4d.dimension() );
        else if (p_4d.item(3) != COORD_4)
            System.out.println( ERROR_TAG + "item(3) returns wrong component " + p_4d.item(0) );
        else if (! p_4d.equals( p_4d ) )
            System.out.println( ERROR_TAG + "point not equal to itself." );
        else if ( p_4d.notEquals( p_4d ) )
            System.out.println( ERROR_TAG + "point notEqual to itself." );
        else
            System.out.println( "OK, result=" + p_4d );

        // 5-D constructor
        System.out.print( PREFIX_TESTCASE + "5D string constructor..." );
        RasPoint p_5d = new RasPoint( "[" + COORD_1 + "," + COORD_2 + "," + COORD_3 + "," + COORD_4 + "," + COORD_5 + "]" );
        if (p_5d == null)
            System.out.println( ERROR_TAG + "result is null." );
        else if (p_5d.dimension() != 5)
            System.out.println( ERROR_TAG + "dimension is not 5 but " + p_5d.dimension() );
        else if (p_5d.item(4) != COORD_5)
            System.out.println( ERROR_TAG + "item(4) returns wrong component " + p_5d.item(0) );
        else if (! p_5d.equals( p_5d ) )
            System.out.println( ERROR_TAG + "point not equal to itself." );
        else if ( p_5d.notEquals( p_5d ) )
            System.out.println( ERROR_TAG + "point notEqual to itself." );
        else
            System.out.println( "OK, result=" + p_5d );

        // copy constructor
        System.out.print( PREFIX_TESTCASE + "copy constructor..." );
        RasPoint p_cp = new RasPoint( p_2d );
        if (p_cp == null)
            System.out.println( ERROR_TAG + "result is null." );
        else if (p_cp.dimension() != p_2d.dimension())
            System.out.println( ERROR_TAG + "dimension mismatch." );
        else if (p_cp.item(0) != p_2d.item(0))
            System.out.println( ERROR_TAG + "item(0) returns wrong component " + p_cp.item(0) );
        else if (p_cp.item(1) != p_2d.item(1))
            System.out.println( ERROR_TAG + "item(1) returns wrong component " + p_cp.item(1) );
        else if (! p_cp.equals( p_2d ) )
            System.out.println( ERROR_TAG + "point not equal to origin." );
        else if ( p_cp.notEquals( p_2d ) )
            System.out.println( ERROR_TAG + "point notEqual to origin." );
        else
            System.out.println( "OK, result=" + p_cp );

        System.out.println( PREFIX_TESTSET + "testing constructor done.\n" );
        return;
      } // testConstructor()

    /**
    * test Point addition -- TO BE DONE
    * any eventual exception that is not caught here is an error, and will cause an abort
    **/
    static void testAdd() throws RasDimensionMismatchException, RasIndexOutOfBoundsException, RasStreamInputOverflowException
      {
        System.out.println( PREFIX_TESTSET + "testing add started." );

          RasPoint p1 = new RasPoint(COORD_3,COORD_4);
          RasPoint p2 = new RasPoint(COORD_3,COORD_4);
          p2 = p2.add(p2);

          // test if two points are equal
          boolean b1 = false;
          if(p2.comparedWith(p1) == 0)
            b1 = p1.equals(p2);
          else
            b1 = false;
          System.out.println("points are equal: " + b1);

          // get the dimension of a Point
          int i;
          b1 = false;
          if((p1.dimension() == 2) && (2 == p2.dimension()))
            b1 = true;
          System.out.println("dimensions of points are correct: " + b1);

          b1 = false;
          p2.setItem(1, 48);
          if(p2.item(1) == 48)
            b1 = true;
          System.out.println("read and write access of points is OK: " + b1);

          b1 = false;
          p2.setTo(p2.mult(p1));
          if(p2.equals(new RasPoint(443556, 42624)))
            b1 = true;
          System.out.println("mult and setTo is OK: " + b1);

          b1 = false;
          RasPoint ps = new RasPoint( 3 );
          ps.stream( 42 );
          if(ps.item(0) == 42)
            b1 = true;
          System.out.println("stream initializing of points is OK: " + b1);

        System.out.println( PREFIX_TESTSET + "testing add done.\n" );
        return;
      } // testAdd()

  } // TestRasPoint