1/* 2 * Copyright 2001-2008 Artima, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package org.scalatest.matchers 17 18import org.scalatest._ 19import org.scalatest.prop.Checkers 20import org.scalacheck._ 21import Arbitrary._ 22import Prop._ 23import Integer.{MAX_VALUE, MIN_VALUE} 24 25class ShouldOrderedSpec extends Spec with ShouldMatchers with Checkers with ReturnsNormallyThrowsAssertion { 26 27 // Checking for a specific size 28 describe("The 'be >/</>=/<= (x)' syntax") { 29 30 describe("on Int") { 31 32 it("should do nothing if the comparison holds true") { 33 check((left: Int, right: Int) => left < right ==> returnsNormally(left should be < (right))) 34 check((left: Int, right: Int) => left <= right ==> returnsNormally(left should be <= (right))) 35 check((left: Int, right: Int) => left > right ==> returnsNormally(left should be > (right))) 36 check((left: Int, right: Int) => left >= right ==> returnsNormally(left should be >= (right))) 37 } 38 39 it("should do nothing if the comparison fails and used with not") { 40 41 check((left: Int, right: Int) => left >= right ==> returnsNormally(left should not be < (right))) 42 check((left: Int, right: Int) => left > right ==> returnsNormally(left should not be <= (right))) 43 check((left: Int, right: Int) => left <= right ==> returnsNormally(left should not be > (right))) 44 check((left: Int, right: Int) => left < right ==> returnsNormally(left should not be >= (right))) 45 46 check((left: Int, right: Int) => left >= right ==> returnsNormally(left should not (be < (right)))) 47 check((left: Int, right: Int) => left > right ==> returnsNormally(left should not (be <= (right)))) 48 check((left: Int, right: Int) => left <= right ==> returnsNormally(left should not (be > (right)))) 49 check((left: Int, right: Int) => left < right ==> returnsNormally(left should not (be >= (right)))) 50 } 51 52 it("should do nothing when comparison succeeds and used in a logical-and expression") { 53 54 check((left: Int, right: Int) => ((left < right) && (right < MAX_VALUE)) ==> returnsNormally(left should ((be < (right)) and (be < (right + 1))))) 55 check((left: Int, right: Int) => ((left < right) && (right < MAX_VALUE)) ==> returnsNormally(left should (be < (right) and (be < (right + 1))))) 56 check((left: Int, right: Int) => ((left < right) && (right < MAX_VALUE)) ==> returnsNormally(left should (be < (right) and be < (right + 1)))) 57 58 check((left: Int, right: Int) => ((left <= right) && (right < MAX_VALUE)) ==> returnsNormally(left should ((be <= (right)) and (be <= (right + 1))))) 59 check((left: Int, right: Int) => ((left <= right) && (right < MAX_VALUE)) ==> returnsNormally(left should (be <= (right) and (be <= (right + 1))))) 60 check((left: Int, right: Int) => ((left <= right) && (right < MAX_VALUE)) ==> returnsNormally(left should (be <= (right) and be <= (right + 1)))) 61 62 check((left: Int, right: Int) => ((left > right) && (right > MIN_VALUE)) ==> returnsNormally(left should ((be > (right)) and (be > (right - 1))))) 63 check((left: Int, right: Int) => ((left > right) && (right > MIN_VALUE)) ==> returnsNormally(left should (be > (right) and (be > (right - 1))))) 64 check((left: Int, right: Int) => ((left > right) && (right > MIN_VALUE)) ==> returnsNormally(left should (be > (right) and be > (right - 1)))) 65 66 check((left: Int, right: Int) => ((left >= right) && (right > MIN_VALUE)) ==> returnsNormally(left should ((be >= (right)) and (be >= (right - 1))))) 67 check((left: Int, right: Int) => ((left >= right) && (right > MIN_VALUE)) ==> returnsNormally(left should (be >= (right) and (be >= (right - 1))))) 68 check((left: Int, right: Int) => ((left >= right) && (right > MIN_VALUE)) ==> returnsNormally(left should (be >= (right) and be >= (right - 1)))) 69 } 70 71 it("should do nothing when array size matches and used in a logical-or expression") { 72 73 check((left: Int, right: Int) => ((left < right) && (right < MAX_VALUE)) ==> returnsNormally(left should ((be < (right - 1)) or (be < (right + 1))))) 74 check((left: Int, right: Int) => ((left < right) && (right < MAX_VALUE)) ==> returnsNormally(left should (be < (right - 1) or (be < (right + 1))))) 75 check((left: Int, right: Int) => ((left < right) && (right < MAX_VALUE)) ==> returnsNormally(left should (be < (right - 1) or be < (right + 1)))) 76 77 check((left: Int, right: Int) => ((left <= right) && (right < MAX_VALUE)) ==> returnsNormally(left should ((be <= (right - 1)) or (be <= (right + 1))))) 78 check((left: Int, right: Int) => ((left <= right) && (right < MAX_VALUE)) ==> returnsNormally(left should (be <= (right - 1) or (be <= (right + 1))))) 79 check((left: Int, right: Int) => ((left <= right) && (right < MAX_VALUE)) ==> returnsNormally(left should (be <= (right - 1) or be <= (right + 1)))) 80 81 check((left: Int, right: Int) => ((left > right) && (right > MIN_VALUE)) ==> returnsNormally(left should ((be > (right + 1)) or (be > (right - 1))))) 82 check((left: Int, right: Int) => ((left > right) && (right > MIN_VALUE)) ==> returnsNormally(left should (be > (right + 1) or (be > (right - 1))))) 83 check((left: Int, right: Int) => ((left > right) && (right > MIN_VALUE)) ==> returnsNormally(left should (be > (right + 1) or be > (right - 1)))) 84 85 check((left: Int, right: Int) => ((left >= right) && (right > MIN_VALUE)) ==> returnsNormally(left should ((be >= (right + 1)) or (be >= (right - 1))))) 86 check((left: Int, right: Int) => ((left >= right) && (right > MIN_VALUE)) ==> returnsNormally(left should (be >= (right + 1) or (be >= (right - 1))))) 87 check((left: Int, right: Int) => ((left >= right) && (right > MIN_VALUE)) ==> returnsNormally(left should (be >= (right + 1) or be >= (right - 1)))) 88 89 check((left: Int, right: Int) => returnsNormally(left should (be >= (right) or be < (right)))) 90 check((left: Int, right: Int) => returnsNormally(left should (be > (right) or be <= (right)))) 91 } 92 93 it("should do nothing when comparison fails and used in a logical-and expression with not") { 94 95 check((left: Int, right: Int) => left > right ==> returnsNormally(left should (not (be < (right)) and not (be < (right + 1))))) 96 check((left: Int, right: Int) => left > right ==> returnsNormally(left should ((not be < (right)) and (not be < (right + 1))))) 97 check((left: Int, right: Int) => left > right ==> returnsNormally(left should (not be < (right) and not be < (right + 1)))) 98 99 check((left: Int, right: Int) => left > right ==> returnsNormally(left should (not (be <= (right)) and not (be <= (right))))) 100 check((left: Int, right: Int) => left > right ==> returnsNormally(left should ((not be <= (right)) and (not be <= (right))))) 101 check((left: Int, right: Int) => left > right ==> returnsNormally(left should (not be <= (right) and not be <= (right)))) 102 103 check((left: Int, right: Int) => left < right ==> returnsNormally(left should (not (be > (right)) and not (be > (right - 1))))) 104 check((left: Int, right: Int) => left < right ==> returnsNormally(left should ((not be > (right)) and (not be > (right - 1))))) 105 check((left: Int, right: Int) => left < right ==> returnsNormally(left should (not be > (right) and not be > (right - 1)))) 106 107 check((left: Int, right: Int) => left < right ==> returnsNormally(left should (not (be >= (right)) and not (be >= (right))))) 108 check((left: Int, right: Int) => left < right ==> returnsNormally(left should ((not be >= (right)) and (not be >= (right))))) 109 check((left: Int, right: Int) => left < right ==> returnsNormally(left should (not be >= (right) and not be >= (right)))) 110 } 111 112 it("should do nothing when comparison fails and used in a logical-or expression with not") { 113 114 check((left: Int, right: Int) => left > right ==> returnsNormally(left should (not (be >= (right)) or not (be < (right))))) 115 check((left: Int, right: Int) => left > right ==> returnsNormally(left should ((not be >= (right)) or (not be < (right))))) 116 check((left: Int, right: Int) => left > right ==> returnsNormally(left should (not be >= (right) or not be < (right)))) 117 118 check((left: Int, right: Int) => left >= right ==> returnsNormally(left should (not (be > (right)) or not (be <= (right))))) 119 check((left: Int, right: Int) => left >= right ==> returnsNormally(left should ((not be > (right)) or (not be <= (right))))) 120 check((left: Int, right: Int) => left >= right ==> returnsNormally(left should (not be > (right) or not be <= (right)))) 121 122 check((left: Int, right: Int) => left < right ==> returnsNormally(left should (not (be <= (right)) or not (be > (right))))) 123 check((left: Int, right: Int) => left < right ==> returnsNormally(left should ((not be <= (right)) or (not be > (right))))) 124 check((left: Int, right: Int) => left < right ==> returnsNormally(left should (not be <= (right) or not be > (right)))) 125 126 check((left: Int, right: Int) => left <= right ==> returnsNormally(left should (not (be < (right)) or not (be >= (right))))) 127 check((left: Int, right: Int) => left <= right ==> returnsNormally(left should ((not be < (right)) or (not be >= (right))))) 128 check((left: Int, right: Int) => left <= right ==> returnsNormally(left should (not be < (right) or not be >= (right)))) 129 } 130 131 it("should throw TestFailedException if comparison does not succeed") { 132 133 val caught1 = intercept[TestFailedException] { 134 1 should be < (1) 135 } 136 assert(caught1.getMessage === "1 was not less than 1") 137 check((left: Int, right: Int) => left >= right ==> throwsTestFailedException(left should be < (right))) 138 139 val caught2 = intercept[TestFailedException] { 140 2 should be <= (1) 141 } 142 assert(caught2.getMessage === "2 was not less than or equal to 1") 143 check((left: Int, right: Int) => left > right ==> throwsTestFailedException(left should be <= (right))) 144 145 val caught3 = intercept[TestFailedException] { 146 1 should be > (1) 147 } 148 assert(caught3.getMessage === "1 was not greater than 1") 149 check((left: Int, right: Int) => left <= right ==> throwsTestFailedException(left should be > (right))) 150 151 val caught4 = intercept[TestFailedException] { 152 1 should be >= (2) 153 } 154 assert(caught4.getMessage === "1 was not greater than or equal to 2") 155 check((left: Int, right: Int) => left < right ==> throwsTestFailedException(left should be >= (right))) 156 } 157 158 it("should throw TestFailedException if comparison succeeds but used with not") { 159 160 val caught1 = intercept[TestFailedException] { 161 1 should not be < (2) 162 } 163 assert(caught1.getMessage === "1 was less than 2") 164 check((left: Int, right: Int) => left < right ==> throwsTestFailedException(left should not be < (right))) 165 166 val caught2 = intercept[TestFailedException] { 167 1 should not be <= (1) 168 } 169 assert(caught2.getMessage === "1 was less than or equal to 1") 170 check((left: Int, right: Int) => left <= right ==> throwsTestFailedException(left should not be <= (right))) 171 172 val caught3 = intercept[TestFailedException] { 173 2 should not be > (1) 174 } 175 assert(caught3.getMessage === "2 was greater than 1") 176 check((left: Int, right: Int) => left > right ==> throwsTestFailedException(left should not be > (right))) 177 178 val caught4 = intercept[TestFailedException] { 179 1 should not be >= (1) 180 } 181 assert(caught4.getMessage === "1 was greater than or equal to 1") 182 check((left: Int, right: Int) => left >= right ==> throwsTestFailedException(left should not be >= (right))) 183 } 184 185 // Comparison with and 186 it("should throw an assertion error when less than comparison doesn't succeed and used in a logical-and expression") { 187 188 val caught1 = intercept[TestFailedException] { 189 2 should { be < (5) and (be < (2)) } 190 } 191 assert(caught1.getMessage === "2 was less than 5, but 2 was not less than 2") 192 193 val caught2 = intercept[TestFailedException] { 194 2 should ((be < (5)) and (be < (2))) 195 } 196 assert(caught2.getMessage === "2 was less than 5, but 2 was not less than 2") 197 198 val caught3 = intercept[TestFailedException] { 199 2 should (be < (5) and be < (2)) 200 } 201 assert(caught3.getMessage === "2 was less than 5, but 2 was not less than 2") 202 } 203 204 it("should throw an assertion error when greater than comparison doesn't succeed and used in a logical-and expression") { 205 206 val caught1 = intercept[TestFailedException] { 207 7 should { be > (5) and (be > (12)) } 208 } 209 assert(caught1.getMessage === "7 was greater than 5, but 7 was not greater than 12") 210 211 val caught2 = intercept[TestFailedException] { 212 7 should ((be > (5)) and (be > (12))) 213 } 214 assert(caught2.getMessage === "7 was greater than 5, but 7 was not greater than 12") 215 216 val caught3 = intercept[TestFailedException] { 217 7 should (be > (5) and be > (12)) 218 } 219 assert(caught3.getMessage === "7 was greater than 5, but 7 was not greater than 12") 220 } 221 222 it("should throw an assertion error when less than or equal to comparison doesn't succeed and used in a logical-and expression") { 223 224 val caught1 = intercept[TestFailedException] { 225 2 should { be <= (2) and (be <= (1)) } 226 } 227 assert(caught1.getMessage === "2 was less than or equal to 2, but 2 was not less than or equal to 1") 228 229 val caught2 = intercept[TestFailedException] { 230 2 should ((be <= (2)) and (be <= (1))) 231 } 232 assert(caught2.getMessage === "2 was less than or equal to 2, but 2 was not less than or equal to 1") 233 234 val caught3 = intercept[TestFailedException] { 235 2 should (be <= (2) and be <= (1)) 236 } 237 assert(caught3.getMessage === "2 was less than or equal to 2, but 2 was not less than or equal to 1") 238 } 239 240 it("should throw an assertion error when greater than or equal to comparison doesn't succeed and used in a logical-and expression") { 241 242 val caught1 = intercept[TestFailedException] { 243 7 should { be >= (7) and (be >= (8)) } 244 } 245 assert(caught1.getMessage === "7 was greater than or equal to 7, but 7 was not greater than or equal to 8") 246 247 val caught2 = intercept[TestFailedException] { 248 7 should ((be >= (7)) and (be >= (8))) 249 } 250 assert(caught2.getMessage === "7 was greater than or equal to 7, but 7 was not greater than or equal to 8") 251 252 val caught3 = intercept[TestFailedException] { 253 7 should (be >= (7) and be >= (8)) 254 } 255 assert(caught3.getMessage === "7 was greater than or equal to 7, but 7 was not greater than or equal to 8") 256 } 257 258 // Comparison with or 259 it("should throw an assertion error when less than comparison doesn't succeed and used in a logical-or expression") { 260 261 val caught1 = intercept[TestFailedException] { 262 2 should { be < (2) or (be < (1)) } 263 } 264 assert(caught1.getMessage === "2 was not less than 2, and 2 was not less than 1") 265 266 val caught2 = intercept[TestFailedException] { 267 2 should ((be < (2)) or (be < (1))) 268 } 269 assert(caught2.getMessage === "2 was not less than 2, and 2 was not less than 1") 270 271 val caught3 = intercept[TestFailedException] { 272 2 should (be < (2) or be < (1)) 273 } 274 assert(caught3.getMessage === "2 was not less than 2, and 2 was not less than 1") 275 } 276 277 it("should throw an assertion error when greater than comparison doesn't succeed and used in a logical-or expression") { 278 279 val caught1 = intercept[TestFailedException] { 280 1 should { be > (5) or (be > (12)) } 281 } 282 assert(caught1.getMessage === "1 was not greater than 5, and 1 was not greater than 12") 283 284 val caught2 = intercept[TestFailedException] { 285 1 should ((be > (5)) or (be > (12))) 286 } 287 assert(caught2.getMessage === "1 was not greater than 5, and 1 was not greater than 12") 288 289 val caught3 = intercept[TestFailedException] { 290 1 should (be > (5) or be > (12)) 291 } 292 assert(caught3.getMessage === "1 was not greater than 5, and 1 was not greater than 12") 293 } 294 295 it("should throw an assertion error when less than or equal to comparison doesn't succeed and used in a logical-or expression") { 296 297 val caught1 = intercept[TestFailedException] { 298 3 should { be <= (2) or (be <= (1)) } 299 } 300 assert(caught1.getMessage === "3 was not less than or equal to 2, and 3 was not less than or equal to 1") 301 302 val caught2 = intercept[TestFailedException] { 303 3 should ((be <= (2)) or (be <= (1))) 304 } 305 assert(caught2.getMessage === "3 was not less than or equal to 2, and 3 was not less than or equal to 1") 306 307 val caught3 = intercept[TestFailedException] { 308 3 should (be <= (2) or be <= (1)) 309 } 310 assert(caught3.getMessage === "3 was not less than or equal to 2, and 3 was not less than or equal to 1") 311 } 312 313 it("should throw an assertion error when greater than or equal to comparison doesn't succeed and used in a logical-or expression") { 314 315 val caught1 = intercept[TestFailedException] { 316 6 should { be >= (7) or (be >= (8)) } 317 } 318 assert(caught1.getMessage === "6 was not greater than or equal to 7, and 6 was not greater than or equal to 8") 319 320 val caught2 = intercept[TestFailedException] { 321 6 should ((be >= (7)) or (be >= (8))) 322 } 323 assert(caught2.getMessage === "6 was not greater than or equal to 7, and 6 was not greater than or equal to 8") 324 325 val caught3 = intercept[TestFailedException] { 326 6 should (be >= (7) or be >= (8)) 327 } 328 assert(caught3.getMessage === "6 was not greater than or equal to 7, and 6 was not greater than or equal to 8") 329 } 330 331 // Comparison with and not 332 it("should throw an assertion error when less than comparison doesn't succeed and used in a logical-and expression used with not") { 333 334 val caught1 = intercept[TestFailedException] { 335 5 should { not { be < (2) } and not { be < (6) }} 336 } 337 assert(caught1.getMessage === "5 was not less than 2, but 5 was less than 6") 338 339 val caught2 = intercept[TestFailedException] { 340 5 should ((not be < (2)) and (not be < (6))) 341 } 342 assert(caught2.getMessage === "5 was not less than 2, but 5 was less than 6") 343 344 val caught3 = intercept[TestFailedException] { 345 5 should (not be < (2) and not be < (6)) 346 } 347 assert(caught3.getMessage === "5 was not less than 2, but 5 was less than 6") 348 } 349 350 it("should throw an assertion error when greater than comparison doesn't succeed and used in a logical-and expression used with not") { 351 352 val caught1 = intercept[TestFailedException] { 353 7 should { not { be > (8) } and not (be > (6)) } 354 } 355 assert(caught1.getMessage === "7 was not greater than 8, but 7 was greater than 6") 356 357 val caught2 = intercept[TestFailedException] { 358 7 should ((not be > (8)) and (not be > (6))) 359 } 360 assert(caught2.getMessage === "7 was not greater than 8, but 7 was greater than 6") 361 362 val caught3 = intercept[TestFailedException] { 363 7 should (not be > (8) and not be > (6)) 364 } 365 assert(caught3.getMessage === "7 was not greater than 8, but 7 was greater than 6") 366 } 367 368 it("should throw an assertion error when less than or equal to comparison doesn't succeed and used in a logical-and expression used with not") { 369 370 val caught1 = intercept[TestFailedException] { 371 2 should { not { be <= (1) } and (not be <= (2)) } 372 } 373 assert(caught1.getMessage === "2 was not less than or equal to 1, but 2 was less than or equal to 2") 374 375 val caught2 = intercept[TestFailedException] { 376 2 should ((not be <= (1)) and (not be <= (2))) 377 } 378 assert(caught2.getMessage === "2 was not less than or equal to 1, but 2 was less than or equal to 2") 379 380 val caught3 = intercept[TestFailedException] { 381 2 should (not be <= (1) and not be <= (2)) 382 } 383 assert(caught3.getMessage === "2 was not less than or equal to 1, but 2 was less than or equal to 2") 384 } 385 386 it("should throw an assertion error when greater than or equal to comparison doesn't succeed and used in a logical-and expression used with not") { 387 388 val caught1 = intercept[TestFailedException] { 389 7 should { not { be >= (8) } and not (be >= (6)) } 390 } 391 assert(caught1.getMessage === "7 was not greater than or equal to 8, but 7 was greater than or equal to 6") 392 393 val caught2 = intercept[TestFailedException] { 394 7 should ((not be >= (8)) and (not be >= (6))) 395 } 396 assert(caught2.getMessage === "7 was not greater than or equal to 8, but 7 was greater than or equal to 6") 397 398 val caught3 = intercept[TestFailedException] { 399 7 should (not be >= (8) and not be >= (6)) 400 } 401 assert(caught3.getMessage === "7 was not greater than or equal to 8, but 7 was greater than or equal to 6") 402 } 403 404 // Comparison with or not 405 it("should throw an assertion error when less than comparison doesn't succeed and used in a logical-or expression used with not") { 406 407 val caught1 = intercept[TestFailedException] { 408 5 should { not { be < (7) } or not { be < (8) }} 409 } 410 assert(caught1.getMessage === "5 was less than 7, and 5 was less than 8") 411 412 val caught2 = intercept[TestFailedException] { 413 5 should ((not be < (7)) or (not be < (8))) 414 } 415 assert(caught2.getMessage === "5 was less than 7, and 5 was less than 8") 416 417 val caught3 = intercept[TestFailedException] { 418 5 should (not be < (7) or not be < (8)) 419 } 420 assert(caught3.getMessage === "5 was less than 7, and 5 was less than 8") 421 } 422 423 it("should throw an assertion error when greater than comparison doesn't succeed and used in a logical-or expression used with not") { 424 425 val caught1 = intercept[TestFailedException] { 426 7 should { not { be > (5) } or not (be > (6)) } 427 } 428 assert(caught1.getMessage === "7 was greater than 5, and 7 was greater than 6") 429 430 val caught2 = intercept[TestFailedException] { 431 7 should ((not be > (5)) or (not be > (6))) 432 } 433 assert(caught2.getMessage === "7 was greater than 5, and 7 was greater than 6") 434 435 val caught3 = intercept[TestFailedException] { 436 7 should (not be > (5) or not be > (6)) 437 } 438 assert(caught3.getMessage === "7 was greater than 5, and 7 was greater than 6") 439 } 440 441 it("should throw an assertion error when less than or equal to comparison doesn't succeed and used in a logical-or expression used with not") { 442 443 val caught1 = intercept[TestFailedException] { 444 2 should { not { be <= (3) } or (not be <= (2)) } 445 } 446 assert(caught1.getMessage === "2 was less than or equal to 3, and 2 was less than or equal to 2") 447 448 val caught2 = intercept[TestFailedException] { 449 2 should ((not be <= (3)) or (not be <= (2))) 450 } 451 assert(caught2.getMessage === "2 was less than or equal to 3, and 2 was less than or equal to 2") 452 453 val caught3 = intercept[TestFailedException] { 454 2 should (not be <= (3) or not be <= (2)) 455 } 456 assert(caught3.getMessage === "2 was less than or equal to 3, and 2 was less than or equal to 2") 457 } 458 459 it("should throw an assertion error when greater than or equal to comparison doesn't succeed and used in a logical-or expression used with not") { 460 461 val caught1 = intercept[TestFailedException] { 462 8 should { not { be >= (7) } or not (be >= (6)) } 463 } 464 assert(caught1.getMessage === "8 was greater than or equal to 7, and 8 was greater than or equal to 6") 465 466 val caught2 = intercept[TestFailedException] { 467 8 should ((not be >= (7)) or (not be >= (6))) 468 } 469 assert(caught2.getMessage === "8 was greater than or equal to 7, and 8 was greater than or equal to 6") 470 471 val caught3 = intercept[TestFailedException] { 472 8 should (not be >= (7) or not be >= (6)) 473 } 474 assert(caught3.getMessage === "8 was greater than or equal to 7, and 8 was greater than or equal to 6") 475 } 476 } 477 478 describe("on String") { 479 480 it("should do nothing if the comparison holds true") { 481 check((left: String, right: String) => left < right ==> returnsNormally(left should be < (right))) 482 check((left: String, right: String) => left <= right ==> returnsNormally(left should be <= (right))) 483 check((left: String, right: String) => left > right ==> returnsNormally(left should be > (right))) 484 check((left: String, right: String) => left >= right ==> returnsNormally(left should be >= (right))) 485 } 486 487 it("should do nothing if the comparison fails and used with not") { 488 489 check((left: String, right: String) => left >= right ==> returnsNormally(left should not be < (right))) 490 check((left: String, right: String) => left > right ==> returnsNormally(left should not be <= (right))) 491 check((left: String, right: String) => left <= right ==> returnsNormally(left should not be > (right))) 492 check((left: String, right: String) => left < right ==> returnsNormally(left should not be >= (right))) 493 494 check((left: String, right: String) => left >= right ==> returnsNormally(left should not (be < (right)))) 495 check((left: String, right: String) => left > right ==> returnsNormally(left should not (be <= (right)))) 496 check((left: String, right: String) => left <= right ==> returnsNormally(left should not (be > (right)))) 497 check((left: String, right: String) => left < right ==> returnsNormally(left should not (be >= (right)))) 498 } 499 500 it("should do nothing when comparison succeeds and used in a logical-and expression") { 501 502 check((left: String, right: String) => left < right ==> returnsNormally(left should ((be < (right)) and (be < (right))))) 503 check((left: String, right: String) => left < right ==> returnsNormally(left should (be < (right) and (be < (right))))) 504 check((left: String, right: String) => left < right ==> returnsNormally(left should (be < (right) and be < (right)))) 505 506 check((left: String, right: String) => left <= right ==> returnsNormally(left should ((be <= (right)) and (be <= (right))))) 507 check((left: String, right: String) => left <= right ==> returnsNormally(left should (be <= (right) and (be <= (right))))) 508 check((left: String, right: String) => left <= right ==> returnsNormally(left should (be <= (right) and be <= (right)))) 509 510 check((left: String, right: String) => left > right ==> returnsNormally(left should ((be > (right)) and (be > (right))))) 511 check((left: String, right: String) => left > right ==> returnsNormally(left should (be > (right) and (be > (right))))) 512 check((left: String, right: String) => left > right ==> returnsNormally(left should (be > (right) and be > (right)))) 513 514 check((left: String, right: String) => left >= right ==> returnsNormally(left should ((be >= (right)) and (be >= (right))))) 515 check((left: String, right: String) => left >= right ==> returnsNormally(left should (be >= (right) and (be >= (right))))) 516 check((left: String, right: String) => left >= right ==> returnsNormally(left should (be >= (right) and be >= (right)))) 517 } 518 519 it("should do nothing when array size matches and used in a logical-or expression") { 520 521 check((left: String, right: String) => left < right ==> returnsNormally(left should ((be < (right)) or (be < (right))))) 522 check((left: String, right: String) => left < right ==> returnsNormally(left should (be < (right) or (be < (right))))) 523 check((left: String, right: String) => left < right ==> returnsNormally(left should (be < (right) or be < (right)))) 524 525 check((left: String, right: String) => left <= right ==> returnsNormally(left should ((be <= (right)) or (be <= (right))))) 526 check((left: String, right: String) => left <= right ==> returnsNormally(left should (be <= (right) or (be <= (right))))) 527 check((left: String, right: String) => left <= right ==> returnsNormally(left should (be <= (right) or be <= (right)))) 528 529 check((left: String, right: String) => left > right ==> returnsNormally(left should ((be > (right)) or (be > (right))))) 530 check((left: String, right: String) => left > right ==> returnsNormally(left should (be > (right) or (be > (right))))) 531 check((left: String, right: String) => left > right ==> returnsNormally(left should (be > (right) or be > (right)))) 532 533 check((left: String, right: String) => left >= right ==> returnsNormally(left should ((be >= (right)) or (be >= (right))))) 534 check((left: String, right: String) => left >= right ==> returnsNormally(left should (be >= (right) or (be >= (right))))) 535 check((left: String, right: String) => left >= right ==> returnsNormally(left should (be >= (right) or be >= (right)))) 536 537 check((left: String, right: String) => returnsNormally(left should (be >= (right) or be < (right)))) 538 check((left: String, right: String) => returnsNormally(left should (be > (right) or be <= (right)))) 539 } 540 541 it("should do nothing when comparison fails and used in a logical-and expression with not") { 542 543 check((left: String, right: String) => left >= right ==> returnsNormally(left should (not (be < (right)) and not (be < (right))))) 544 check((left: String, right: String) => left >= right ==> returnsNormally(left should ((not be < (right)) and (not be < (right))))) 545 check((left: String, right: String) => left >= right ==> returnsNormally(left should (not be < (right) and not be < (right)))) 546 547 check((left: String, right: String) => left > right ==> returnsNormally(left should (not (be <= (right)) and not (be <= (right))))) 548 check((left: String, right: String) => left > right ==> returnsNormally(left should ((not be <= (right)) and (not be <= (right))))) 549 check((left: String, right: String) => left > right ==> returnsNormally(left should (not be <= (right) and not be <= (right)))) 550 551 check((left: String, right: String) => left <= right ==> returnsNormally(left should (not (be > (right)) and not (be > (right))))) 552 check((left: String, right: String) => left <= right ==> returnsNormally(left should ((not be > (right)) and (not be > (right))))) 553 check((left: String, right: String) => left <= right ==> returnsNormally(left should (not be > (right) and not be > (right)))) 554 555 check((left: String, right: String) => left < right ==> returnsNormally(left should (not (be >= (right)) and not (be >= (right))))) 556 check((left: String, right: String) => left < right ==> returnsNormally(left should ((not be >= (right)) and (not be >= (right))))) 557 check((left: String, right: String) => left < right ==> returnsNormally(left should (not be >= (right) and not be >= (right)))) 558 } 559 560 it("should do nothing when comparison fails and used in a logical-or expression with not") { 561 562 check((left: String, right: String) => left > right ==> returnsNormally(left should (not (be >= (right)) or not (be < (right))))) 563 check((left: String, right: String) => left > right ==> returnsNormally(left should ((not be >= (right)) or (not be < (right))))) 564 check((left: String, right: String) => left > right ==> returnsNormally(left should (not be >= (right) or not be < (right)))) 565 566 check((left: String, right: String) => left >= right ==> returnsNormally(left should (not (be > (right)) or not (be <= (right))))) 567 check((left: String, right: String) => left >= right ==> returnsNormally(left should ((not be > (right)) or (not be <= (right))))) 568 check((left: String, right: String) => left >= right ==> returnsNormally(left should (not be > (right) or not be <= (right)))) 569 570 check((left: String, right: String) => left < right ==> returnsNormally(left should (not (be <= (right)) or not (be > (right))))) 571 check((left: String, right: String) => left < right ==> returnsNormally(left should ((not be <= (right)) or (not be > (right))))) 572 check((left: String, right: String) => left < right ==> returnsNormally(left should (not be <= (right) or not be > (right)))) 573 574 check((left: String, right: String) => left <= right ==> returnsNormally(left should (not (be < (right)) or not (be >= (right))))) 575 check((left: String, right: String) => left <= right ==> returnsNormally(left should ((not be < (right)) or (not be >= (right))))) 576 check((left: String, right: String) => left <= right ==> returnsNormally(left should (not be < (right) or not be >= (right)))) 577 } 578 579 it("should throw TestFailedException if comparison does not succeed") { 580 581 val caught1 = intercept[TestFailedException] { 582 "aaa" should be < ("aaa") 583 } 584 assert(caught1.getMessage === "\"aaa\" was not less than \"aaa\"") 585 check((left: String, right: String) => left >= right ==> throwsTestFailedException(left should be < (right))) 586 587 val caught2 = intercept[TestFailedException] { 588 "bbb" should be <= ("aaa") 589 } 590 assert(caught2.getMessage === "\"bbb\" was not less than or equal to \"aaa\"") 591 check((left: String, right: String) => left > right ==> throwsTestFailedException(left should be <= (right))) 592 593 val caught3 = intercept[TestFailedException] { 594 "aaa" should be > ("aaa") 595 } 596 assert(caught3.getMessage === "\"aaa\" was not greater than \"aaa\"") 597 check((left: String, right: String) => left <= right ==> throwsTestFailedException(left should be > (right))) 598 599 val caught4 = intercept[TestFailedException] { 600 "aaa" should be >= ("bbb") 601 } 602 assert(caught4.getMessage === "\"aaa\" was not greater than or equal to \"bbb\"") 603 check((left: String, right: String) => left < right ==> throwsTestFailedException(left should be >= (right))) 604 } 605 606 it("should throw TestFailedException if comparison succeeds but used with not") { 607 608 val caught1 = intercept[TestFailedException] { 609 "aaa" should not be < ("bbb") 610 } 611 assert(caught1.getMessage === "\"aaa\" was less than \"bbb\"") 612 check((left: String, right: String) => left < right ==> throwsTestFailedException(left should not be < (right))) 613 614 val caught2 = intercept[TestFailedException] { 615 "aaa" should not be <= ("aaa") 616 } 617 assert(caught2.getMessage === "\"aaa\" was less than or equal to \"aaa\"") 618 check((left: String, right: String) => left <= right ==> throwsTestFailedException(left should not be <= (right))) 619 620 val caught3 = intercept[TestFailedException] { 621 "bbb" should not be > ("aaa") 622 } 623 assert(caught3.getMessage === "\"bbb\" was greater than \"aaa\"") 624 check((left: String, right: String) => left > right ==> throwsTestFailedException(left should not be > (right))) 625 626 val caught4 = intercept[TestFailedException] { 627 "aaa" should not be >= ("aaa") 628 } 629 assert(caught4.getMessage === "\"aaa\" was greater than or equal to \"aaa\"") 630 check((left: String, right: String) => left >= right ==> throwsTestFailedException(left should not be >= (right))) 631 } 632 633 // Comparison with and 634 it("should throw an assertion error when less than comparison doesn't succeed and used in a logical-and expression") { 635 636 val caught1 = intercept[TestFailedException] { 637 "2" should { be < ("5") and (be < ("2")) } 638 } 639 assert(caught1.getMessage === "\"2\" was less than \"5\", but \"2\" was not less than \"2\"") 640 641 val caught2 = intercept[TestFailedException] { 642 "2" should ((be < ("5")) and (be < ("2"))) 643 } 644 assert(caught2.getMessage === "\"2\" was less than \"5\", but \"2\" was not less than \"2\"") 645 646 val caught3 = intercept[TestFailedException] { 647 "2" should (be < ("5") and be < ("2")) 648 } 649 assert(caught3.getMessage === "\"2\" was less than \"5\", but \"2\" was not less than \"2\"") 650 } 651 652 it("should throw an assertion error when greater than comparison doesn't succeed and used in a logical-and expression") { 653 654 val caught1 = intercept[TestFailedException] { 655 "7" should { be > ("5") and (be > ("9")) } 656 } 657 assert(caught1.getMessage === "\"7\" was greater than \"5\", but \"7\" was not greater than \"9\"") 658 659 val caught2 = intercept[TestFailedException] { 660 "7" should ((be > ("5")) and (be > ("9"))) 661 } 662 assert(caught2.getMessage === "\"7\" was greater than \"5\", but \"7\" was not greater than \"9\"") 663 664 val caught3 = intercept[TestFailedException] { 665 "7" should (be > ("5") and be > ("9")) 666 } 667 assert(caught3.getMessage === "\"7\" was greater than \"5\", but \"7\" was not greater than \"9\"") 668 } 669 670 it("should throw an assertion error when less than or equal to comparison doesn't succeed and used in a logical-and expression") { 671 672 val caught1 = intercept[TestFailedException] { 673 "2" should { be <= ("2") and (be <= ("1")) } 674 } 675 assert(caught1.getMessage === "\"2\" was less than or equal to \"2\", but \"2\" was not less than or equal to \"1\"") 676 677 val caught2 = intercept[TestFailedException] { 678 "2" should ((be <= ("2")) and (be <= ("1"))) 679 } 680 assert(caught2.getMessage === "\"2\" was less than or equal to \"2\", but \"2\" was not less than or equal to \"1\"") 681 682 val caught3 = intercept[TestFailedException] { 683 "2" should (be <= ("2") and be <= ("1")) 684 } 685 assert(caught3.getMessage === "\"2\" was less than or equal to \"2\", but \"2\" was not less than or equal to \"1\"") 686 } 687 688 it("should throw an assertion error when greater than or equal to comparison doesn't succeed and used in a logical-and expression") { 689 690 val caught1 = intercept[TestFailedException] { 691 "7" should { be >= ("7") and (be >= ("8")) } 692 } 693 assert(caught1.getMessage === "\"7\" was greater than or equal to \"7\", but \"7\" was not greater than or equal to \"8\"") 694 695 val caught2 = intercept[TestFailedException] { 696 "7" should ((be >= ("7")) and (be >= ("8"))) 697 } 698 assert(caught2.getMessage === "\"7\" was greater than or equal to \"7\", but \"7\" was not greater than or equal to \"8\"") 699 700 val caught3 = intercept[TestFailedException] { 701 "7" should (be >= ("7") and be >= ("8")) 702 } 703 assert(caught3.getMessage === "\"7\" was greater than or equal to \"7\", but \"7\" was not greater than or equal to \"8\"") 704 } 705 706 // Comparison with or 707 it("should throw an assertion error when less than comparison doesn't succeed and used in a logical-or expression") { 708 709 val caught1 = intercept[TestFailedException] { 710 "2" should { be < ("2") or (be < ("1")) } 711 } 712 assert(caught1.getMessage === "\"2\" was not less than \"2\", and \"2\" was not less than \"1\"") 713 714 val caught2 = intercept[TestFailedException] { 715 "2" should ((be < ("2")) or (be < ("1"))) 716 } 717 assert(caught2.getMessage === "\"2\" was not less than \"2\", and \"2\" was not less than \"1\"") 718 719 val caught3 = intercept[TestFailedException] { 720 "2" should (be < ("2") or be < ("1")) 721 } 722 assert(caught3.getMessage === "\"2\" was not less than \"2\", and \"2\" was not less than \"1\"") 723 } 724 725 it("should throw an assertion error when greater than comparison doesn't succeed and used in a logical-or expression") { 726 727 val caught1 = intercept[TestFailedException] { 728 "1" should { be > ("5") or (be > ("9")) } 729 } 730 assert(caught1.getMessage === "\"1\" was not greater than \"5\", and \"1\" was not greater than \"9\"") 731 732 val caught2 = intercept[TestFailedException] { 733 "1" should ((be > ("5")) or (be > ("9"))) 734 } 735 assert(caught2.getMessage === "\"1\" was not greater than \"5\", and \"1\" was not greater than \"9\"") 736 737 val caught3 = intercept[TestFailedException] { 738 "1" should (be > ("5") or be > ("9")) 739 } 740 assert(caught3.getMessage === "\"1\" was not greater than \"5\", and \"1\" was not greater than \"9\"") 741 } 742 743 it("should throw an assertion error when less than or equal to comparison doesn't succeed and used in a logical-or expression") { 744 745 val caught1 = intercept[TestFailedException] { 746 "3" should { be <= ("2") or (be <= ("1")) } 747 } 748 assert(caught1.getMessage === "\"3\" was not less than or equal to \"2\", and \"3\" was not less than or equal to \"1\"") 749 750 val caught2 = intercept[TestFailedException] { 751 "3" should ((be <= ("2")) or (be <= ("1"))) 752 } 753 assert(caught2.getMessage === "\"3\" was not less than or equal to \"2\", and \"3\" was not less than or equal to \"1\"") 754 755 val caught3 = intercept[TestFailedException] { 756 "3" should (be <= ("2") or be <= ("1")) 757 } 758 assert(caught3.getMessage === "\"3\" was not less than or equal to \"2\", and \"3\" was not less than or equal to \"1\"") 759 } 760 761 it("should throw an assertion error when greater than or equal to comparison doesn't succeed and used in a logical-or expression") { 762 763 val caught1 = intercept[TestFailedException] { 764 "6" should { be >= ("7") or (be >= ("8")) } 765 } 766 assert(caught1.getMessage === "\"6\" was not greater than or equal to \"7\", and \"6\" was not greater than or equal to \"8\"") 767 768 val caught2 = intercept[TestFailedException] { 769 "6" should ((be >= ("7")) or (be >= ("8"))) 770 } 771 assert(caught2.getMessage === "\"6\" was not greater than or equal to \"7\", and \"6\" was not greater than or equal to \"8\"") 772 773 val caught3 = intercept[TestFailedException] { 774 "6" should (be >= ("7") or be >= ("8")) 775 } 776 assert(caught3.getMessage === "\"6\" was not greater than or equal to \"7\", and \"6\" was not greater than or equal to \"8\"") 777 } 778 779 // Comparison with and not 780 it("should throw an assertion error when less than comparison doesn't succeed and used in a logical-and expression used with not") { 781 782 val caught1 = intercept[TestFailedException] { 783 "5" should { not { be < ("2") } and not { be < ("6") }} 784 } 785 assert(caught1.getMessage === "\"5\" was not less than \"2\", but \"5\" was less than \"6\"") 786 787 val caught2 = intercept[TestFailedException] { 788 "5" should ((not be < ("2")) and (not be < ("6"))) 789 } 790 assert(caught2.getMessage === "\"5\" was not less than \"2\", but \"5\" was less than \"6\"") 791 792 val caught3 = intercept[TestFailedException] { 793 "5" should (not be < ("2") and not be < ("6")) 794 } 795 assert(caught3.getMessage === "\"5\" was not less than \"2\", but \"5\" was less than \"6\"") 796 } 797 798 it("should throw an assertion error when greater than comparison doesn't succeed and used in a logical-and expression used with not") { 799 800 val caught1 = intercept[TestFailedException] { 801 "7" should { not { be > ("8") } and not (be > ("6")) } 802 } 803 assert(caught1.getMessage === "\"7\" was not greater than \"8\", but \"7\" was greater than \"6\"") 804 805 val caught2 = intercept[TestFailedException] { 806 "7" should ((not be > ("8")) and (not be > ("6"))) 807 } 808 assert(caught2.getMessage === "\"7\" was not greater than \"8\", but \"7\" was greater than \"6\"") 809 810 val caught3 = intercept[TestFailedException] { 811 "7" should (not be > ("8") and not be > ("6")) 812 } 813 assert(caught3.getMessage === "\"7\" was not greater than \"8\", but \"7\" was greater than \"6\"") 814 } 815 816 it("should throw an assertion error when less than or equal to comparison doesn't succeed and used in a logical-and expression used with not") { 817 818 val caught1 = intercept[TestFailedException] { 819 "2" should { not { be <= ("1") } and (not be <= ("2")) } 820 } 821 assert(caught1.getMessage === "\"2\" was not less than or equal to \"1\", but \"2\" was less than or equal to \"2\"") 822 823 val caught2 = intercept[TestFailedException] { 824 "2" should ((not be <= ("1")) and (not be <= ("2"))) 825 } 826 assert(caught2.getMessage === "\"2\" was not less than or equal to \"1\", but \"2\" was less than or equal to \"2\"") 827 828 val caught3 = intercept[TestFailedException] { 829 "2" should (not be <= ("1") and not be <= ("2")) 830 } 831 assert(caught3.getMessage === "\"2\" was not less than or equal to \"1\", but \"2\" was less than or equal to \"2\"") 832 } 833 834 it("should throw an assertion error when greater than or equal to comparison doesn't succeed and used in a logical-and expression used with not") { 835 836 val caught1 = intercept[TestFailedException] { 837 "7" should { not { be >= ("8") } and not (be >= ("6")) } 838 } 839 assert(caught1.getMessage === "\"7\" was not greater than or equal to \"8\", but \"7\" was greater than or equal to \"6\"") 840 841 val caught2 = intercept[TestFailedException] { 842 "7" should ((not be >= ("8")) and (not be >= ("6"))) 843 } 844 assert(caught2.getMessage === "\"7\" was not greater than or equal to \"8\", but \"7\" was greater than or equal to \"6\"") 845 846 val caught3 = intercept[TestFailedException] { 847 "7" should (not be >= ("8") and not be >= ("6")) 848 } 849 assert(caught3.getMessage === "\"7\" was not greater than or equal to \"8\", but \"7\" was greater than or equal to \"6\"") 850 } 851 852 // Comparison with or not 853 it("should throw an assertion error when less than comparison doesn't succeed and used in a logical-or expression used with not") { 854 855 val caught1 = intercept[TestFailedException] { 856 "5" should { not { be < ("7") } or not { be < ("8") }} 857 } 858 assert(caught1.getMessage === "\"5\" was less than \"7\", and \"5\" was less than \"8\"") 859 860 val caught2 = intercept[TestFailedException] { 861 "5" should ((not be < ("7")) or (not be < ("8"))) 862 } 863 assert(caught2.getMessage === "\"5\" was less than \"7\", and \"5\" was less than \"8\"") 864 865 val caught3 = intercept[TestFailedException] { 866 "5" should (not be < ("7") or not be < ("8")) 867 } 868 assert(caught3.getMessage === "\"5\" was less than \"7\", and \"5\" was less than \"8\"") 869 } 870 871 it("should throw an assertion error when greater than comparison doesn't succeed and used in a logical-or expression used with not") { 872 873 val caught1 = intercept[TestFailedException] { 874 "7" should { not { be > ("5") } or not (be > ("6")) } 875 } 876 assert(caught1.getMessage === "\"7\" was greater than \"5\", and \"7\" was greater than \"6\"") 877 878 val caught2 = intercept[TestFailedException] { 879 "7" should ((not be > ("5")) or (not be > ("6"))) 880 } 881 assert(caught2.getMessage === "\"7\" was greater than \"5\", and \"7\" was greater than \"6\"") 882 883 val caught3 = intercept[TestFailedException] { 884 "7" should (not be > ("5") or not be > ("6")) 885 } 886 assert(caught3.getMessage === "\"7\" was greater than \"5\", and \"7\" was greater than \"6\"") 887 } 888 889 it("should throw an assertion error when less than or equal to comparison doesn't succeed and used in a logical-or expression used with not") { 890 891 val caught1 = intercept[TestFailedException] { 892 "2" should { not { be <= ("3") } or (not be <= ("2")) } 893 } 894 assert(caught1.getMessage === "\"2\" was less than or equal to \"3\", and \"2\" was less than or equal to \"2\"") 895 896 val caught2 = intercept[TestFailedException] { 897 "2" should ((not be <= ("3")) or (not be <= ("2"))) 898 } 899 assert(caught2.getMessage === "\"2\" was less than or equal to \"3\", and \"2\" was less than or equal to \"2\"") 900 901 val caught3 = intercept[TestFailedException] { 902 "2" should (not be <= ("3") or not be <= ("2")) 903 } 904 assert(caught3.getMessage === "\"2\" was less than or equal to \"3\", and \"2\" was less than or equal to \"2\"") 905 } 906 907 it("should throw an assertion error when greater than or equal to comparison doesn't succeed and used in a logical-or expression used with not") { 908 909 val caught1 = intercept[TestFailedException] { 910 "8" should { not { be >= ("7") } or not (be >= ("6")) } 911 } 912 assert(caught1.getMessage === "\"8\" was greater than or equal to \"7\", and \"8\" was greater than or equal to \"6\"") 913 914 val caught2 = intercept[TestFailedException] { 915 "8" should ((not be >= ("7")) or (not be >= ("6"))) 916 } 917 assert(caught2.getMessage === "\"8\" was greater than or equal to \"7\", and \"8\" was greater than or equal to \"6\"") 918 919 val caught3 = intercept[TestFailedException] { 920 "8" should (not be >= ("7") or not be >= ("6")) 921 } 922 assert(caught3.getMessage === "\"8\" was greater than or equal to \"7\", and \"8\" was greater than or equal to \"6\"") 923 } 924 } 925 } 926} 927