diff options
Diffstat (limited to 'contexts/data/lib/closure-library/closure/goog/testing/performancetimer_test.html')
-rw-r--r-- | contexts/data/lib/closure-library/closure/goog/testing/performancetimer_test.html | 160 |
1 files changed, 0 insertions, 160 deletions
diff --git a/contexts/data/lib/closure-library/closure/goog/testing/performancetimer_test.html b/contexts/data/lib/closure-library/closure/goog/testing/performancetimer_test.html deleted file mode 100644 index f4727c4..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/performancetimer_test.html +++ /dev/null @@ -1,160 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- -Author: attila@google.com (Attila Bodis) ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> - <title>Closure Unit Tests - goog.testing.PerformanceTimer</title> - <script src="../base.js"></script> - <script> - goog.require('goog.dom'); - goog.require('goog.math'); - goog.require('goog.testing.MockClock'); - goog.require('goog.testing.PerformanceTimer'); - goog.require('goog.testing.jsunit'); - </script> -</head> -<body> - <div id="sandbox"></div> - <script> - var mockClock; - var sandbox = document.getElementById('sandbox'); - var timer; - - // Fast test function, pretty much guaranteed to run in under 5,000ms. - function fastTestFunction() { - for (var i = 0; i < 10; i++) { - var div = document.createElement('div'); - div.innerHTML = 'Div no. ' + i; - sandbox.appendChild(div); - } - } - - function setUp() { - mockClock = new goog.testing.MockClock(true); - timer = new goog.testing.PerformanceTimer(); - } - - function tearDown() { - mockClock.dispose(); - timer = null; - goog.dom.removeChildren(sandbox); - } - - function testConstructor() { - assertTrue('Timer must be an instance of goog.testing.PerformanceTimer', - timer instanceof goog.testing.PerformanceTimer); - assertEquals('Timer must collect the default number of samples', 10, - timer.getNumSamples()); - assertEquals('Timer must have the default timeout interval', 5000, - timer.getTimeoutInterval()); - } - - function testRun_noSetUpOrTearDown() { - runAndAssert(false, false); - } - - function testRun_withSetup() { - runAndAssert(true, false); - } - - function testRun_withTearDown() { - runAndAssert(false, true); - } - - function testRun_withSetUpAndTearDown() { - runAndAssert(true, true); - } - - function runAndAssert(useSetUp, useTearDown) { - var fakeExecutionTime = [100, 95, 98, 104, 130, 101, 96, 98, 90, 103] - var count = 0; - var testFunction = function() { - mockClock.tick(fakeExecutionTime[count++]); - }; - - var setUpCount = 0; - var setUpFunction = function() { - // Should have no effect on total time. - mockClock.tick(7); - setUpCount++; - }; - - var tearDownCount = 0; - var tearDownFunction = function() { - // Should have no effect on total time. - mockClock.tick(11); - tearDownCount++; - }; - - // Fast test function should complete successfully in under 5 seconds... - var task = new goog.testing.PerformanceTimer.Task(testFunction); - if (useSetUp) { - task.withSetUp(setUpFunction); - } - if (useTearDown) { - task.withTearDown(tearDownFunction); - } - var results = timer.runTask(task); - - assertNotNull('Results must be available.', results); - - assertEquals('Average is wrong.', - goog.math.average.apply(null, fakeExecutionTime), results['average']); - assertEquals('Standard deviation is wrong.', - goog.math.standardDeviation.apply(null, fakeExecutionTime), - results['standardDeviation']); - - assertEquals('Count must be as expected.', 10, results['count']); - assertEquals('Maximum is wrong.', 130, results['maximum']); - assertEquals('Mimimum is wrong.', 90, results['minimum']); - assertEquals('Total must be a nonnegative number.', - goog.math.sum.apply(null, fakeExecutionTime), results['total']); - - assertEquals('Set up count must be as expected.', - useSetUp ? 10 : 0, setUpCount); - assertEquals('Tear down count must be as expected.', - useTearDown ? 10 : 0, tearDownCount); - } - - function testTimeout() { - var count = 0; - var testFunction = function() { - mockClock.tick(100); - ++count; - }; - - timer.setNumSamples(200); - timer.setTimeoutInterval(2500); - var results = timer.run(testFunction); - - assertNotNull('Results must be available', results); - assertEquals('Count is wrong', count, results['count']); - assertTrue('Count must less than expected', - results['count'] < timer.getNumSamples()); - } - - function testCreateResults() { - var samples = [53, 0, 103]; - var expectedResults = { - 'average': 52, - 'count': 3, - 'maximum': 103, - 'minimum': 0, - 'standardDeviation': goog.math.standardDeviation.apply(null, samples), - 'total': 156 - }; - assertObjectEquals( - expectedResults, - goog.testing.PerformanceTimer.createResults(samples)); - } - </script> -</body> -</html> |