示例#1
0
class TestAttribute(unittest.TestCase):
    """Unit test class to test the Attribute class functions."""

    def setUp(self):
        """Set up the attribute for testing."""

        self.attribute_name = 'Test Attribute'
        self.attribute = Attribute(self.attribute_name, weightage_function_mock,
                                   valuation_function_mock,
                                   production_function_mock)

    def test_init(self):
        """Test the constructor function."""

        self.assertEqual(self.attribute.name, self.attribute_name,
                         'Attribute name not correct.')
        self.assertEqual(self.attribute._weightage_function.__name__,
                         weightage_function_mock.__name__,
                         'Weightage function name not correct.')

    def test_repr(self):
        """Test the repr function."""

        attribute_name = self.attribute.name
        attribute_repr = 'Attribute[name={}, value=0]'.format(attribute_name)
        self.assertEqual(attribute_repr, self.attribute.__repr__())

    def test_production(self):
        """Test the production function."""

        self.assertEqual(self.attribute.production(100, 0.5), 50,
                         'Production not correct.')

    def test_valuation(self):
        """Test the valuation function."""

        self.assertEqual(self.attribute.valuation(100), 100,
                         'Valuation not correct.')

    def test_weightage(self):
        """Test the weightage function."""

        self.assertEqual(self.attribute.weightage(5), 5 / 100,
                         'Weight not correct.')