View Javadoc
1 /*** 2 * Redistribution and use of this software and associated documentation 3 * ("Software"), with or without modification, are permitted provided 4 * that the following conditions are met: 5 * 6 * 1. Redistributions of source code must retain copyright 7 * statements and notices. Redistributions must also contain a 8 * copy of this document. 9 * 10 * 2. Redistributions in binary form must reproduce the 11 * above copyright notice, this list of conditions and the 12 * following disclaimer in the documentation and/or other 13 * materials provided with the distribution. 14 * 15 * 3. The name "Exolab" must not be used to endorse or promote 16 * products derived from this Software without prior written 17 * permission of Exoffice Technologies. For written permission, 18 * please contact tma@netspace.net.au. 19 * 20 * 4. Products derived from this Software may not be called "Exolab" 21 * nor may "Exolab" appear in their names without prior written 22 * permission of Exoffice Technologies. Exolab is a registered 23 * trademark of Exoffice Technologies. 24 * 25 * 5. Due credit should be given to the Exolab Project 26 * (http://www.exolab.org/). 27 * 28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS 29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 39 * OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * Copyright 2003-2004 (C) Exoffice Technologies Inc. All Rights Reserved. 42 * 43 * $Id: FloatTest.java,v 1.7 2004/02/03 21:52:11 tanderson Exp $ 44 */ 45 package org.exolab.jmscts.test.selector; 46 47 import junit.framework.Test; 48 49 import java.util.HashMap; 50 51 import org.exolab.jmscts.core.TestCreator; 52 53 54 /*** 55 * This class tests selectors containing floating point literals and objects. 56 * 57 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 58 * @version $Revision: 1.7 $ 59 * @see AbstractSelectorTestCase 60 * @jmscts.message MapMessage 61 */ 62 public class FloatTest extends AbstractSelectorTestCase { 63 64 /*** 65 * Message properties 66 */ 67 private static final HashMap PROPERTIES = new HashMap(); 68 69 70 /*** 71 * Create an instance of this class for a specific test case, testing 72 * against all delivery types 73 * 74 * @param name the name of test case 75 */ 76 public FloatTest(String name) { 77 super(name); 78 } 79 80 /*** 81 * Sets up the test suite 82 * 83 * @return an instance of this class that may be run by 84 * {@link org.exolab.jmscts.core.JMSTestRunner} 85 */ 86 public static Test suite() { 87 return TestCreator.createSendReceiveTest(FloatTest.class); 88 } 89 90 /*** 91 * Verifies that the selector <code>0.0 = 0.0</code> selects all 92 * messages 93 * 94 * @jmscts.requirement selector.literal.approxnumeric 95 * @jmscts.requirement selector.expression 96 * @throws Exception for any error 97 */ 98 public void testEquals1() throws Exception { 99 checkSelector("0.0 = 0.0", true); 100 } 101 102 /*** 103 * Verifies that the selector <code>0.0 = 1.0</code> selects no 104 * messages 105 * 106 * @jmscts.requirement selector.literal.approxnumeric 107 * @jmscts.requirement selector.expression 108 * @throws Exception for any error 109 */ 110 public void testEquals2() throws Exception { 111 checkSelector("0.0 = 1.0", false); 112 } 113 114 /*** 115 * Verifies that the selector <code>0.2 = 0.2</code> selects all 116 * messages 117 * 118 * @jmscts.requirement selector.literal.approxnumeric 119 * @jmscts.requirement selector.expression 120 * @throws Exception for any error 121 */ 122 public void testEquals3() throws Exception { 123 checkSelector("0.2 = 0.2", true); 124 } 125 126 /*** 127 * Verifies that the selector <code>0.2 = 0.0</code> selects no 128 * messages 129 * 130 * @jmscts.requirement selector.literal.approxnumeric 131 * @jmscts.requirement selector.expression 132 * @throws Exception for any error 133 */ 134 public void testEquals4() throws Exception { 135 checkSelector("0.2 = 0.0", false); 136 } 137 138 /*** 139 * Verifies that the selector <code>92d = 92</code> selects all messages 140 * 141 * @jmscts.requirement selector.literal.approxnumeric 142 * @jmscts.requirement selector.expression 143 * @throws Exception for any error 144 */ 145 public void testEquals5() throws Exception { 146 checkSelector("92d = 92", true); 147 } 148 149 /*** 150 * Verifies that the selector <code>93f = 93</code> selects all messages 151 * 152 * @jmscts.requirement selector.literal.approxnumeric 153 * @jmscts.requirement selector.expression 154 * @throws Exception for any error 155 */ 156 public void testEquals6() throws Exception { 157 checkSelector("93f = 93", true); 158 } 159 160 /*** 161 * Verifies that the selector <code>1.0 <> 2.0</code> selects all 162 * messages 163 * 164 * @jmscts.requirement selector.literal.approxnumeric 165 * @jmscts.requirement selector.expression 166 * @throws Exception for any error 167 */ 168 public void testNotEquals1() throws Exception { 169 checkSelector("1.0 <> 2.0", true); 170 } 171 172 /*** 173 * Verifies that the selector <code>1.0 <> 1.0</code> selects no 174 * messages 175 * 176 * @jmscts.requirement selector.literal.approxnumeric 177 * @jmscts.requirement selector.expression 178 * @throws Exception for any error 179 */ 180 public void testNotEquals2() throws Exception { 181 checkSelector("1.0 <> 1.0", false); 182 } 183 184 /*** 185 * Verifies that the selector <code>1.0 <> 1.0</code> selects all 186 * messages 187 * 188 * @jmscts.requirement selector.literal.approxnumeric 189 * @jmscts.requirement selector.expression 190 * @throws Exception for any error 191 */ 192 public void testNotEquals3() throws Exception { 193 checkSelector("1.0 <> 1.1", true); 194 } 195 196 /*** 197 * Verifies that the selector <code>1.0 < 2.0</code> selects all 198 * messages 199 * 200 * @jmscts.requirement selector.literal.approxnumeric 201 * @jmscts.requirement selector.expression 202 * @throws Exception for any error 203 */ 204 public void testLessThan1() throws Exception { 205 checkSelector("1.0 < 2.0", true); 206 } 207 208 /*** 209 * Verifies that the selector <code>2.0 < 1.0</code> selects no 210 * messages 211 * 212 * @jmscts.requirement selector.literal.approxnumeric 213 * @jmscts.requirement selector.expression 214 * @throws Exception for any error 215 */ 216 public void testLessThan2() throws Exception { 217 checkSelector("2.0 < 1.0", false); 218 } 219 220 /*** 221 * Verifies that the selector <code>2.0 > 1.0</code> selects all 222 * messages 223 * 224 * @jmscts.requirement selector.literal.approxnumeric 225 * @jmscts.requirement selector.expression 226 * @throws Exception for any error 227 */ 228 public void testGreaterThan1() throws Exception { 229 checkSelector("2.0 > 1.0", true); 230 } 231 232 /*** 233 * Verifies that the selector <code>1.0 > 2.0</code> selects no 234 * messages 235 * 236 * @jmscts.requirement selector.literal.approxnumeric 237 * @jmscts.requirement selector.expression 238 * @throws Exception for any error 239 */ 240 public void testGreaterThan2() throws Exception { 241 checkSelector("1.0 > 2.0", false); 242 } 243 244 /*** 245 * Verifies that the selector <code>1.0 <= 2.0</code> selects all 246 * messages 247 * 248 * @jmscts.requirement selector.literal.approxnumeric 249 * @jmscts.requirement selector.expression 250 * @throws Exception for any error 251 */ 252 public void testLessEquals1() throws Exception { 253 checkSelector("1.0 <= 2.0", true); 254 } 255 256 /*** 257 * Verifies that the selector <code>2.0 <= 1.0</code> selects no 258 * messages 259 * 260 * @jmscts.requirement selector.literal.approxnumeric 261 * @jmscts.requirement selector.expression 262 * @throws Exception for any error 263 */ 264 public void testLessEquals2() throws Exception { 265 checkSelector("2.0 <= 1.0", false); 266 } 267 268 /*** 269 * Verifies that the selector <code>2.0 >= 1.0</code> selects all 270 * messages 271 * 272 * @jmscts.requirement selector.literal.approxnumeric 273 * @jmscts.requirement selector.expression 274 * @throws Exception for any error 275 */ 276 public void testGreaterEquals1() throws Exception { 277 checkSelector("2.0 >= 1.0", true); 278 } 279 280 /*** 281 * Verifies that the selector <code>1.0 >= 2.0</code> selects no 282 * messages 283 * 284 * @jmscts.requirement selector.literal.approxnumeric 285 * @jmscts.requirement selector.expression 286 * @throws Exception for any error 287 */ 288 public void testGreaterEquals2() throws Exception { 289 checkSelector("1.0 >= 2.0", false); 290 } 291 292 /*** 293 * Verifies that the selector <code>-1.0 = -1.0</code> selects all messages 294 * 295 * @jmscts.requirement selector.literal.approxnumeric 296 * @jmscts.requirement selector.expression 297 * @throws Exception for any error 298 */ 299 public void testUnaryMinus1() throws Exception { 300 checkSelector("-1.0 = -1.0", true); 301 } 302 303 /*** 304 * Verifies that the selector <code>-1.0 = 1.0</code> selects no messages 305 * 306 * @jmscts.requirement selector.literal.approxnumeric 307 * @jmscts.requirement selector.expression 308 * @throws Exception for any error 309 */ 310 public void testUnaryMinus2() throws Exception { 311 checkSelector("-1.0 = 1.0", false); 312 } 313 314 /*** 315 * Verifies that the selector <code>--1.0 = 1.0</code> selects all messages 316 * 317 * @jmscts.requirement selector.literal.approxnumeric 318 * @jmscts.requirement selector.expression 319 * @throws Exception for any error 320 */ 321 public void testUnaryMinus3() throws Exception { 322 checkSelector("--1.0 = 1.0", true); 323 } 324 325 /*** 326 * Verifies that the selector <code>rate = 0.2</code> selects 327 * all messages, when the double property 'rate' is set, with 328 * value <code>0.2</code> 329 * 330 * @jmscts.requirement selector.literal.approxnumeric 331 * @jmscts.requirement selector.expression 332 * @throws Exception for any error 333 */ 334 public void testEqualsProperty() throws Exception { 335 checkSelector("rate = 0.2", true, PROPERTIES); 336 } 337 338 /*** 339 * Verifies that the selector <code>rate <> 0.2</code> selects 340 * no messages, when the double property 'rate' is set, with 341 * value <code>0.2</code> 342 * 343 * @jmscts.requirement selector.literal.approxnumeric 344 * @jmscts.requirement selector.expression 345 * @throws Exception for any error 346 */ 347 public void testNotEqualsProperty() throws Exception { 348 checkSelector("rate <> 0.2", false, PROPERTIES); 349 } 350 351 /*** 352 * Verifies that the selector <code>dummy + 10.0 = 10.0</code> selects 353 * no messages, for the unset property 'dummy' 354 * 355 * @jmscts.requirement selector.expression 356 * @jmscts.requirement selector.values.null 357 * @throws Exception for any error 358 */ 359 public void testUnsetProperty1() throws Exception { 360 checkSelector("dummy + 10.0 = 10.0", false); 361 } 362 363 /*** 364 * Verifies that the selector <code>dummy - 10.0 = -10.0</code> selects 365 * no messages, for the unset property 'dummy' 366 * 367 * @jmscts.requirement selector.expression 368 * @jmscts.requirement selector.values.null 369 * @throws Exception for any error 370 */ 371 public void testUnsetProperty2() throws Exception { 372 checkSelector("dummy - 10.0 = -10.0", false); 373 } 374 375 /*** 376 * Verifies that the selector <code>10.0 + dummy = 10.0</code> selects 377 * no messages, for the unset property 'dummy' 378 * 379 * @jmscts.requirement selector.expression 380 * @jmscts.requirement selector.values.null 381 * @throws Exception for any error 382 */ 383 public void testUnsetProperty3() throws Exception { 384 checkSelector("10.0 + dummy = 10.0", false); 385 } 386 387 /*** 388 * Verifies that the selector <code>10.0 - dummy = 0.0</code> selects 389 * no messages, for the unset property 'dummy' 390 * 391 * @jmscts.requirement selector.expression 392 * @jmscts.requirement selector.values.null 393 * @throws Exception for any error 394 */ 395 public void testUnsetProperty4() throws Exception { 396 checkSelector("10.0 - dummy = 0.0", false); 397 } 398 399 /*** 400 * Verifies that the selector <code>dummy * 10.0 = 0.0</code> selects 401 * no messages, for the unset property 'dummy' 402 * 403 * @jmscts.requirement selector.expression 404 * @jmscts.requirement selector.values.null 405 * @throws Exception for any error 406 */ 407 public void testUnsetProperty5() throws Exception { 408 checkSelector("dummy * 10.0 = 0.0", false); 409 } 410 411 /*** 412 * Verifies that the selector <code>10.0 * dummy = 0.0</code> selects 413 * no messages, for the unset property 'dummy' 414 * 415 * @jmscts.requirement selector.expression 416 * @jmscts.requirement selector.values.null 417 * @throws Exception for any error 418 */ 419 public void testUnsetProperty6() throws Exception { 420 checkSelector("10.0 * dummy = 0.0", false); 421 } 422 423 /*** 424 * Verifies that the selector <code>dummy / 10.0 = 0.0</code> selects 425 * no messages, for the unset property 'dummy' 426 * 427 * @jmscts.requirement selector.expression 428 * @jmscts.requirement selector.values.null 429 * @throws Exception for any error 430 */ 431 public void testUnsetProperty7() throws Exception { 432 checkSelector("dummy / 10.0 = 1.0", false); 433 } 434 435 /*** 436 * Verifies that the selector <code>10.0 / dummy = 0.0</code> selects 437 * no messages, for the unset property 'dummy' 438 * 439 * @jmscts.requirement selector.expression 440 * @jmscts.requirement selector.values.null 441 * @throws Exception for any error 442 */ 443 public void testUnsetProperty8() throws Exception { 444 checkSelector("10.0 / dummy = 1.0", false); 445 } 446 447 /*** 448 * Verifies that selectors can have approximate numeric literals 449 * in the range <code>Double.MIN_VALUE..Double.MAX_VALUE</code>, 450 * using the selector 451 * <code>{min-value}={min-value} and {max-value} = {max-value}</code> 452 * where {min-value} and {max-value} are the values of Double.MIN_VALUE and 453 * Double.MAX_VALUE respectively. This should select all messages. 454 * 455 * @jmscts.requirement selector.literal.approxnumeric 456 * @jmscts.requirement selector.expression 457 * @throws Exception for any error 458 */ 459 public void testNumericRange() throws Exception { 460 checkSelector(Double.MIN_VALUE + "=" + Double.MIN_VALUE + " and " 461 + Double.MAX_VALUE + "=" + Double.MAX_VALUE, true); 462 } 463 464 /*** 465 * Verifies that the selector <code>10 / zero = 10 / zero</code> selects 466 * all messages, when the double property 'zero' is set, with 467 * value <code>0.0</code> 468 * 469 * @jmscts.requirement selector.expression 470 * @throws Exception for any error 471 */ 472 public void testDivisionByZero() throws Exception { 473 checkSelector("10.0 / zero = 10.0 / zero", true, PROPERTIES); 474 } 475 476 /*** 477 * Verifies that the selector <code>floatNaN = floatNaN</code> selects 478 * no messages, when the float property 'floatNaN' is set, with 479 * value <code>Float.NaN</code> (as NaN != NaN) 480 * 481 * @jmscts.requirement selector.expression 482 * @throws Exception for any error 483 */ 484 public void testFloatNaN1() throws Exception { 485 checkSelector("floatNaN = floatNaN", false, PROPERTIES); 486 } 487 488 /*** 489 * Verifies that the selector <code>floatNaN <> floatNaN</code> 490 * selects all messages, when the float property 'floatNaN' is set, with 491 * value <code>Float.NaN</code> 492 * 493 * @jmscts.requirement selector.expression 494 * @throws Exception for any error 495 */ 496 public void testFloatNaN2() throws Exception { 497 checkSelector("floatNaN <> floatNaN", true, PROPERTIES); 498 } 499 500 /*** 501 * Verifies that the selector <code>doubleNaN = doubleNaN</code> 502 * selects no messages, when the double property 'doubleNaN' is set, 503 * with value <code>Double.NaN</code> (as NaN != NaN) 504 * 505 * @jmscts.requirement selector.expression 506 * @throws Exception for any error 507 */ 508 public void testDoubleNaN1() throws Exception { 509 checkSelector("doubleNaN = doubleNaN", false, PROPERTIES); 510 } 511 512 /*** 513 * Verifies that the selector <code>doubleNaN <> doubleNaN</code> 514 * selects all messages, when the double property 'doubleNaN' is set, 515 * with value <code>Double.NaN</code> 516 * 517 * @jmscts.requirement selector.expression 518 * @throws Exception for any error 519 */ 520 public void testDoubleNaN2() throws Exception { 521 checkSelector("doubleNaN <> doubleNaN", true, PROPERTIES); 522 } 523 524 /*** 525 * Verifies that the selector <code>1.0</code> throws 526 * InvalidSelectorException 527 * 528 * @jmscts.requirement selector.validation 529 * @throws Exception for any error 530 */ 531 public void testInvalid1() throws Exception { 532 checkInvalidSelector("1.0"); 533 } 534 535 /*** 536 * Verifies that the selector <code>-1.0</code> throws 537 * InvalidSelectorException 538 * 539 * @jmscts.requirement selector.validation 540 * @throws Exception for any error 541 */ 542 public void testInvalid2() throws Exception { 543 checkInvalidSelector("-1.0"); 544 } 545 546 /*** 547 * Verifies that the selector <code>2.0 < '3.0'</code> throws 548 * InvalidSelectorException 549 * 550 * @jmscts.requirement selector.validation 551 * @throws Exception for any error 552 */ 553 public void testInvalid3() throws Exception { 554 checkInvalidSelector("2.0 < '3.0'"); 555 } 556 557 /*** 558 * Verifies that the selector <code>1.0 <> false</code> throws 559 * InvalidSelectorException 560 * 561 * @jmscts.requirement selector.validation 562 * @throws Exception for any error 563 */ 564 public void testInvalid4() throws Exception { 565 checkInvalidSelector("1.0 <> false"); 566 } 567 568 /*** 569 * Verifies that the selector <code>1a.0 = 1a.0</code> throws 570 * InvalidSelectorException 571 * 572 * @jmscts.requirement selector.validation 573 * @throws Exception for any error 574 */ 575 public void testInvalid5() throws Exception { 576 checkInvalidSelector("1a.0 = 1a.0"); 577 } 578 579 static { 580 final double rate = 0.2; 581 PROPERTIES.put("rate", new Double(rate)); 582 PROPERTIES.put("zero", new Double(0.0)); 583 PROPERTIES.put("floatNaN", new Float(Float.NaN)); 584 PROPERTIES.put("doubleNaN", new Double(Double.NaN)); 585 } 586 587 }

This page was automatically generated by Maven