133259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reck# Copyright 2014 The Chromium Authors. All rights reserved.
233259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reck# Use of this source code is governed by a BSD-style license that can be
333259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reck# found in the LICENSE file.
433259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reck
533259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reckimport json
633259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reckimport unittest
733259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reck
833259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reckfrom telemetry.internal.platform.power_monitor import monsoon_power_monitor
933259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reck
1033259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reck
1133259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reckclass MonsoonPowerMonitorTest(unittest.TestCase):
1233259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reck
1333259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reck  def testEnergyComsumption(self):
1433259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reck    data = {
1533259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reck        'duration_s': 3600.0,
1633259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reck        'samples': [(1.0, 1.0), (2.0, 2.0), (3.0, 3.0), (4.0, 4.0)]
1733259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reck    }
1833259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reck    results = monsoon_power_monitor.MonsoonPowerMonitor.ParseSamplingOutput(
1933259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reck        json.dumps(data))
2033259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reck    self.assertEqual(results['power_samples_mw'], [1000, 4000, 9000, 16000])
2133259e44c8229f70ffe0cf3bb5ca9375c4feb2f9John Reck    self.assertEqual(results['monsoon_energy_consumption_mwh'], 7500)
22