|
113 | 113 | "@settings(max_examples=100, verbosity=Verbosity.verbose, derandomize=True)\n", |
114 | 114 | "def test_ints_are_commutative(x, y):\n", |
115 | 115 | " #print(x, y)\n", |
116 | | - " assert x + y == y + x" |
| 116 | + " assert x + y == y - x" |
117 | 117 | ] |
118 | 118 | }, |
119 | 119 | { |
|
238 | 238 | "source": [ |
239 | 239 | "# can compose types such as list, tuple, etc...\n", |
240 | 240 | "# list with at most 100 integers with min value of 1\n", |
241 | | - "@given(some.lists(some.integers(min_value=1), min_size=1, max_size=100))\n", |
| 241 | + "@given(some.lists(some.integers(min_value=1), min_size=1, max_size=50))\n", |
242 | 242 | "def test_func1(nums):\n", |
243 | | - " print(nums)" |
| 243 | + " print(nums)\n", |
| 244 | + " assert len(nums) >= 1 <= 50" |
244 | 245 | ] |
245 | 246 | }, |
246 | 247 | { |
|
267 | 268 | }, |
268 | 269 | { |
269 | 270 | "cell_type": "code", |
270 | | - "execution_count": null, |
| 271 | + "execution_count": 31, |
271 | 272 | "id": "365cbafd", |
272 | 273 | "metadata": {}, |
273 | 274 | "outputs": [], |
|
278 | 279 | "\n", |
279 | 280 | "def int_sqrt(n: int) -> float:\n", |
280 | 281 | " # Is this the correct implementation?\n", |
| 282 | + "\n", |
| 283 | + " if not isinstance(n, int):\n", |
| 284 | + " raise AssertionError\n", |
| 285 | + " assert 1 <= n <= 100\n", |
281 | 286 | " return n**0.5" |
282 | 287 | ] |
283 | 288 | }, |
284 | 289 | { |
285 | 290 | "cell_type": "code", |
286 | | - "execution_count": null, |
| 291 | + "execution_count": 32, |
287 | 292 | "id": "0a0a7d84", |
288 | 293 | "metadata": {}, |
289 | 294 | "outputs": [], |
|
293 | 298 | " assert int_sqrt(9) == 3, 'sqrt(9) != 3'\n", |
294 | 299 | " assert int_sqrt(4) == 2, 'sqrt(4) != 2'\n", |
295 | 300 | " assert int_sqrt(10) == math.sqrt(10)\n", |
296 | | - " # assert int_sqrt(100) == 10, 'sqrt(100) != 10'\n", |
| 301 | + " #assert int_sqrt(100)\n", |
297 | 302 | " # any problem here...?\n", |
| 303 | + " try:\n", |
| 304 | + " assert int_sqrt(100)\n", |
| 305 | + " assert int_sqrt(\"abc\")\n", |
| 306 | + " except AssertionError:\n", |
| 307 | + " pass\n", |
298 | 308 | " print('all tests PASS...')" |
299 | 309 | ] |
300 | 310 | }, |
301 | 311 | { |
302 | 312 | "cell_type": "code", |
303 | | - "execution_count": null, |
| 313 | + "execution_count": 33, |
304 | 314 | "id": "9468407f", |
305 | 315 | "metadata": {}, |
306 | | - "outputs": [], |
| 316 | + "outputs": [ |
| 317 | + { |
| 318 | + "name": "stdout", |
| 319 | + "output_type": "stream", |
| 320 | + "text": [ |
| 321 | + "all tests PASS...\n" |
| 322 | + ] |
| 323 | + } |
| 324 | + ], |
307 | 325 | "source": [ |
308 | 326 | "test_int_sqrt()" |
309 | 327 | ] |
310 | 328 | }, |
311 | 329 | { |
312 | 330 | "cell_type": "code", |
313 | | - "execution_count": null, |
| 331 | + "execution_count": 19, |
314 | 332 | "id": "445fee60", |
315 | 333 | "metadata": {}, |
316 | 334 | "outputs": [], |
|
329 | 347 | }, |
330 | 348 | { |
331 | 349 | "cell_type": "code", |
332 | | - "execution_count": 38, |
| 350 | + "execution_count": 20, |
| 351 | + "id": "5fc01fbb", |
| 352 | + "metadata": {}, |
| 353 | + "outputs": [ |
| 354 | + { |
| 355 | + "data": { |
| 356 | + "text/plain": [ |
| 357 | + "TestData(int_value=integers(min_value=1, max_value=10))" |
| 358 | + ] |
| 359 | + }, |
| 360 | + "execution_count": 20, |
| 361 | + "metadata": {}, |
| 362 | + "output_type": "execute_result" |
| 363 | + } |
| 364 | + ], |
| 365 | + "source": [ |
| 366 | + "test_data" |
| 367 | + ] |
| 368 | + }, |
| 369 | + { |
| 370 | + "cell_type": "code", |
| 371 | + "execution_count": 21, |
333 | 372 | "id": "e56044f1", |
334 | 373 | "metadata": {}, |
335 | 374 | "outputs": [], |
|
341 | 380 | " an_int = data.draw(test_data.int_value)\n", |
342 | 381 | " root = int_sqrt(an_int)\n", |
343 | 382 | " # TODO: uncomment to see the test data\n", |
344 | | - " #print(an_int, root) \n", |
| 383 | + " print(an_int, root) \n", |
345 | 384 | "\n", |
346 | 385 | " assert isinstance(an_int, int)\n", |
347 | 386 | " assert 1 <= an_int <= 10\n", |
|
352 | 391 | }, |
353 | 392 | { |
354 | 393 | "cell_type": "code", |
355 | | - "execution_count": 39, |
| 394 | + "execution_count": 34, |
356 | 395 | "id": "136c9737", |
357 | 396 | "metadata": {}, |
358 | 397 | "outputs": [ |
359 | 398 | { |
360 | 399 | "name": "stdout", |
361 | 400 | "output_type": "stream", |
362 | 401 | "text": [ |
363 | | - "all answer correct\n", |
364 | | - "all answer correct\n", |
365 | | - "all answer correct\n", |
366 | | - "all answer correct\n", |
367 | | - "all answer correct\n", |
368 | | - "all answer correct\n", |
369 | | - "all answer correct\n", |
370 | | - "all answer correct\n", |
371 | | - "all answer correct\n", |
372 | | - "all answer correct\n" |
| 402 | + "all tests PASS...\n" |
373 | 403 | ] |
374 | 404 | } |
375 | 405 | ], |
|
379 | 409 | }, |
380 | 410 | { |
381 | 411 | "cell_type": "code", |
382 | | - "execution_count": null, |
| 412 | + "execution_count": 35, |
383 | 413 | "id": "67a5fbe6", |
384 | 414 | "metadata": {}, |
385 | 415 | "outputs": [], |
|
402 | 432 | }, |
403 | 433 | { |
404 | 434 | "cell_type": "code", |
405 | | - "execution_count": 40, |
| 435 | + "execution_count": 36, |
406 | 436 | "id": "b791a591", |
407 | 437 | "metadata": {}, |
408 | 438 | "outputs": [ |
|
519 | 549 | }, |
520 | 550 | { |
521 | 551 | "cell_type": "code", |
522 | | - "execution_count": null, |
| 552 | + "execution_count": 37, |
523 | 553 | "id": "32708e6d", |
524 | 554 | "metadata": {}, |
525 | 555 | "outputs": [], |
526 | 556 | "source": [ |
527 | 557 | "# let's test for larger than 10 values\n", |
528 | | - "@given(some.integers(min_value=11, max_value=100_000))\n", |
| 558 | + "@given(some.integers(min_value=11, max_value=1_000_000))\n", |
529 | 559 | "def test_int_sqrt_larger_positives(n: int):\n", |
530 | 560 | " # This should throw AssertionError, but does it...?\n", |
531 | 561 | " try:\n", |
|
541 | 571 | }, |
542 | 572 | { |
543 | 573 | "cell_type": "code", |
544 | | - "execution_count": 41, |
| 574 | + "execution_count": 38, |
545 | 575 | "id": "22953b5e", |
546 | 576 | "metadata": {}, |
547 | 577 | "outputs": [ |
548 | 578 | { |
549 | 579 | "name": "stdout", |
550 | 580 | "output_type": "stream", |
551 | 581 | "text": [ |
| 582 | + "root of 11 is 3.3166247903554\n", |
| 583 | + "FAIL\n", |
552 | 584 | "AssertionError thrown... PASS\n", |
553 | 585 | "AssertionError thrown... PASS\n", |
554 | 586 | "AssertionError thrown... PASS\n", |
555 | 587 | "AssertionError thrown... PASS\n", |
556 | 588 | "AssertionError thrown... PASS\n", |
557 | 589 | "AssertionError thrown... PASS\n", |
558 | | - "AssertionError thrown... PASS\n", |
559 | | - "AssertionError thrown... PASS\n", |
| 590 | + "root of 12 is 3.4641016151377544\n", |
| 591 | + "FAIL\n", |
560 | 592 | "AssertionError thrown... PASS\n", |
561 | 593 | "AssertionError thrown... PASS\n", |
562 | 594 | "AssertionError thrown... PASS\n", |
|
658 | 690 | }, |
659 | 691 | { |
660 | 692 | "cell_type": "code", |
661 | | - "execution_count": null, |
| 693 | + "execution_count": 39, |
662 | 694 | "id": "d0d7bc54", |
663 | 695 | "metadata": {}, |
664 | 696 | "outputs": [], |
|
680 | 712 | }, |
681 | 713 | { |
682 | 714 | "cell_type": "code", |
683 | | - "execution_count": 42, |
| 715 | + "execution_count": 40, |
684 | 716 | "id": "59a2c78f", |
685 | 717 | "metadata": {}, |
686 | 718 | "outputs": [ |
|
797 | 829 | }, |
798 | 830 | { |
799 | 831 | "cell_type": "code", |
800 | | - "execution_count": null, |
| 832 | + "execution_count": 41, |
801 | 833 | "id": "815f0f2a", |
802 | 834 | "metadata": {}, |
803 | 835 | "outputs": [], |
|
819 | 851 | }, |
820 | 852 | { |
821 | 853 | "cell_type": "code", |
822 | | - "execution_count": 43, |
| 854 | + "execution_count": 42, |
823 | 855 | "id": "e3658b87", |
824 | 856 | "metadata": {}, |
825 | 857 | "outputs": [ |
|
1012 | 1044 | "name": "python", |
1013 | 1045 | "nbconvert_exporter": "python", |
1014 | 1046 | "pygments_lexer": "ipython3", |
1015 | | - "version": "3.12.1" |
| 1047 | + "version": "3.9.6" |
1016 | 1048 | } |
1017 | 1049 | }, |
1018 | 1050 | "nbformat": 4, |
|
0 commit comments