http://www.mediawiki.org/wiki/Special:Code/MediaWiki/96066

Revision: 96066
Author:   inez
Date:     2011-09-01 23:36:52 +0000 (Thu, 01 Sep 2011)
Log Message:
-----------
Implementation and tests for getLengthOfItems in es.ContentSeries

Modified Paths:
--------------
    trunk/parsers/wikidom/lib/synth/bases/es.ContentSeries.js
    trunk/parsers/wikidom/tests/synth/test.js

Modified: trunk/parsers/wikidom/lib/synth/bases/es.ContentSeries.js
===================================================================
--- trunk/parsers/wikidom/lib/synth/bases/es.ContentSeries.js   2011-09-01 
23:32:08 UTC (rev 96065)
+++ trunk/parsers/wikidom/lib/synth/bases/es.ContentSeries.js   2011-09-01 
23:36:52 UTC (rev 96066)
@@ -43,12 +43,12 @@
        return null;
 };
 
-es.ContentSeries.prototype.size = function() {
+es.ContentSeries.prototype.getLengthOfItems = function() {
        var sum = 0;
        for ( var i = 0, length = this.length; i < length; i++ ) {
                sum += this[i].getLength();
        }
-       return sum;
+       return Math.max( 0, sum + this.length - 1 );
 };
 
 es.ContentSeries.prototype.select = function( start, end ) {

Modified: trunk/parsers/wikidom/tests/synth/test.js
===================================================================
--- trunk/parsers/wikidom/tests/synth/test.js   2011-09-01 23:32:08 UTC (rev 
96065)
+++ trunk/parsers/wikidom/tests/synth/test.js   2011-09-01 23:36:52 UTC (rev 
96066)
@@ -166,7 +166,7 @@
        return this.size;
 };
 
-test( 'ContentSeries lookup and rangeOf', function() {
+test( 'ContentSeries lookup, rangeOf and getLengthOfItems', function() {
        strictEqual(
                ( new ContentStub( 'a', 0 ) ).getLength(),
                0,
@@ -178,7 +178,24 @@
                d = new ContentStub( 'd', 3 ),
                e = new ContentStub( 'e', 4 ),
                contentSeries = new es.ContentSeries( [ a, b, c, d, e ] );
+               
+       var lengthOfItemsTests = [
+               { 'input' : [ ], 'output' : 0 },
+               { 'input' : [ a ], 'output' : 0 },
+               { 'input' : [ a, b ], 'output' : 2 },
+               { 'input' : [ a, b, c ], 'output' : 5 },
+               { 'input' : [ a, b, c, d ], 'output' : 9 },
+               { 'input' : [ a, b, c, d, e ], 'output' : 14 }
+       ];
 
+       for ( var i = 0; i < lengthOfItemsTests.length; i++ ) {
+               strictEqual(
+                       ( new es.ContentSeries( lengthOfItemsTests[i].input ) 
).getLengthOfItems(),
+                       lengthOfItemsTests[i].output,
+                       'es.ContentSeries.lookup finds the right item or 
returns null when out of range'
+               );
+       }
+
        var lookupTests = [
                { 'input' : -1, 'output' : null },
                { 'input' : 0, 'output' : a },
@@ -197,7 +214,7 @@
                { 'input' : 13, 'output' : e },
                { 'input' : 14, 'output' : e },
                { 'input' : 15, 'output' : null }
-               ];
+       ];
        
        for ( var i = 0; i < lookupTests.length; i++ ) {
                strictEqual(


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to