def top_percentile(sample, nth): """Test that a given sample is in the top nth percentile. Args: sample (list of Measurement): sample of measurements nth (number): percentage of the position in which the sample should fit app (string): identifier of the application within the sample should be compared use_case (string: identifier of the use case used to create the ranking """ position, total = Measurement.get_position_in_ranking(sample) percentile_position = float(position) / total * 100 assert percentile_position <= nth,\ ("Given sample is not on {:.1f}% top percentile " "(Position: {:.1f}%)".format( nth, percentile_position ))
def test_get_energy_ranking(self): sample = (create_random_sample(10, 1, app_pkg="com.app1") + create_random_sample(11, 1, app_pkg="com.app2") + create_random_sample(12, 1, app_pkg="com.app3") + create_random_sample(13, 1, app_pkg="com.app4") + create_random_sample(14, 1, app_pkg="com.app5") + create_random_sample(15, 1, app_pkg="com.app6")) for measurement in sample: measurement.persist() ranking = Measurement.get_energy_ranking() self.assertEqual(list(ranking.keys()), [ "com.app1", "com.app2", "com.app3", "com.app4", "com.app5", "com.app6", ]) compare_sample = create_random_sample(12.5, 0.5, app_pkg="com.app7") self.assertEqual(Measurement.get_position_in_ranking(compare_sample), (4, 6))