def testWithSampleData(self): viewport = 1000, 1000 # Add up the parts of the speed index for each time interval. # Each part is the time interval multiplied by the proportion of the # total area value that is not yet painted for that interval. parts = [] parts.append(100 * 1.0) parts.append(200 * 0.5) parts.append(100 * 0.4) parts.append(400 * 0.2) expected = sum(parts) # 330.0 actual = speedindex._SpeedIndex(_SAMPLE_EVENTS, viewport) self.assertEqual(actual, expected)
def _TestJsonTimelineExpectation(self, filename, viewport, expected): """Check whether the result for some timeline data is as expected. Args: filename: Filename of a json file which contains a expected: The result expected based on the WPT result. """ file_path = os.path.join(_TEST_DIR, filename) with open(file_path) as json_file: raw_events = json.load(json_file) events = model.TimelineModel(event_data=raw_events).GetAllEvents() actual = speedindex._SpeedIndex(events, viewport) # The result might differ by 1 or more milliseconds due to rounding, # so compare to the nearest 10 milliseconds. self.assertAlmostEqual(actual, expected, places=-1)