+ 2

Python test suite problems

This testing suite only prints that the tests fail. Even though they are true. I would put the tests where the "#" symbols are and it returns the fail string every time for every test. I am testing if a string == string. yes, i am aware there are testing functions but i want to learn everything i can from scratch first. What can i change to make my 'True' tests print out the 'ok' string? Any help is appreciated https://code.sololearn.com/cG9JotOQimij/?ref=app

12th Mar 2020, 3:50 PM
Slick
Slick - avatar
9 Antworten
+ 2
What you have done wrong is what most beginners do. In your function you are not returning anything, i.e. you have no return statement. Every function in Python that doesn't have a return statement returns None by default. So if you break down test(turn_clockwise("N") == "E") It will become test(None == "E") which is False. So instead of print(ways[dir]) do return ways[dir] That will make the code work. Also remember from now on that print != return.
12th Mar 2020, 5:17 PM
XXX
XXX - avatar
+ 2
Stared at your update for a minute and couldnt figure it out. What did you change?
12th Mar 2020, 4:00 PM
Slick
Slick - avatar
+ 2
Check the parantheses count in line 9
12th Mar 2020, 4:34 PM
XXX
XXX - avatar
+ 1
The error im running into is when i use it in Pyscript. When i test values in a function it will print the correct value, then tell me that the test failed. While it should say the test is ok.
12th Mar 2020, 4:28 PM
Slick
Slick - avatar
+ 1
So there was an error? I still don't get what it is. Could you enlighten me?
12th Mar 2020, 4:32 PM
Slick
Slick - avatar
+ 1
Alright been messing around with it in Pyscript. This is the function im testing: def turn_clockwise(dir): '''Takes a direction and goes to the next direction clockwise''' ways={'N':'E', 'E':'S', 'S':'W', 'W':'N',} print(ways[dir]) I still end up getting false. Is it because Im using strings?
12th Mar 2020, 4:59 PM
Slick
Slick - avatar
+ 1
Just posted a picture of the interpretor
12th Mar 2020, 5:11 PM
Slick
Slick - avatar
+ 1
Thats it! Thank you, very greatly appreciate you taking the time. Totally makes sense.
12th Mar 2020, 5:23 PM
Slick
Slick - avatar
+ 1
Gotcha, thats honestly only for reference. But i can see how someone who knows what they're doing just sees it as extra characters in the way. Will do.
12th Mar 2020, 5:26 PM
Slick
Slick - avatar