#Python assertion error. my tests do not pass.

1 messages · Page 1 of 1 (latest)

mortal goblet
#

if someone can dm that would be helpful because theres more than one file

tawdry flame
#

It's best to send everything you can here and ask for help here. Usually people are reluctant to help in DM, specially when not all the info is given. https://dontasktoask.com/

#

You can see here the tests that failed and why but it's hard for us to say exactly the issue without more info.

mortal goblet
#

Okay sure

#

okay so theres the sample tests file first of all

tough cliff
#

One of your failures is from here:

def test_request_driver() -> None:
    y = Rider('rider', 10, Location(1, 1), Location(10, 10))
    x = Dispatcher()
    output = x.request_driver(y)
    assert output is None

    z = Driver('driver', Location(0, 0), 10)
    assert x.request_rider(z) == y

Why would you expect the output of x.request_driver(y) to be None

#

The logic of this whole method doesn't make mutch sense to me

#

Wouldn't you want something like:

def test_request_driver() -> None:
    y = Rider('rider', 10, Location(1, 1), Location(10, 10))
    x = Dispatcher()
    z = x.request_driver(y)
    assert output is not None
    assert x.request_rider(z) == y

#

In the assertion failure x.request_driver(y) shows its returning a driver. so why would you request a driver and expect it to be None ?

mortal goblet
#

i tried that but still the assertion error is there 🤔

tough cliff
#

Think about what the thing is actually trying to do

mortal goblet
#

assert report == {'rider_wait_time': 2.0, 'driver_total_distance': 6.0, 'driver_ride_distance': 6.0}
this is the line it has a problem with

tough cliff
#

Do you maybe need to create a Driver and submit it to x

mortal goblet
#

I did create a driver

#

here

tough cliff
#

Uh

#

thats not an instantiation of a driver

#

Thats just the class

mortal goblet
#

then what were u referring to?

#

wait so u think theres something wrong with the tests?

tough cliff
#
def test_request_driver() -> None:
    the_dispatcher = Dispatcher()
    the_driver = Driver('driver', Location(0, 0), 10)
    the_rider = Rider('rider', 10, Location(1, 1), Location(10, 10))

    # You need to tell the dispatcher that the driver exists
    # before it can asssign a driver to the rider

    z = the_dispatcher.request_driver(the_rider)
    assert z is not None
    assert the_rider == the_dispatcher.request_rider(the_driver)


#

The Dispatcher can't just divine that the driver exists when you create it

mortal goblet
#

oh

#

so i've been basically making the tests wrong this whole time

tough cliff
#

Well, at least this one seems wrong

#

I highly recommend you use better variable names than x y and z unless those are used in math formulas.

mortal goblet
#

right

tough cliff
#

It looks like in at least that test test_request_driver you are attempting to test that the dispatcher will return the correct driver given a rider.

  • make a dispatcher
  • make a driver
  • tell the dispatcher that the driver is ready for work
  • make a rider
  • ask the dispatcher to dispatch some driver
  • ensure that the driver that the dispatcher is the exact same driver that you said was ready for work
mortal goblet
#

yeah

#

ok so i guess the problem was with the way i was making the test cases

#

and not the code

tough cliff
#

at least in this case.