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 trial

Python

The use of the test_upper() test for dice rolling doesn't make any sense to me.

We're learning to make a test for dice rolling with this code:

def test_upper(self):
    self.assertLessEqual(int(self.hand3), 18)

Though it doesn't make any sense to me what the use is for this test. If I 'create' an error by changing 18 into 17 the chances are very slim the test fails if I run it (1 to 216, to be precise).

Can you help me out with this?

Steven Parker
Steven Parker
243,656 Points

Can you provide a link to the course page where you saw this?

If I understand, I think you're wondering how the test proves you can't roll more than 18?

I don't think the test proves that. I think it's only showing that whatever random roll the test generated is not more than 18.

What did you mean by the "1 to 216, to be precise"?

Tagging Kenneth Love

3 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Yeah, it's just a test to make sure that any random roll of the dice isn't over 18. It's not meant to be an exhaustive test, it's meant to be a sanity check.

Most tests you write won't be exhaustive. You can't account for every single scenario that might ever come up. So you write tests to catch the edges and the known-bads and you keep your suite up-to-date when new known failures come up.

Hello Steven, I found it here: https://teamtreehouse.com/library/python-testing/be-assertive/membership-and-other-assertions In the video from about 5:40

I know my question should be here: https://teamtreehouse.com/community/video:36842 But somehow my post ended up somewhere else.

Hi David,

Did you use the "Get Help" button for that video when posting your question?

Hello Kenneth,

Sanity check, non exhaustive. That makes sense to me! Thanks for your answer.

@Jason: 1 in 216, being 1:6 * 1:6 * 1:6, the small chance that the test will fail if I change 18 into 17. Yes, I used the "get help" button.

I think this topic can be closed now. Thanks for your help guys.