From 9923388cce81a38dda88a2924fd782becf4d7da3 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sun, 4 Mar 2012 07:31:04 -0500 Subject: [PATCH] Moved test runner to RandomGroupedSet and began offering option for different set randomization algorithms --- scripts/RecTest.js | 10 +++++---- scripts/TestRunner.js | 22 +++++++++++++------ scripts/main.js | 2 +- .../{TestRun.js => set/RandomGroupedSet.js} | 14 +++++++++++- scripts/set/Set.js | 15 +++++++++++++ scripts/set/SetFactory.js | 22 +++++++++++++++++++ test.html | 16 +++++++++++++- 7 files changed, 87 insertions(+), 14 deletions(-) rename scripts/{TestRun.js => set/RandomGroupedSet.js} (86%) create mode 100644 scripts/set/Set.js create mode 100644 scripts/set/SetFactory.js diff --git a/scripts/RecTest.js b/scripts/RecTest.js index 9ba5c40..2f55e7a 100644 --- a/scripts/RecTest.js +++ b/scripts/RecTest.js @@ -24,9 +24,11 @@ rectest.RecTest = Class( 'RecTest', __construct: function( jquery, cases ) { - this._jQuery = jquery; - this._cases = cases; - this._runner = rectest.TestRunner( jquery, rectest.TestRun ); + this._jQuery = jquery; + this._cases = cases; + this._runner = rectest.TestRunner( + jquery, rectest.set.SetFactory() + ); }, @@ -98,7 +100,7 @@ rectest.RecTest = Class( 'RecTest', { var options = {}, values = [ - 'case', 'set', 'interval', 'blank', 'samples', 'delay' + 'case', 'set', 'ralgo', 'interval', 'blank', 'samples', 'delay' ], i = values.length; diff --git a/scripts/TestRunner.js b/scripts/TestRunner.js index f785b23..335f04a 100644 --- a/scripts/TestRunner.js +++ b/scripts/TestRunner.js @@ -15,6 +15,12 @@ rectest.TestRunner = Class( 'TestRunner', */ 'private _TestRun': null, + /** + * Produces sets from the given id + * @var {set.SetFactory} + */ + 'private _setFactory': null, + /** * Render destination element * @var {jQuery} @@ -37,14 +43,14 @@ rectest.TestRunner = Class( 'TestRunner', /** * Initialize with jQuery instance * - * @param {jQuery} jquery jQuery instance - * @param {Function} TestRun TestRun constructor + * @param {jQuery} jquery jQuery instance + * @param {set.SetFactory} set_factory factory to create sets */ - __construct: function( jquery, TestRun ) + __construct: function( jquery, set_factory ) { - this._jQuery = jquery; - this._TestRun = TestRun; - this._$dest = this._createDestElement(); + this._jQuery = jquery; + this._setFactory = set_factory; + this._$dest = this._createDestElement(); }, @@ -86,7 +92,9 @@ rectest.TestRunner = Class( 'TestRunner', this._$dest.html( '' ); var _self = this, - run = _self._TestRun( test_case, options ); + run = this._setFactory.fromId( options.ralgo, + test_case, options + ); // allow test case to initialize its display test_case.initRender( this._$dest ); diff --git a/scripts/main.js b/scripts/main.js index 310f922..9dd62af 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -3,7 +3,7 @@ window.Class = easejs.Class; window.Interface = easejs.Interface; // namespace -window.rectest = { cases: {} }; +window.rectest = { set: {}, cases: {} }; $( document ).ready( function() { diff --git a/scripts/TestRun.js b/scripts/set/RandomGroupedSet.js similarity index 86% rename from scripts/TestRun.js rename to scripts/set/RandomGroupedSet.js index c310d5e..0db21cc 100644 --- a/scripts/TestRun.js +++ b/scripts/set/RandomGroupedSet.js @@ -1,4 +1,11 @@ -rectest.TestRun = Class( 'TestRun', +/** + * Represents a set that is randomized each time the first element is reached. + * The set will loop back to the first element until the required number of + * samples are satisfied. + */ +rectest.set.RandomGroupedSet = Class( 'RandomGroupedSet' ) + .implement( rectest.set.Set ) + .extend( { /** * Test case being executed @@ -89,6 +96,11 @@ rectest.TestRun = Class( 'TestRun', }, + /** + * Retrieve the next element in the set + * + * @return {string} next element in set + */ 'public getNextElement': function() { // reset once we're at the end diff --git a/scripts/set/Set.js b/scripts/set/Set.js new file mode 100644 index 0000000..5e7780d --- /dev/null +++ b/scripts/set/Set.js @@ -0,0 +1,15 @@ +/** + * Represents a set from which samples should be gathered + */ +rectest.set.Set = Interface( 'Set', +{ + __construct: [ 'test_case', 'options' ], + + + /** + * Retrieve the next element in the set + * + * @return {string} next element in set + */ + 'public getNextElement': [] +} ); diff --git a/scripts/set/SetFactory.js b/scripts/set/SetFactory.js new file mode 100644 index 0000000..cf2f9d1 --- /dev/null +++ b/scripts/set/SetFactory.js @@ -0,0 +1,22 @@ +/** + * Returns the requesetd type of set + */ +rectest.set.SetFactory = Class( 'SetFactory', +{ + 'public fromId': function( id, test_case, options ) + { + var sets = rectest.set; + + if ( !( Class.isA( rectest.TestCase, test_case ) ) ) + { + throw TypeError( "Invalid test case: " + test_case ); + } + + return [ + null, + sets.RandomGroupedSet, + null, + null + ][ id ]( test_case, options ); + } +} ); diff --git a/test.html b/test.html index c37393d..61393cb 100644 --- a/test.html +++ b/test.html @@ -56,7 +56,15 @@
seconds
Sample Size
-
(0 for infinite)
+
+ + +
Begin Delay
seconds
@@ -92,6 +100,12 @@ + + + + +