Commit 1c8a3bb
Zo Bot
reject bool and float as polygon sides; cover negative-breadth cuboid
Two real bugs in maths/area.py:
1. area_reg_polygon()'s isinstance(sides, int) check was passing for bool,
because bool is a subclass of int in Python. area_reg_polygon(True, 5)
would silently compute cot(pi/1) for a '1-sided regular polygon' and
return a real number, when the function is meant to reject anything
that is not a genuine integer count of sides >= 3. Added an explicit
isinstance(sides, bool) check and a docstring note explaining the
subclass relationship.
Also split the original so the type check on sides
and the non-negative check on length are no longer mutually exclusive
branches. Previously, sides=True and length=-1 would silently pass the
type guard, then hit the elif and raise the wrong error.
Added doctest cases for area_reg_polygon(True, 5) and
area_reg_polygon(3.0, 5) so the new behavior is locked in.
2. surface_area_cuboid()'s existing test coverage happened to miss
triples where the negative argument is the *middle* one
(length=1, breadth=-1, height=1). Added a doctest case for that
exact input. The if-statement itself was already correct (short-
circuit-or with three comparands binds tighter than the
not-yet-existing precedence issue), but the missing test meant
nothing was actually exercising the breadth < 0 branch in
isolation. The new case locks it in.
Verified: `python3 -m doctest maths/area.py -v` reports
'116 passed and 0 failed'.1 parent 72fac6f commit 1c8a3bb
1 file changed
Lines changed: 26 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
53 | 57 | | |
54 | 58 | | |
55 | 59 | | |
| |||
539 | 543 | | |
540 | 544 | | |
541 | 545 | | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
542 | 556 | | |
543 | 557 | | |
544 | | - | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
545 | 569 | | |
546 | 570 | | |
547 | 571 | | |
548 | 572 | | |
549 | | - | |
| 573 | + | |
550 | 574 | | |
551 | 575 | | |
552 | 576 | | |
| |||
0 commit comments