示例#1
0
class AbstractStatMethodTests(TestCase):
    """Tests for the AbstractStatMethod class."""

    def setUp(self):
        """Define some sample data that will be used by the tests."""
        self.inst = AbstractStatMethod()

    def test_parse(self):
        """Test raises error."""
        self.assertRaises(NotImplementedError, self.inst.parse, 'foo')

    def test_parse_float(self):
        """Test parsing float strings."""
        obs = self.inst.parse_float('0.045')
        self.assertFloatEqual(obs, 0.045)

        obs = self.inst.parse_float('1.0')
        self.assertFloatEqual(obs, 1.0)

        obs = self.inst.parse_float('0')
        self.assertFloatEqual(obs, 0.0)

        obs = self.inst.parse_float('42')
        self.assertFloatEqual(obs, 42.0)

        obs = self.inst.parse_float('5', 0)
        self.assertFloatEqual(obs, 5.0)

        obs = self.inst.parse_float('-9', max_val=10)
        self.assertFloatEqual(obs, -9.0)

    def test_parse_float_invalid_input(self):
        """Test parsing invalid float strings raises errors."""
        self.assertRaises(ValueError, self.inst.parse_float, 'foo')
        self.assertRaises(ValueError, self.inst.parse_float, '5.0', 0, 1)
        self.assertRaises(ValueError, self.inst.parse_float, '-0.1', 0, 1)
        self.assertRaises(ValueError, self.inst.parse_float, '-0.1', 0)
        self.assertRaises(ValueError, self.inst.parse_float, '11.2',
                          max_val=10)
        self.assertRaises(TypeError, self.inst.parse_float, 'nan')

    def test_eq(self):
        """Test equality check."""
        self.assertTrue(Best() == Best())
        self.assertTrue(QiimeStatMethod() == QiimeStatMethod())
        self.assertFalse(Best() == Mantel())
        self.assertFalse(QiimeStatMethod() == Anosim())
        self.assertFalse(Anosim() == QiimeStatMethod())

    def test_ne(self):
        """Test inequality check."""
        self.assertFalse(Best() != Best())
        self.assertFalse(QiimeStatMethod() != QiimeStatMethod())
        self.assertTrue(Best() != Mantel())
        self.assertTrue(QiimeStatMethod() != Anosim())
        self.assertTrue(Anosim() != QiimeStatMethod())
示例#2
0
 def setUp(self):
     """Define some sample data that will be used by the tests."""
     self.inst = AbstractStatMethod()