From e44a7e37b6c7b5961adaffc62b9042b8d442938e Mon Sep 17 00:00:00 2001 From: mensonge Date: Thu, 13 Nov 2008 09:49:11 +0000 Subject: New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f --- includes/js/dojox/collections/ArrayList.js | 133 +++++++++++++ includes/js/dojox/collections/BinaryTree.js | 211 +++++++++++++++++++++ includes/js/dojox/collections/Dictionary.js | 116 +++++++++++ includes/js/dojox/collections/Queue.js | 74 ++++++++ includes/js/dojox/collections/README | 39 ++++ includes/js/dojox/collections/Set.js | 89 +++++++++ includes/js/dojox/collections/SortedList.js | 198 +++++++++++++++++++ includes/js/dojox/collections/Stack.js | 72 +++++++ includes/js/dojox/collections/_base.js | 100 ++++++++++ includes/js/dojox/collections/tests/ArrayList.js | 83 ++++++++ includes/js/dojox/collections/tests/BinaryTree.js | 83 ++++++++ includes/js/dojox/collections/tests/Dictionary.js | 82 ++++++++ includes/js/dojox/collections/tests/Queue.js | 49 +++++ includes/js/dojox/collections/tests/Set.js | 35 ++++ includes/js/dojox/collections/tests/SortedList.js | 168 ++++++++++++++++ includes/js/dojox/collections/tests/Stack.js | 49 +++++ includes/js/dojox/collections/tests/_base.js | 84 ++++++++ includes/js/dojox/collections/tests/collections.js | 19 ++ includes/js/dojox/collections/tests/runTests.html | 9 + 19 files changed, 1693 insertions(+) create mode 100644 includes/js/dojox/collections/ArrayList.js create mode 100644 includes/js/dojox/collections/BinaryTree.js create mode 100644 includes/js/dojox/collections/Dictionary.js create mode 100644 includes/js/dojox/collections/Queue.js create mode 100644 includes/js/dojox/collections/README create mode 100644 includes/js/dojox/collections/Set.js create mode 100644 includes/js/dojox/collections/SortedList.js create mode 100644 includes/js/dojox/collections/Stack.js create mode 100644 includes/js/dojox/collections/_base.js create mode 100644 includes/js/dojox/collections/tests/ArrayList.js create mode 100644 includes/js/dojox/collections/tests/BinaryTree.js create mode 100644 includes/js/dojox/collections/tests/Dictionary.js create mode 100644 includes/js/dojox/collections/tests/Queue.js create mode 100644 includes/js/dojox/collections/tests/Set.js create mode 100644 includes/js/dojox/collections/tests/SortedList.js create mode 100644 includes/js/dojox/collections/tests/Stack.js create mode 100644 includes/js/dojox/collections/tests/_base.js create mode 100644 includes/js/dojox/collections/tests/collections.js create mode 100644 includes/js/dojox/collections/tests/runTests.html (limited to 'includes/js/dojox/collections') diff --git a/includes/js/dojox/collections/ArrayList.js b/includes/js/dojox/collections/ArrayList.js new file mode 100644 index 0000000..d57f6e7 --- /dev/null +++ b/includes/js/dojox/collections/ArrayList.js @@ -0,0 +1,133 @@ +if(!dojo._hasResource["dojox.collections.ArrayList"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.collections.ArrayList"] = true; +dojo.provide("dojox.collections.ArrayList"); +dojo.require("dojox.collections._base"); + +dojox.collections.ArrayList=function(/* array? */arr){ + // summary + // Returns a new object of type dojox.collections.ArrayList + var items=[]; + if(arr) items=items.concat(arr); + this.count=items.length; + this.add=function(/* object */obj){ + // summary + // Add an element to the collection. + items.push(obj); + this.count=items.length; + }; + this.addRange=function(/* array */a){ + // summary + // Add a range of objects to the ArrayList + if(a.getIterator){ + var e=a.getIterator(); + while(!e.atEnd()){ + this.add(e.get()); + } + this.count=items.length; + }else{ + for(var i=0; i=0) { + items.splice(i,1); + } + this.count=items.length; + }; + this.removeAt=function(/* int */ i){ + // summary + // return an array with function applied to all elements + items.splice(i,1); + this.count=items.length; + }; + this.reverse=function(){ + // summary + // Reverse the internal array + items.reverse(); + }; + this.sort=function(/* function? */ fn){ + // summary + // sort the internal array + if(fn){ + items.sort(fn); + }else{ + items.sort(); + } + }; + this.setByIndex=function(/* int */ i, /* object */ obj){ + // summary + // Set an element in the array by the passed index. + items[i]=obj; + this.count=items.length; + }; + this.toArray=function(){ + // summary + // Return a new array with all of the items of the internal array concatenated. + return [].concat(items); + } + this.toString=function(/* string */ delim){ + // summary + // implementation of toString, follows [].toString(); + return items.join((delim||",")); + }; +}; + +} diff --git a/includes/js/dojox/collections/BinaryTree.js b/includes/js/dojox/collections/BinaryTree.js new file mode 100644 index 0000000..edd9fbf --- /dev/null +++ b/includes/js/dojox/collections/BinaryTree.js @@ -0,0 +1,211 @@ +if(!dojo._hasResource["dojox.collections.BinaryTree"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.collections.BinaryTree"] = true; +dojo.provide("dojox.collections.BinaryTree"); +dojo.require("dojox.collections._base"); + +dojox.collections.BinaryTree=function(data){ + function node(data, rnode, lnode){ + this.value=data||null; + this.right=rnode||null; + this.left=lnode||null; + this.clone=function(){ + var c=new node(); + if(this.value.value){ + c.value=this.value.clone(); + }else{ + c.value=this.value; + } + if(this.left!=null){ + c.left=this.left.clone(); + } + if(this.right!=null){ + c.right=this.right.clone(); + } + return c; + } + this.compare=function(n){ + if(this.value>n.value){ return 1; } + if(this.valued){ return 1; } + if(this.value0){ return searchHelper(current.left, data); } + else{ return searchHelper(current.right, data); } + } + + this.add=function(data){ + var n=new node(data); + var i; + var current=root; + var parent=null; + while(current){ + i=current.compare(n); + if(i==0){ return; } + parent=current; + if(i>0){ current=current.left; } + else{ current=current.right; } + } + this.count++; + if(!parent){ + root=n; + }else{ + i=parent.compare(n); + if(i>0){ + parent.left=n; + }else{ + parent.right=n; + } + } + }; + this.clear=function(){ + root=null; + this.count=0; + }; + this.clone=function(){ + var c=new dojox.collections.BinaryTree(); + var itr=this.getIterator(); + while(!itr.atEnd()){ + c.add(itr.get()); + } + return c; + }; + this.contains=function(data){ + return this.search(data) != null; + }; + this.deleteData=function(data){ + var current=root; + var parent=null; + var i=current.compareData(data); + while(i!=0&¤t!=null){ + if(i>0){ + parent=current; + current=current.left; + }else if(i<0){ + parent=current; + current=current.right; + } + i=current.compareData(data); + } + if(!current){ return; } + this.count--; + if(!current.right){ + if(!parent){ + root=current.left; + }else{ + i=parent.compare(current); + if(i>0){ parent.left=current.left; } + else if(i<0){ parent.right=current.left; } + } + } + else if(!current.right.left){ + if(!parent){ + root=current.right; + }else{ + i=parent.compare(current); + if(i>0){ parent.left=current.right; } + else if(i<0){ parent.right=current.right; } + } + } + else{ + var leftmost=current.right.left; + var lmParent=current.right; + while(leftmost.left!=null){ + lmParent=leftmost; + leftmost=leftmost.left; + } + lmParent.left=leftmost.right; + leftmost.left=current.left; + leftmost.right=current.right; + if(!parent){ + root=leftmost; + }else{ + i=parent.compare(current); + if(i>0){ parent.left=leftmost; } + else if(i<0){ parent.right=leftmost; } + } + } + }; + this.getIterator=function(){ + var a=[]; + inorderTraversalBuildup(root, a); + return new dojox.collections.Iterator(a); + }; + this.search=function(data){ + return searchHelper(root, data); + }; + this.toString=function(order, sep){ + if(!order){ order=dojox.collections.BinaryTree.TraversalMethods.Inorder; } + if(!sep){ sep=","; } + var s=""; + switch(order){ + case dojox.collections.BinaryTree.TraversalMethods.Preorder: + s=preorderTraversal(root, sep); + break; + case dojox.collections.BinaryTree.TraversalMethods.Inorder: + s=inorderTraversal(root, sep); + break; + case dojox.collections.BinaryTree.TraversalMethods.Postorder: + s=postorderTraversal(root, sep); + break; + }; + if(s.length==0){ return ""; } + else{ return s.substring(0, s.length - sep.length); } + }; + + this.count=0; + var root=this.root=null; + if(data){ + this.add(data); + } +} +dojox.collections.BinaryTree.TraversalMethods={ + Preorder: 1, Inorder: 2, Postorder: 3 +}; + +} diff --git a/includes/js/dojox/collections/Dictionary.js b/includes/js/dojox/collections/Dictionary.js new file mode 100644 index 0000000..8213790 --- /dev/null +++ b/includes/js/dojox/collections/Dictionary.js @@ -0,0 +1,116 @@ +if(!dojo._hasResource["dojox.collections.Dictionary"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.collections.Dictionary"] = true; +dojo.provide("dojox.collections.Dictionary"); +dojo.require("dojox.collections._base"); + +dojox.collections.Dictionary=function(/* dojox.collections.Dictionary? */dictionary){ + // summary + // Returns an object of type dojox.collections.Dictionary + var items={}; + this.count=0; + + // comparator for property addition and access. + var testObject={}; + + this.add=function(/* string */k, /* object */v){ + // summary + // Add a new item to the Dictionary. + var b=(k in items); + items[k]=new dojox.collections.DictionaryEntry(k,v); + if(!b){ + this.count++; + } + }; + this.clear=function(){ + // summary + // Clears the internal dictionary. + items={}; + this.count=0; + }; + this.clone=function(){ + // summary + // Returns a new instance of dojox.collections.Dictionary; note the the dictionary is a clone but items might not be. + return new dojox.collections.Dictionary(this); // dojox.collections.Dictionary + }; + this.contains=this.containsKey=function(/* string */k){ + // summary + // Check to see if the dictionary has an entry at key "k". + if(testObject[k]){ + return false; // bool + } + return (items[k]!=null); // bool + }; + this.containsValue=function(/* object */v){ + // summary + // Check to see if the dictionary has an entry with value "v". + var e=this.getIterator(); + while(e.get()){ + if(e.element.value==v){ + return true; // bool + } + } + return false; // bool + }; + this.entry=function(/* string */k){ + // summary + // Accessor method; similar to dojox.collections.Dictionary.item but returns the actual Entry object. + return items[k]; // dojox.collections.DictionaryEntry + }; + this.forEach=function(/* function */ fn, /* object? */ scope){ + // summary + // functional iterator, following the mozilla spec. + var a=[]; // Create an indexing array + for(var p in items) { + if(!testObject[p]){ + a.push(items[p]); // fill it up + } + } + dojo.forEach(a, fn, scope); + }; + this.getKeyList=function(){ + // summary + // Returns an array of the keys in the dictionary. + return (this.getIterator()).map(function(entry){ + return entry.key; + }); // array + }; + this.getValueList=function(){ + // summary + // Returns an array of the values in the dictionary. + return (this.getIterator()).map(function(entry){ + return entry.value; + }); // array + }; + this.item=function(/* string */k){ + // summary + // Accessor method. + if(k in items){ + return items[k].valueOf(); // object + } + return undefined; // object + }; + this.getIterator=function(){ + // summary + // Gets a dojox.collections.DictionaryIterator for iteration purposes. + return new dojox.collections.DictionaryIterator(items); // dojox.collections.DictionaryIterator + }; + this.remove=function(/* string */k){ + // summary + // Removes the item at k from the internal collection. + if(k in items && !testObject[k]){ + delete items[k]; + this.count--; + return true; // bool + } + return false; // bool + }; + + if (dictionary){ + var e=dictionary.getIterator(); + while(e.get()) { + this.add(e.element.key, e.element.value); + } + } +}; + +} diff --git a/includes/js/dojox/collections/Queue.js b/includes/js/dojox/collections/Queue.js new file mode 100644 index 0000000..5fa4a5d --- /dev/null +++ b/includes/js/dojox/collections/Queue.js @@ -0,0 +1,74 @@ +if(!dojo._hasResource["dojox.collections.Queue"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.collections.Queue"] = true; +dojo.provide("dojox.collections.Queue"); +dojo.require("dojox.collections._base"); + +dojox.collections.Queue=function(/* array? */arr){ + // summary + // return an object of type dojox.collections.Queue + var q=[]; + if (arr){ + q=q.concat(arr); + } + this.count=q.length; + this.clear=function(){ + // summary + // clears the internal collection + q=[]; + this.count=q.length; + }; + this.clone=function(){ + // summary + // creates a new Queue based on this one + return new dojox.collections.Queue(q); // dojox.collections.Queue + }; + this.contains=function(/* object */ o){ + // summary + // Check to see if the passed object is an element in this queue + for(var i=0; i b.key) return 1; + if (a.key < b.key) return -1; + return 0; + }; + var build=function(){ + q=[]; + var e=_this.getIterator(); + while (!e.atEnd()){ + q.push(e.get()); + } + q.sort(sorter); + }; + var testObject={}; + + this.count=q.length; + this.add=function(/* string */ k,/* object */v){ + // summary + // add the passed value to the dictionary at location k + if (!items[k]) { + items[k]=new dojox.collections.DictionaryEntry(k,v); + this.count=q.push(items[k]); + q.sort(sorter); + } + }; + this.clear=function(){ + // summary + // clear the internal collections + items={}; + q=[]; + this.count=q.length; + }; + this.clone=function(){ + // summary + // create a clone of this sorted list + return new dojox.collections.SortedList(this); // dojox.collections.SortedList + }; + this.contains=this.containsKey=function(/* string */ k){ + // summary + // Check to see if the list has a location k + if(testObject[k]){ + return false; // bool + } + return (items[k]!=null); // bool + }; + this.containsValue=function(/* object */ o){ + // summary + // Check to see if this list contains the passed object + var e=this.getIterator(); + while (!e.atEnd()){ + var item=e.get(); + if(item.value==o){ + return true; // bool + } + } + return false; // bool + }; + this.copyTo=function(/* array */ arr, /* int */ i){ + // summary + // copy the contents of the list into array arr at index i + var e=this.getIterator(); + var idx=i; + while(!e.atEnd()){ + arr.splice(idx,0,e.get()); + idx++; + } + }; + this.entry=function(/* string */ k){ + // summary + // return the object at location k + return items[k]; // dojox.collections.DictionaryEntry + }; + this.forEach=function(/* function */ fn, /* object? */ scope){ + // summary + // functional iterator, following the mozilla spec. + dojo.forEach(q, fn, scope); + }; + this.getByIndex=function(/* int */ i){ + // summary + // return the item at index i + return q[i].valueOf(); // object + }; + this.getIterator=function(){ + // summary + // get an iterator for this object + return new dojox.collections.DictionaryIterator(items); // dojox.collections.DictionaryIterator + }; + this.getKey=function(/* int */ i){ + // summary + // return the key of the item at index i + return q[i].key; + }; + this.getKeyList=function(){ + // summary + // return an array of the keys set in this list + var arr=[]; + var e=this.getIterator(); + while (!e.atEnd()){ + arr.push(e.get().key); + } + return arr; // array + }; + this.getValueList=function(){ + // summary + // return an array of values in this list + var arr=[]; + var e=this.getIterator(); + while (!e.atEnd()){ + arr.push(e.get().value); + } + return arr; // array + }; + this.indexOfKey=function(/* string */ k){ + // summary + // return the index of the passed key. + for (var i=0; i=a.length); // bool + }; + this.get=function(){ + // summary + // Get the next member in the collection. + if(this.atEnd()){ + return null; // object + } + this.element=a[position++]; + return this.element; // object + }; + this.map=function(/* function */fn, /* object? */scope){ + // summary + // Functional iteration with optional scope. + return dojo.map(a, fn, scope); + }; + this.reset=function(){ + // summary + // reset the internal cursor. + position=0; + this.element=a[position]; + }; +} + +/* Notes: + * The DictionaryIterator no longer supports a key and value property; + * the reality is that you can use this to iterate over a JS object + * being used as a hashtable. + */ +dojox.collections.DictionaryIterator=function(/* object */obj){ + // summary + // return an object of type dojox.collections.DictionaryIterator + var a=[]; // Create an indexing array + var testObject={}; + for(var p in obj){ + if(!testObject[p]){ + a.push(obj[p]); // fill it up + } + } + var position=0; + this.element=a[position]||null; + this.atEnd=function(){ + // summary + // Test to see if the internal cursor has reached the end of the internal collection. + return (position>=a.length); // bool + }; + this.get=function(){ + // summary + // Get the next member in the collection. + if(this.atEnd()){ + return null; // object + } + this.element=a[position++]; + return this.element; // object + }; + this.map=function(/* function */fn, /* object? */scope){ + // summary + // Functional iteration with optional scope. + return dojo.map(a, fn, scope); + }; + this.reset=function() { + // summary + // reset the internal cursor. + position=0; + this.element=a[position]; + }; +}; + +} diff --git a/includes/js/dojox/collections/tests/ArrayList.js b/includes/js/dojox/collections/tests/ArrayList.js new file mode 100644 index 0000000..2645238 --- /dev/null +++ b/includes/js/dojox/collections/tests/ArrayList.js @@ -0,0 +1,83 @@ +if(!dojo._hasResource["dojox.collections.tests.ArrayList"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.collections.tests.ArrayList"] = true; +dojo.provide("dojox.collections.tests.ArrayList"); +dojo.require("dojox.collections.ArrayList"); + +tests.register("dojox.collections.tests.ArrayList", [ + function testCtor(t){ + var al=new dojox.collections.ArrayList(["foo","bar","test","bull"]); + t.assertEqual(4, al.count); + }, + function testAdd(t){ + var al=new dojox.collections.ArrayList(["foo","bar","test","bull"]); + al.add("carp"); + t.assertEqual("foo,bar,test,bull,carp", al.toString()); + al.addRange(["oof","rab"]); + t.assertEqual("foo,bar,test,bull,carp,oof,rab", al.toString()); + }, + function testClear(t){ + var al=new dojox.collections.ArrayList(["foo","bar","test","bull"]); + al.clear(); + t.assertEqual(0, al.count); + }, + function testClone(t){ + var al=new dojox.collections.ArrayList(["foo","bar","test","bull"]); + var cloned=al.clone(); + t.assertEqual(al.toString(), cloned.toString()); + }, + function testContains(t){ + var al=new dojox.collections.ArrayList(["foo","bar","test","bull"]); + t.assertTrue(al.contains("bar")); + t.assertFalse(al.contains("faz")); + }, + function testGetIterator(t){ + var al=new dojox.collections.ArrayList(["foo","bar","test","bull"]); + var itr=al.getIterator(); + while(!itr.atEnd()){ + itr.get(); + } + t.assertEqual("bull", itr.element); + }, + function testIndexOf(t){ + var al=new dojox.collections.ArrayList(["foo","bar","test","bull"]); + t.assertEqual(1, al.indexOf("bar")); + }, + function testInsert(t){ + var al=new dojox.collections.ArrayList(["foo","bar","test","bull"]); + al.insert(2, "baz"); + t.assertEqual(2, al.indexOf("baz")); + }, + function testItem(t){ + var al=new dojox.collections.ArrayList(["foo","bar","test","bull"]); + t.assertEqual("test", al.item(2)); + }, + function testRemove(t){ + var al=new dojox.collections.ArrayList(["foo","bar","test","bull"]); + al.remove("bar"); + t.assertEqual("foo,test,bull", al.toString()); + t.assertEqual(3, al.count); + }, + function testRemoveAt(t){ + var al=new dojox.collections.ArrayList(["foo","bar","test","bull"]); + al.removeAt(3); + t.assertEqual("foo,bar,test", al.toString()); + t.assertEqual(3, al.count); + }, + function testReverse(t){ + var al=new dojox.collections.ArrayList(["foo","bar","test","bull"]); + al.reverse(); + t.assertEqual("bull,test,bar,foo", al.toString()); + }, + function testSort(t){ + var al=new dojox.collections.ArrayList(["foo","bar","test","bull"]); + al.sort(); + t.assertEqual("bar,bull,foo,test", al.toString()); + }, + function testToArray(t){ + var al=new dojox.collections.ArrayList(["foo","bar","test","bull"]); + var a=al.toArray(); + t.assertEqual(a.join(","), al.toString()); + } +]); + +} diff --git a/includes/js/dojox/collections/tests/BinaryTree.js b/includes/js/dojox/collections/tests/BinaryTree.js new file mode 100644 index 0000000..48acaa4 --- /dev/null +++ b/includes/js/dojox/collections/tests/BinaryTree.js @@ -0,0 +1,83 @@ +if(!dojo._hasResource["dojox.collections.tests.BinaryTree"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.collections.tests.BinaryTree"] = true; +dojo.provide("dojox.collections.tests.BinaryTree"); +dojo.require("dojox.collections.BinaryTree"); + +tests.register("dojox.collections.tests.BinaryTree", [ + function testCtor(t){ + var bt=new dojox.collections.BinaryTree("foo"); + t.assertTrue(bt instanceof dojox.collections.BinaryTree); + }, + function testAdd(t){ + var bt=new dojox.collections.BinaryTree("foo"); + bt.add("bar"); + bt.add("baz"); + bt.add("buck"); + bt.add("shot"); + bt.add("apple"); + t.assertEqual("apple,bar,baz,buck,foo,shot",bt.toString()); + }, + function testClear(t){ + var bt=new dojox.collections.BinaryTree("foo"); + bt.add("bar"); + bt.add("baz"); + bt.add("buck"); + bt.add("shot"); + bt.add("apple"); + bt.clear(); + t.assertEqual(bt.count, 0); + }, + function testClone(t){ + var bt=new dojox.collections.BinaryTree("foo"); + bt.add("bar"); + bt.add("baz"); + bt.add("buck"); + bt.add("shot"); + bt.add("apple"); + var bt2=bt.clone(); + t.assertEqual(bt2.count, 6); + t.assertEqual(bt.toString(), bt2.toString()); + }, + function testContains(t){ + var bt=new dojox.collections.BinaryTree("foo"); + bt.add("bar"); + bt.add("baz"); + bt.add("buck"); + bt.add("shot"); + bt.add("apple"); + t.assertTrue(bt.contains("buck")); + t.assertFalse(bt.contains("duck")); + }, + function testDeleteData(t){ + var bt=new dojox.collections.BinaryTree("foo"); + bt.add("bar"); + bt.add("baz"); + bt.add("buck"); + bt.add("shot"); + bt.add("apple"); + bt.deleteData("buck"); + t.assertEqual("apple,bar,baz,foo,shot",bt.toString()); + }, + function testGetIterator(t){ + var bt=new dojox.collections.BinaryTree("foo"); + bt.add("bar"); + bt.add("baz"); + bt.add("buck"); + bt.add("shot"); + bt.add("apple"); + var itr=bt.getIterator(); + while(!itr.atEnd()){ itr.get(); } + t.assertEqual("shot", itr.element); + }, + function testSearch(t){ + var bt=new dojox.collections.BinaryTree("foo"); + bt.add("bar"); + bt.add("baz"); + bt.add("buck"); + bt.add("shot"); + bt.add("apple"); + t.assertEqual("buck", bt.search("buck").value); + } +]); + +} diff --git a/includes/js/dojox/collections/tests/Dictionary.js b/includes/js/dojox/collections/tests/Dictionary.js new file mode 100644 index 0000000..7bde6ee --- /dev/null +++ b/includes/js/dojox/collections/tests/Dictionary.js @@ -0,0 +1,82 @@ +if(!dojo._hasResource["dojox.collections.tests.Dictionary"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.collections.tests.Dictionary"] = true; +dojo.provide("dojox.collections.tests.Dictionary"); +dojo.require("dojox.collections.Dictionary"); + +tests.register("dojox.collections.tests.Dictionary", [ + function testCtor(t){ + var d=new dojox.collections.Dictionary(); + t.assertTrue(d instanceof dojox.collections.Dictionary); + }, + function testAdd(t){ + var d=new dojox.collections.Dictionary(); + d.add("foo","bar"); + t.assertEqual("bar", d.item("foo").valueOf()); + }, + function testClear(t){ + var d=new dojox.collections.Dictionary(); + d.add("foo","bar"); + d.clear() + t.assertEqual(0, d.count); + }, + function testClone(t){ + var d=new dojox.collections.Dictionary(); + d.add("baz","fab"); + d.add("buck","shot"); + d.add("apple","orange"); + var d2 = d.clone(); + t.assertTrue(d2.contains("baz")); + }, + function testContains(t){ + var d=new dojox.collections.Dictionary(); + d.add("foo","bar"); + d.add("baz","fab"); + d.add("buck","shot"); + d.add("apple","orange"); + t.assertTrue(d.contains("baz")); + }, + function testContainsKey(t){ + var d=new dojox.collections.Dictionary(); + d.add("foo","bar"); + d.add("baz","fab"); + d.add("buck","shot"); + d.add("apple","orange"); + t.assertTrue(d.containsKey("buck")); + }, + function testContainsValue(t){ + var d=new dojox.collections.Dictionary(); + d.add("foo","bar"); + d.add("baz","fab"); + d.add("buck","shot"); + d.add("apple","orange"); + t.assertTrue(d.containsValue("shot")); + }, + function testGetKeyList(t){ + var d=new dojox.collections.Dictionary(); + d.add("foo","bar"); + d.add("baz","fab"); + d.add("buck","shot"); + d.add("apple","orange"); + t.assertEqual("foo,baz,buck,apple", d.getKeyList().join(",")); + }, + function testGetValueList(t){ + var d=new dojox.collections.Dictionary(); + d.add("foo","bar"); + d.add("baz","fab"); + d.add("buck","shot"); + d.add("apple","orange"); + t.assertEqual("bar,fab,shot,orange", d.getValueList().join(",")); + }, + function testRemove(t){ + var d=new dojox.collections.Dictionary(); + d.add("foo","bar"); + d.add("baz","fab"); + d.add("buck","shot"); + d.add("apple","orange"); + d.remove("baz"); + t.assertEqual(3, d.count); + t.assertEqual(undefined, d.item("baz")); + } +]); + +} diff --git a/includes/js/dojox/collections/tests/Queue.js b/includes/js/dojox/collections/tests/Queue.js new file mode 100644 index 0000000..5ac61bc --- /dev/null +++ b/includes/js/dojox/collections/tests/Queue.js @@ -0,0 +1,49 @@ +if(!dojo._hasResource["dojox.collections.tests.Queue"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.collections.tests.Queue"] = true; +dojo.provide("dojox.collections.tests.Queue"); +dojo.require("dojox.collections.Queue"); + +tests.register("dojox.collections.tests.Queue", [ + function testCtor(t){ + var q=new dojox.collections.Queue(["foo","bar","test","bull"]); + t.assertEqual(4, q.count); + }, + function testClear(t){ + var q=new dojox.collections.Queue(["foo","bar","test","bull"]); + q.clear(); + t.assertEqual(0, q.count); + }, + function testClone(t){ + var q=new dojox.collections.Queue(["foo","bar","test","bull"]); + var cloned=q.clone(); + t.assertEqual(q.count, cloned.count); + t.assertEqual(q.toArray().join(), cloned.toArray().join()); + }, + function testContains(t){ + var q=new dojox.collections.Queue(["foo","bar","test","bull"]); + t.assertTrue(q.contains("bar")); + t.assertFalse(q.contains("faz")); + }, + function testGetIterator(t){ + var q=new dojox.collections.Queue(["foo","bar","test","bull"]); + var itr=q.getIterator(); + while(!itr.atEnd()){ itr.get(); } + t.assertEqual("bull", itr.element); + }, + function testPeek(t){ + var q=new dojox.collections.Queue(["foo","bar","test","bull"]); + t.assertEqual("foo", q.peek()); + }, + function testDequeue(t){ + var q=new dojox.collections.Queue(["foo","bar","test","bull"]); + t.assertEqual("foo", q.dequeue()); + t.assertEqual("bar,test,bull", q.toArray().join(",")); + }, + function testEnqueue(t){ + var q=new dojox.collections.Queue(["foo","bar","test","bull"]); + q.enqueue("bull"); + t.assertEqual("bull", q.toArray().pop()); + } +]); + +} diff --git a/includes/js/dojox/collections/tests/Set.js b/includes/js/dojox/collections/tests/Set.js new file mode 100644 index 0000000..d548223 --- /dev/null +++ b/includes/js/dojox/collections/tests/Set.js @@ -0,0 +1,35 @@ +if(!dojo._hasResource["dojox.collections.tests.Set"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.collections.tests.Set"] = true; +dojo.provide("dojox.collections.tests.Set"); +dojo.require("dojox.collections.Set"); + +(function(){ + var dxcs=dojox.collections.Set; + var a = ["apple","bear","candy","donut","epiphite","frank"]; + var b = ["bear","epiphite","google","happy","joy"]; + tests.register("dojox.collections.tests.Set", [ + function testUnion(t){ + var union=dxcs.union(a,b); + t.assertEqual("apple,bear,candy,donut,epiphite,frank,google,happy,joy", union.toArray().join(',')); + }, + function testIntersection(t){ + var itsn=dxcs.intersection(a,b); + t.assertEqual("bear,epiphite", itsn.toArray().join(",")); + t.assertEqual("bear", dxcs.intersection(["bear","apple"], ["bear"])); + }, + function testDifference(t){ + var d=dxcs.difference(a,b); + t.assertEqual("apple,candy,donut,frank",d.toArray().join(',')); + }, + function testIsSubSet(t){ + t.assertFalse(dxcs.isSubSet(a,["bear","candy"])); + t.assertTrue(dxcs.isSubSet(["bear","candy"],a)); + }, + function testIsSuperSet(t){ + t.assertTrue(dxcs.isSuperSet(a,["bear","candy"])); + t.assertFalse(dxcs.isSuperSet(["bear","candy"],a)); + } + ]); +})(); + +} diff --git a/includes/js/dojox/collections/tests/SortedList.js b/includes/js/dojox/collections/tests/SortedList.js new file mode 100644 index 0000000..dfb4ffa --- /dev/null +++ b/includes/js/dojox/collections/tests/SortedList.js @@ -0,0 +1,168 @@ +if(!dojo._hasResource["dojox.collections.tests.SortedList"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.collections.tests.SortedList"] = true; +dojo.provide("dojox.collections.tests.SortedList"); +dojo.require("dojox.collections.SortedList"); + +tests.register("dojox.collections.tests.SortedList", [ + function testCtor(t){ + var sl=new dojox.collections.SortedList(); + t.assertTrue(sl instanceof dojox.collections.SortedList); + }, + function testAdd(t){ + var sl=new dojox.collections.SortedList(); + sl.add("foo","bar"); + t.assertEqual("bar", sl.item("foo").valueOf()); + }, + function testClear(t){ + var sl=new dojox.collections.SortedList(); + sl.add("foo","bar"); + sl.clear(); + t.assertEqual(0, sl.count); + }, + function testClone(t){ + var sl=new dojox.collections.SortedList(); + sl.add("foo","bar"); + sl.add("baz","fab"); + sl.add("buck","shot"); + sl.add("apple","orange"); + var sl2=sl.clone(); + t.assertTrue(sl2.contains("baz")); + }, + function testContains(t){ + var sl=new dojox.collections.SortedList(); + sl.add("foo","bar"); + sl.add("baz","fab"); + sl.add("buck","shot"); + sl.add("apple","orange"); + t.assertTrue(sl.contains("baz")); + t.assertFalse(sl.contains("faz")); + }, + function testContainsKey(t){ + var sl=new dojox.collections.SortedList(); + sl.add("foo","bar"); + sl.add("baz","fab"); + sl.add("buck","shot"); + sl.add("apple","orange"); + t.assertTrue(sl.containsKey("buck")); + t.assertFalse(sl.containsKey("faz")); + }, + function testContainsValue(t){ + var sl=new dojox.collections.SortedList(); + sl.add("foo","bar"); + sl.add("baz","fab"); + sl.add("buck","shot"); + sl.add("apple","orange"); + t.assertTrue(sl.containsValue("shot")); + t.assertFalse(sl.containsValue("faz")); + }, + function testGetKeyList(t){ + var sl=new dojox.collections.SortedList(); + sl.add("foo","bar"); + sl.add("baz","fab"); + sl.add("buck","shot"); + sl.add("apple","orange"); + t.assertEqual("foo,baz,buck,apple",sl.getKeyList().join(',')); + }, + function testGetValueList(t){ + var sl=new dojox.collections.SortedList(); + sl.add("foo","bar"); + sl.add("baz","fab"); + sl.add("buck","shot"); + sl.add("apple","orange"); + t.assertEqual("bar,fab,shot,orange",sl.getValueList().join(',')); + }, + function testCopyTo(t){ + var sl=new dojox.collections.SortedList(); + sl.add("foo","bar"); + sl.add("baz","fab"); + sl.add("buck","shot"); + sl.add("apple","orange"); + var arr=["bek"]; + sl.copyTo(arr,0); + t.assertEqual("bar,fab,shot,orange,bek", arr.join(',')); + }, + function testGetByIndex(t){ + var sl=new dojox.collections.SortedList(); + sl.add("foo","bar"); + sl.add("baz","fab"); + sl.add("buck","shot"); + sl.add("apple","orange"); + t.assertEqual("shot", sl.getByIndex(2)); + }, + function testGetKey(t){ + var sl=new dojox.collections.SortedList(); + sl.add("foo","bar"); + sl.add("baz","fab"); + sl.add("buck","shot"); + sl.add("apple","orange"); + t.assertEqual("apple", sl.getKey(0)); + }, + function testIndexOfKey(t){ + var sl=new dojox.collections.SortedList(); + sl.add("foo","bar"); + sl.add("baz","fab"); + sl.add("buck","shot"); + sl.add("apple","orange"); + t.assertEqual(0, sl.indexOfKey("apple")); + }, + function testIndexOfValue(t){ + var sl=new dojox.collections.SortedList(); + sl.add("foo","bar"); + sl.add("baz","fab"); + sl.add("buck","shot"); + sl.add("apple","orange"); + t.assertEqual(3, sl.indexOfValue("bar")); + }, + function testRemove(t){ + var sl=new dojox.collections.SortedList(); + sl.add("foo","bar"); + sl.add("baz","fab"); + sl.add("buck","shot"); + sl.add("apple","orange"); + sl.remove("baz"); + t.assertEqual(3, sl.count); + t.assertEqual(undefined, sl.item("baz")); + }, + function testRemoveAt(t){ + var sl=new dojox.collections.SortedList(); + sl.add("foo","bar"); + sl.add("baz","fab"); + sl.add("buck","shot"); + sl.add("apple","orange"); + sl.removeAt(2); + t.assertEqual(undefined, sl.item("buck")); + }, + function testReplace(t){ + var sl=new dojox.collections.SortedList(); + sl.add("foo","bar"); + sl.add("baz","fab"); + sl.add("buck","shot"); + sl.add("apple","orange"); + sl.replace("buck","dollar"); + t.assertEqual(sl.item("buck").valueOf(), "dollar"); + }, + function testSetByIndex(t){ + var sl=new dojox.collections.SortedList(); + sl.add("foo","bar"); + sl.add("baz","fab"); + sl.add("buck","shot"); + sl.add("apple","orange"); + sl.setByIndex(0, "bar"); + t.assertEqual("bar", sl.getByIndex(0)); + }, + function testSorting(t){ + var sl=new dojox.collections.SortedList(); + sl.add("foo","bar"); + sl.add("baz","fab"); + sl.add("buck","shot"); + sl.add("apple","orange"); + + var a=[]; + sl.forEach(function(item){ + a.push(item); + }); + t.assertEqual("orange,fab,shot,bar", a.join()); + } +]); + +} diff --git a/includes/js/dojox/collections/tests/Stack.js b/includes/js/dojox/collections/tests/Stack.js new file mode 100644 index 0000000..7bf4e79 --- /dev/null +++ b/includes/js/dojox/collections/tests/Stack.js @@ -0,0 +1,49 @@ +if(!dojo._hasResource["dojox.collections.tests.Stack"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.collections.tests.Stack"] = true; +dojo.provide("dojox.collections.tests.Stack"); +dojo.require("dojox.collections.Stack"); + +tests.register("dojox.collections.tests.Stack", [ + function testCtor(t){ + var s=new dojox.collections.Stack(["foo","bar","test","bull"]); + t.assertEqual(4, s.count); + }, + function testClear(t){ + var s=new dojox.collections.Stack(["foo","bar","test","bull"]); + s.clear(); + t.assertEqual(0, s.count); + }, + function testClone(t){ + var s=new dojox.collections.Stack(["foo","bar","test","bull"]); + var cloned=s.clone(); + t.assertEqual(s.count, cloned.count); + t.assertEqual(s.toArray().join(), cloned.toArray().join()); + }, + function testContains(t){ + var s=new dojox.collections.Stack(["foo","bar","test","bull"]); + t.assertTrue(s.contains("bar")); + t.assertFalse(s.contains("faz")); + }, + function testGetIterator(t){ + var s=new dojox.collections.Stack(["foo","bar","test","bull"]); + var itr=s.getIterator(); + while(!itr.atEnd()){ itr.get(); } + t.assertEqual("bull", itr.element); + }, + function testPeek(t){ + var s=new dojox.collections.Stack(["foo","bar","test","bull"]); + t.assertEqual("bull", s.peek()); + }, + function testPop(t){ + var s=new dojox.collections.Stack(["foo","bar","test","bull"]); + t.assertEqual("bull", s.pop()); + t.assertEqual("test", s.pop()); + }, + function testPush(t){ + var s=new dojox.collections.Stack(["foo","bar","test","bull"]); + s.push("bug"); + t.assertEqual("bug", s.peek()); + } +]); + +} diff --git a/includes/js/dojox/collections/tests/_base.js b/includes/js/dojox/collections/tests/_base.js new file mode 100644 index 0000000..f58a82c --- /dev/null +++ b/includes/js/dojox/collections/tests/_base.js @@ -0,0 +1,84 @@ +if(!dojo._hasResource["dojox.collections.tests._base"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.collections.tests._base"] = true; +dojo.provide("dojox.collections.tests._base"); +dojo.require("dojox.collections"); + +tests.register("dojox.collections.tests._base", [ + function testDictionaryEntry(t){ + var d=new dojox.collections.DictionaryEntry("foo","bar"); + t.assertEqual("bar", d.valueOf()); + t.assertEqual("bar", d.toString()); + }, + + function testIterator(t){ + var itr=new dojox.collections.Iterator(["foo","bar","baz","zoo"]); + t.assertEqual("foo", itr.element); // test initialization + t.assertTrue(!itr.atEnd()); + t.assertEqual("foo", itr.get()); // make sure the first get doesn't advance. + t.assertEqual("bar", itr.get()); + t.assertEqual("baz", itr.get()); + t.assertEqual("zoo", itr.get()); + t.assertTrue(itr.atEnd()); + t.assertEqual(null, itr.get()); + + itr.reset(); + t.assertTrue(!itr.atEnd()); + t.assertEqual("foo", itr.element); + + // test map + var a=itr.map(function(elm){ + return elm+"-mapped"; + }); + itr=new dojox.collections.Iterator(a); + t.assertEqual("foo-mapped", itr.element); // test initialization + t.assertTrue(!itr.atEnd()); + t.assertEqual("foo-mapped", itr.get()); // make sure the first get doesn't advance. + t.assertEqual("bar-mapped", itr.get()); + t.assertEqual("baz-mapped", itr.get()); + t.assertEqual("zoo-mapped", itr.get()); + t.assertTrue(itr.atEnd()); + t.assertEqual(null, itr.get()); + }, + + function testDictionaryIterator(t){ + /* + in the context of any of the Dictionary-based collections, the + element would normally return a DictionaryEntry. However, since + the DictionaryIterator is really an iterator of pure objects, + we will just test with an object here. This means all property + names are lost in the translation, but...that's why there's a + DictionaryEntry object :) + */ + var itr=new dojox.collections.DictionaryIterator({ + first:"foo", second:"bar", third:"baz", fourth:"zoo" + }); + t.assertEqual("foo", itr.element); // test initialization + t.assertTrue(!itr.atEnd()); + t.assertEqual("foo", itr.get()); // make sure the first get doesn't advance. + t.assertEqual("bar", itr.get()); + t.assertEqual("baz", itr.get()); + t.assertEqual("zoo", itr.get()); + t.assertTrue(itr.atEnd()); + t.assertEqual(null, itr.get()); + + itr.reset(); + t.assertTrue(!itr.atEnd()); + t.assertEqual("foo", itr.element); + + // test map + var a=itr.map(function(elm){ + return elm+"-mapped"; + }); + itr=new dojox.collections.Iterator(a); + t.assertEqual("foo-mapped", itr.element); // test initialization + t.assertTrue(!itr.atEnd()); + t.assertEqual("foo-mapped", itr.get()); // make sure the first get doesn't advance. + t.assertEqual("bar-mapped", itr.get()); + t.assertEqual("baz-mapped", itr.get()); + t.assertEqual("zoo-mapped", itr.get()); + t.assertTrue(itr.atEnd()); + t.assertEqual(null, itr.get()); + } +]); + +} diff --git a/includes/js/dojox/collections/tests/collections.js b/includes/js/dojox/collections/tests/collections.js new file mode 100644 index 0000000..4fb2634 --- /dev/null +++ b/includes/js/dojox/collections/tests/collections.js @@ -0,0 +1,19 @@ +if(!dojo._hasResource["dojox.collections.tests.collections"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.collections.tests.collections"] = true; +dojo.provide("dojox.collections.tests.collections"); +dojo.require("dojox.collections"); + +try{ + dojo.require("dojox.collections.tests._base"); + dojo.require("dojox.collections.tests.ArrayList"); + dojo.require("dojox.collections.tests.BinaryTree"); + dojo.require("dojox.collections.tests.Dictionary"); + dojo.require("dojox.collections.tests.Queue"); + dojo.require("dojox.collections.tests.Set"); + dojo.require("dojox.collections.tests.SortedList"); + dojo.require("dojox.collections.tests.Stack"); +}catch(e){ + doh.debug(e); +} + +} diff --git a/includes/js/dojox/collections/tests/runTests.html b/includes/js/dojox/collections/tests/runTests.html new file mode 100644 index 0000000..37f26a6 --- /dev/null +++ b/includes/js/dojox/collections/tests/runTests.html @@ -0,0 +1,9 @@ + + + + Dojox.wire Unit Test Runner + + + Redirecting to D.O.H runner. + + -- cgit v1.2.3