def test_is_last_point_in_control_does_not_generate_false_positives_when_outliers_exist_but_are_not_last( self): chart = ControlChart(SERIES_WITH_UCL_OUTLIERS) chart_points_outside_ucl = chart.points_outside_ucl() self.assertGreater(len(chart_points_outside_ucl), 0) self.assertTrue(chart.is_last_point_in_control())
def test_chart_computes_sample_statistics(self): series = (1, 2, 2, 3, 3, 3, 2, 2, 1) chart = ControlChart(series) self.assertAlmostEqual(2.1111, chart.mean(), places=4) self.assertEquals(2, chart.median()) self.assertAlmostEqual(0.78173, chart.std_dev(), places=3) self.assertEquals(len(series), chart.count())
def test_get_last_point(self): chart = ControlChart(SERIES_UNDER_CONTROL) last_index = len(SERIES_UNDER_CONTROL) - 1 expected_last_point = (last_index, SERIES_UNDER_CONTROL[last_index]) last_point = chart.get_last_point() print "expected_last_point: {}".format(expected_last_point) print "last_point: {}".format(last_point) self.assertEquals(expected_last_point, last_point)
def test_chart_computes_control_limits(self): chart = ControlChart(SERIES_WITH_UCL_OUTLIERS) (lcl, ucl) = chart.control_limits() self.assertEquals(lcl, chart.lower_control_limit()) self.assertEquals(ucl, chart.upper_control_limit()) self.assertAlmostEqual(lcl, -3.1952, places=4) self.assertAlmostEqual(ucl, 3.4809, places=4)
def test_series_under_control(self): chart = ControlChart(SERIES_UNDER_CONTROL) self.assertEquals(10.05, chart.mean()) self.assertEquals(10.05, chart.median()) self.assertAlmostEquals(0.8737, chart.std_dev(), places=4) self.assertAlmostEquals(7.429, chart.lower_control_limit(), places=3) self.assertAlmostEquals(12.671, chart.upper_control_limit(), places=3) self.assertEquals([], chart.points_outside_lcl()) self.assertEquals([], chart.points_outside_ucl())
def test_data_series_is_analyzed(self): tf = tempfile.NamedTemporaryFile() control_chart = ControlChart(SERIES_UNDER_CONTROL) test_input = "" for val in SERIES_UNDER_CONTROL: test_input += " {} \n".format(str(val)) tf.write(test_input) tf.flush() sys.argv = ["analyze_series", tf.name, "--verbose"] (status, message) = self._analyze_series_cmd.execute() self.assertEquals(AnalyzeSeriesCommand.STATUS_SUCCESS, status) self.assertEquals("", message) expected_mean = control_chart.mean() actual_mean = self._analyze_series_cmd._control_chart.mean() self.assertAlmostEquals(expected_mean, actual_mean, places=3)
def test_chart_can_get_last_point_when_only_one_point_exists(self): series = (42, ) chart = ControlChart(series) self.assertEquals((0, 42), chart.get_last_point())
def test_chart_handles_get_last_point_on_empty_series_gracefully(self): series = () chart = ControlChart(series) self.assertIsNone(chart.get_last_point())
def test_points_outside_ucl_are_identified(self): chart = ControlChart(SERIES_WITH_UCL_OUTLIERS) index = 18 value = 4 self.assertIn((index, value), chart.points_outside_ucl())
def test_is_last_point_in_control_does_not_generate_false_positives_when_outliers_exist_but_are_not_last(self): chart = ControlChart(SERIES_WITH_UCL_OUTLIERS) chart_points_outside_ucl = chart.points_outside_ucl() self.assertGreater(len(chart_points_outside_ucl), 0) self.assertTrue(chart.is_last_point_in_control())
def test_chart_can_get_last_point_when_only_one_point_exists(self): series = (42,) chart = ControlChart(series) self.assertEquals((0, 42), chart.get_last_point())