def setUp(self): """Define some sample data that will be used by the tests.""" self.colwell_data1 = asarray(colwell_data1) self.colwell_data2 = asarray(colwell_data2) self.est1 = AbstractPointEstimator(asarray([0, 1, 2, 3, 4, 5])) self.est2 = AbstractPointEstimator(self.colwell_data1) self.est3 = AbstractPointEstimator(self.colwell_data2)
class AbstractPointEstimatorTests(TestCase): """Tests for the AbstractPointEstimator class.""" def setUp(self): """Define some sample data that will be used by the tests.""" self.colwell_data1 = asarray(colwell_data1) self.colwell_data2 = asarray(colwell_data2) self.est1 = AbstractPointEstimator(asarray([0, 1, 2, 3, 4, 5])) self.est2 = AbstractPointEstimator(self.colwell_data1) self.est3 = AbstractPointEstimator(self.colwell_data2) def test_constructor(self): """Test instantiating an AbstractPointEstimator instance.""" self.assertTrue(isinstance(self.est1, AbstractPointEstimator)) def test_constructor_empty_sample(self): """Test instantiating an estimator with a sample that has no obs.""" with self.assertRaises(EmptySampleError): _ = AbstractPointEstimator(asarray([0, 0, 0, 0.0, 0, 0.0])) def test_getTotalIndividualCount(self): """Returns correct total number of observed individuals.""" # Verified with iNEXT. self.assertEqual(self.est1.getTotalIndividualCount(), 15) # Verified against results in Colwell 2012 paper. self.assertEqual(self.est2.getTotalIndividualCount(), 976) self.assertEqual(self.est3.getTotalIndividualCount(), 237) def test_getObservationCount(self): """Returns correct number of (observed) observations.""" # Verified with iNEXT. self.assertEqual(self.est1.getObservationCount(), 5) # Verified against results in Colwell 2012 paper. self.assertEqual(self.est2.getObservationCount(), 140) self.assertEqual(self.est3.getObservationCount(), 112) def test_getAbundanceFrequencyCounts(self): """Returns correct abundance frequency counts.""" # Verified with iNEXT. exp = defaultdict(int, {1: 1, 2: 1, 3: 1, 4: 1, 5: 1}) obs = self.est1.getAbundanceFrequencyCounts() self.assertEqual(obs, exp) # Verified against results in Colwell 2012 paper. self.assertEqual(self.est2.getAbundanceFrequencyCounts(), colwell_fk1) self.assertEqual(self.est3.getAbundanceFrequencyCounts(), colwell_fk2) def test_call(self): """Test should raise error.""" with self.assertRaises(NotImplementedError): self.est1(1)
def test_constructor_empty_sample(self): """Test instantiating an estimator with a sample that has no obs.""" with self.assertRaises(EmptySampleError): _ = AbstractPointEstimator(asarray([0, 0, 0, 0.0, 0, 0.0]))