Question(s)
o1bigtenor
o1bigtenor at gmail.com
Thu Oct 26 08:46:54 EDT 2023
On Wed, Oct 25, 2023 at 11:58 AM Michael F. Stemper via Python-list
<python-list at python.org> wrote:
>
> On 25/10/2023 05.45, o1bigtenor wrote:
> > On Tue, Oct 24, 2023 at 8:35 PM Chris Angelico via Python-list
> > <python-list at python.org> wrote:
>
> >> 3. Catch the failure before you commit and push. Unit tests are great for this.
> >
> > Where might I find such please.
>
> You don't "find" unit tests; you write them. A unit test tests
> a specific function or program.
>
> Ideally, you write each unit test *before* you write the function
> that it tests.
>
> For instance, suppose that you were writing a function to calculate
> the distance between two points. We know the following things about
> distance:
> 1. The distance from a point to itself is zero.
> 2. The distance between two distinct points is positive.
> 3. The distance from A to B is equal to the distance from B to A.
> 4. The distance from A to B plus the distance from B to C is at
> least as large as the distance from A to C.
>
> You would write unit tests that generate random points and apply
> your distance function to them, checking that each of these
> conditions is satisfied. You'd also write a few tests of hard-coded
> points,such as:
> - Distance from (0,0) to (0,y) is y
> - Distance from (0,0) to (x,0) is x
> - Distance from (0,0) to (3,4) is 5
> - Distance from (0,0) to (12,5) is 13
>
> The python ecosystem provides many tools to simplify writing and
> running unit tests. Somebody has already mentioned "unittest". I
> use this one all of the time. There are also "doctest", "nose",
> "tox", and "py.test" (none of which I've used).
>
Very useful information - - - thanks!
More information about the Python-list
mailing list