Exemple #1
0
    def test_consumption_lower_than_app(self):
        sample_low_energy = create_random_sample(9,
                                                 1,
                                                 app_pkg='com.sample',
                                                 use_case='login')
        sample_high_energy = create_random_sample(12,
                                                  1,
                                                  app_pkg='com.sample',
                                                  use_case='login')
        existing_sample_one = create_random_sample(10,
                                                   1,
                                                   app_pkg='com.persisted',
                                                   use_case='login')
        existing_sample_two = create_random_sample(11,
                                                   1,
                                                   app_pkg='com.persisted',
                                                   use_case='logout')

        for measurement in existing_sample_one + existing_sample_two:
            measurement.persist()

        asserts.consumption_lower_than_app(sample_low_energy, "com.persisted")
        asserts.consumption_lower_than_app(sample_low_energy, "com.persisted",
                                           "login")
        with self.assertRaises(Exception):
            asserts.consumption_lower_than_app(sample_high_energy,
                                               "com.persisted")
        with self.assertRaises(Exception):
            asserts.consumption_lower_than_app(sample_high_energy,
                                               "com.persisted", "login")
Exemple #2
0
 def test_violinplot(self):
     # pylint: disable=no-self-use
     sample_a = create_random_sample(10, 1, use_case='login_fb')
     sample_b = create_random_sample(20, 0.5, use_case='login_twitter')
     sample_c = create_random_sample(15, 3, use_case='login_google+')
     with NamedTemporaryFile(prefix="violinplot",
                             suffix='.png',
                             delete=False) as tmp_file:
         violinplot(sample_a, sample_b, sample_c, save_fig=tmp_file)
Exemple #3
0
 def test_top_percentile(self):
     sample = create_random_sample(11,
                                   1,
                                   app_pkg='com.sample',
                                   use_case='login')
     for i in range(100):
         existing_sample = create_random_sample(
             i, 1, app_pkg=('com.persisted.{}'.format(i)), use_case='login')
         for measurement in existing_sample:
             measurement.persist()
     asserts.top_percentile(sample, 12)
     with self.assertRaises(Exception):
         asserts.top_percentile(sample, 11)
Exemple #4
0
 def test_smart_hypothesis_testing(self):
     # pylint: disable=no-self-use
     sample_a = create_random_sample(10, 1, use_case='login_fb')
     sample_b = create_random_sample(20, 0.5, use_case='login_twitter')
     sample_c = create_random_sample(15, 3, use_case='login_google+')
     with NamedTemporaryFile(prefix="violinplot",
                             suffix='.tex',
                             delete=False) as tmp_file, open(
                                 tmp_file.name, "w") as out:
         smart_hypothesis_testing(sample_a,
                                  sample_b,
                                  sample_c,
                                  fancy="True",
                                  alpha=0.05,
                                  equal_var=True,
                                  out=out)
Exemple #5
0
 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))
Exemple #6
0
 def test_consumption_below(self):
     sample = create_random_sample(10, 1)
     asserts.consumption_below(sample, 11)
     with self.assertRaises(Exception):
         asserts.consumption_below(sample, 9)