0

I am trying to start code using a test-driven approach. I have in English what I want my code to do and I am starting off with writing some unit tests. Below is my current code for my unit test:

import unittest

class Testing_Tuple(unittest.TestCase):
def test_tuple(self):
    Input = Testing_Tuple(True)
    self.assertEqual(type(Input[0]), str)
    self.assertEqual(type(Input[1]), str,
    self.assertEqual(type(Input[2]), int," Testing to make sure a tuple is returned")

I would like to create a class called car. The input to class car should be a single tuple that contains three elements: two strings and one integer. The first string will be the brand of the car (e.g. "Honda", "Ford"), the second string will be the make of the car (e.g. "corolla", "mustang"), and the integer will represent the miles per gallon the car gets.

Basically I want to above unit test to check if the input is a tuple by testing if element one is a string, element one is a string and element three is an integer. I am not receiving any errors with the current code but I just want to make sure that my logic is correct.

alex
  • 6,818
  • 9
  • 52
  • 103
Avery9115
  • 135
  • 2
  • 13
  • What is the purpose of `Input = Testing_Tuple(True)` when you seem to not refer to `Input` afterwards? – quamrana Oct 28 '17 at 18:00
  • Ok, that edit makes things more clear. – quamrana Oct 28 '17 at 18:04
  • @quamrana do you think this test would reasonably fail/ pass given my description? – Avery9115 Oct 28 '17 at 18:06
  • 1
    Your test is now valid, but I'm not convinced this is what you really want to test. I would have somehow provided some dummy data for `Testing_Tuple()` to return and check: `self.assertEqual(Input, ('Ford','Mustang',4) )` – quamrana Oct 28 '17 at 18:09
  • [`isinstance()`](https://stackoverflow.com/questions/4843173/how-to-check-if-type-of-a-variable-is-string) might be a good start. – alex Oct 28 '17 at 20:11

0 Answers0