#๐Ÿ”’ Testing plates

44 messages ยท Page 1 of 1 (latest)

lunar parrot
#

How do i test my function for this?


import plates

def test_plate():
    assert plates.is_valid("AAA222")

def test_alpha():
    assert plates.is_valid("a1A222") != True


spiral sequoiaBOT
#

@lunar parrot

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

novel matrix
#

first off, you should never, ever have to do == True or == False

#

for the former, just leave it out

#

for the latter, just add not

#

but can you clarify your question a bit?

lunar parrot
novel matrix
#

assert plates.is_valid("AAA222")

lunar parrot
lunar parrot
#

its a course

novel matrix
#

should I already know how that function works or what it does?

lunar parrot
#

u can have a read

novel matrix
#

where?

lunar parrot
#

def is_valid(s):
    if len(s) > 6 or len(s) < 2:
        return False

    if s[0].isnumeric() or s[1].isnumeric():
        return False

    count = 0
    for char in s:

        if char.isalnum() == False:
            return  False

        if char.isnumeric() and count == 0 and char == "0":
            return  False
        elif char.isnumeric():
            count += 1

    for c in s:
        if c.isnumeric():

            position = s.index(c)
            if s[position: ].isnumeric() != True:
                return False

    return True
#

here

novel matrix
#

ok so are those two tests failing?

lunar parrot
#

apologies if its not clear

lunar parrot
#

but idk how to do the checks of my tests

#

heres a link for the question

novel matrix
#

if I understand the assignment correctly, you should have additional tests for failing cases

lunar parrot
#

umm

#

im not sure what to do for that tho

#

have a read of this too, this is for the function is_valid()

#

๐Ÿ˜ฆ test_plates catches plates.py without beginning alphabetical checks

#

what does the above mean? ^^

novel matrix
#

presumably it would test that this part is in place:

    if s[0].isnumeric() or s[1].isnumeric():
        return False
#

so the test should call the function with a plate that is of the correct length but starts with a digit

#

if I understand this correctly

lunar parrot
#

um

lunar parrot
#

its just the checks that is not doing its job

novel matrix
#

frankly I also have trouble understanding just what this test module is expected to do

lunar parrot
#

fair enough

#

should i put a raise Error?

novel matrix
#

like, are you supposed to introduce errors to plates.py to trigger the failures?

lunar parrot
#

honestly got no idea

#

ill let someone else awnser

spiral sequoiaBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.