Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialElizabeth McInerney
3,175 Pointsis_palindrome
I am looking for some help to understand what I am missing here.
import unittest
from string_fun import is_palindrome
class PalindromeTestCase(unittest.TestCase):
def test_good_palindrome(self):
pass
def test_bad_palindrome(self):
pass
def test_is_palindrome(self):
self.assertTrue(self.is_palindrome == "tacocat")
def is_palindrome(yarn):
"""Return whether or not a string is a palindrome.
A palindrome is a word/phrase that's the same in
both directions.
"""
return yarn == yarn[::-1]
2 Answers
Kenneth Love
Treehouse Guest TeacherYou need to actually call is_palindrome
(and it doesn't belong to the test instance so you don't use self
).
Elizabeth McInerney
3,175 PointsThis just worked:
class PalindromeTestCase(unittest.TestCase):
def test_good_palindrome(self):
self.assertTrue(is_palindrome('tacocat'))
Elizabeth McInerney
3,175 PointsThe code the worked, will not work without the self.
Kenneth Love
Treehouse Guest TeacherYes. The assertTrue
needs to have self
because it comes from TestCase
. But is_palindrome
doesn't need it because it doesn't belong to TestCase
, it is its own stand alone method.
Elizabeth McInerney
3,175 PointsHow do I get into the Workspace that includes moves.py?
Kenneth Love
Treehouse Guest TeacherIt should be attached to all of the videos, down here in the corner:
Is it not there for you?
Elizabeth McInerney
3,175 PointsThere is a workspace link below the video, but when I click on it, I get a response saying that I need to create a workspace. If I did that, the workspace would be empty.
Kenneth Love
Treehouse Guest TeacherThose are your workspaces that you've already created that are associated with this video. On the bottom right edge of the video player should be the "Launch Workspace" button I screenshotted above. Is it not there?
Elizabeth McInerney
3,175 PointsOk, I just saw it. I had to start running the video to get it to show up. So I launched a workspace, and it contained dice, dungeon and rps, but no moves.
Kenneth Love
Treehouse Guest TeacherCheck inside the rps/
directory.
Elizabeth McInerney
3,175 PointsI see it now. I may be the only thick student this course gets, but just an FYI that I had trouble knowing where to look for it. ps: the moves Jagger was a good one.
Elizabeth McInerney
3,175 PointsElizabeth McInerney
3,175 PointsThanks for your help. I understand now. There were 2 things that I did not understand in the video. First was the use of the word dunder a couple of times (the first time at 1:08), when I did not see you type any dunders. (I use CC to watch the videos). The second thing that confused me was not understanding why you used self.rock and self.paper in test_not_equal, but then used self.rock and moves.Rock() in test_equal.
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest Teacher"dunder" just means "double underscore" or
__
. It's pretty common in the Python world, and I think I used it in Object-Oriented Python but I should have explained it here too. Sorry about that.I didn't use
self.rock
twice in the second example because I wanted to be sure and have two differentRock
s to compare.Elizabeth McInerney
3,175 PointsElizabeth McInerney
3,175 PointsYes, I remember what dunder means, I just didn't understand why you were using the term when you weren't adding or looking at any code that had any dunders. So I wasn't sure what part of the code you were referring to. I guess what was also a little confusing about that video was just trying to remember what rock referred to. I know it was from the paper/rock/scissors game, just couldn't remember what it meant for 2 rocks to be equal or not equal. Thanks. I have really enjoyed the course and will hopefully finish soon, just giving user feedback on some things.
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherOh. If you look in
moves.py
, you'll see a bunch of dunder methods (magic methods) in theMoves
class, whichRock
,Paper
, andScissors
all extend.Elizabeth McInerney
3,175 PointsElizabeth McInerney
3,175 PointsI couldn't figure out how to get into the workspace you were showing that included moves.py.