Browse Source

test collection size in base

Herbert Vojčík 11 years ago
parent
commit
ebbe2e345a
2 changed files with 106 additions and 74 deletions
  1. 83 55
      js/Kernel-Tests.js
  2. 23 19
      st/Kernel-Tests.st

+ 83 - 55
js/Kernel-Tests.js

@@ -1302,6 +1302,22 @@ referencedClasses: []
 }),
 smalltalk.CollectionTest);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "collectionSize",
+protocol: 'fixture',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+self._subclassResponsibility();
+return self}, function($ctx1) {$ctx1.fill(self,"collectionSize",{},smalltalk.CollectionTest)})},
+args: [],
+source: "collectionSize\x0a\x09\x22Answers size of self collection.\x22\x0a\x0a\x09self subclassResponsibility",
+messageSends: ["subclassResponsibility"],
+referencedClasses: []
+}),
+smalltalk.CollectionTest);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "collectionWithDuplicates",
@@ -1800,11 +1816,11 @@ $1=_st(_st(self._collectionClass())._new())._size();
 $ctx1.sendIdx["size"]=1;
 self._assert_equals_($1,(0));
 $ctx1.sendIdx["assert:equals:"]=1;
-self._assert_equals_(_st(self._collection())._size(),(4));
+self._assert_equals_(_st(self._collection())._size(),self._collectionSize());
 return self}, function($ctx1) {$ctx1.fill(self,"testSize",{},smalltalk.CollectionTest)})},
 args: [],
-source: "testSize\x0a\x09self assert: self collectionClass new size equals: 0.\x0a\x09self assert: self collection size equals: 4",
-messageSends: ["assert:equals:", "size", "new", "collectionClass", "collection"],
+source: "testSize\x0a\x09self assert: self collectionClass new size equals: 0.\x0a\x09self assert: self collection size equals: self collectionSize",
+messageSends: ["assert:equals:", "size", "new", "collectionClass", "collection", "collectionSize"],
 referencedClasses: []
 }),
 smalltalk.CollectionTest);
@@ -2212,6 +2228,22 @@ referencedClasses: []
 }),
 smalltalk.HashedCollectionTest);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "collectionSize",
+protocol: 'fixture',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return (4);
+}, function($ctx1) {$ctx1.fill(self,"collectionSize",{},smalltalk.HashedCollectionTest)})},
+args: [],
+source: "collectionSize\x0a\x09^ 4",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.HashedCollectionTest);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "collectionWithDuplicates",
@@ -2433,6 +2465,22 @@ referencedClasses: ["Dictionary"]
 }),
 smalltalk.DictionaryTest);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "collectionSize",
+protocol: 'fixture',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return (4);
+}, function($ctx1) {$ctx1.fill(self,"collectionSize",{},smalltalk.DictionaryTest)})},
+args: [],
+source: "collectionSize\x0a\x09^ 4",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.DictionaryTest);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "collectionWithDuplicates",
@@ -2870,37 +2918,6 @@ referencedClasses: ["Dictionary"]
 }),
 smalltalk.DictionaryTest);
 
-smalltalk.addMethod(
-smalltalk.method({
-selector: "testSize",
-protocol: 'tests',
-fn: function (){
-var self=this;
-var d;
-function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
-return smalltalk.withContext(function($ctx1) { 
-var $1,$2;
-d=_st($Dictionary())._new();
-$1=_st(d)._size();
-$ctx1.sendIdx["size"]=1;
-self._assert_equals_($1,(0));
-$ctx1.sendIdx["assert:equals:"]=1;
-_st(d)._at_put_((1),(2));
-$ctx1.sendIdx["at:put:"]=1;
-$2=_st(d)._size();
-$ctx1.sendIdx["size"]=2;
-self._assert_equals_($2,(1));
-$ctx1.sendIdx["assert:equals:"]=2;
-_st(d)._at_put_((2),(3));
-self._assert_equals_(_st(d)._size(),(2));
-return self}, function($ctx1) {$ctx1.fill(self,"testSize",{d:d},smalltalk.DictionaryTest)})},
-args: [],
-source: "testSize\x0a\x09| d |\x0a\x0a\x09d := Dictionary new.\x0a\x09self assert: d size equals: 0.\x0a\x0a\x09d at: 1 put: 2.\x0a\x09self assert: d size equals: 1.\x0a\x0a\x09d at: 2 put: 3.\x0a\x09self assert: d size equals: 2.",
-messageSends: ["new", "assert:equals:", "size", "at:put:"],
-referencedClasses: ["Dictionary"]
-}),
-smalltalk.DictionaryTest);
-
 smalltalk.addMethod(
 smalltalk.method({
 selector: "testValues",
@@ -3386,6 +3403,22 @@ referencedClasses: []
 }),
 smalltalk.ArrayTest);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "collectionSize",
+protocol: 'fixture',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return (4);
+}, function($ctx1) {$ctx1.fill(self,"collectionSize",{},smalltalk.ArrayTest)})},
+args: [],
+source: "collectionSize\x0a\x09^ 4",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.ArrayTest);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "collectionWithDuplicates",
@@ -3778,6 +3811,22 @@ referencedClasses: []
 }),
 smalltalk.StringTest);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "collectionSize",
+protocol: 'fixture',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return (5);
+}, function($ctx1) {$ctx1.fill(self,"collectionSize",{},smalltalk.StringTest)})},
+args: [],
+source: "collectionSize\x0a\x09^ 5",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.StringTest);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "collectionWithDuplicates",
@@ -4322,27 +4371,6 @@ referencedClasses: []
 }),
 smalltalk.StringTest);
 
-smalltalk.addMethod(
-smalltalk.method({
-selector: "testSize",
-protocol: 'tests',
-fn: function (){
-var self=this;
-return smalltalk.withContext(function($ctx1) { 
-var $1;
-$1="smalltalk"._size();
-$ctx1.sendIdx["size"]=1;
-self._assert_equals_($1,(9));
-$ctx1.sendIdx["assert:equals:"]=1;
-self._assert_equals_(""._size(),(0));
-return self}, function($ctx1) {$ctx1.fill(self,"testSize",{},smalltalk.StringTest)})},
-args: [],
-source: "testSize\x0a\x09self assert: 'smalltalk' size equals: 9.\x0a\x09self assert: '' size equals: 0",
-messageSends: ["assert:equals:", "size"],
-referencedClasses: []
-}),
-smalltalk.StringTest);
-
 smalltalk.addMethod(
 smalltalk.method({
 selector: "testStreamContents",

+ 23 - 19
st/Kernel-Tests.st

@@ -404,6 +404,12 @@ collectionClass
 	^ self class collectionClass
 !
 
+collectionSize
+	"Answers size of self collection."
+
+	self subclassResponsibility
+!
+
 collectionWithDuplicates
 	"Answers pre-filled collection of type tested,
 	with exactly five distinct elements,
@@ -541,7 +547,7 @@ testSelect
 
 testSize
 	self assert: self collectionClass new size equals: 0.
-	self assert: self collection size equals: 4
+	self assert: self collection size equals: self collectionSize
 ! !
 
 !CollectionTest class methodsFor: 'fixture'!
@@ -677,6 +683,10 @@ collection
 	^ #{ 'b' -> 1. 'a' -> 2. 'c' -> 3. 'd' -> -4 }
 !
 
+collectionSize
+	^ 4
+!
+
 collectionWithDuplicates
 	^ #{ 'b' -> 1. 'a' -> 2. 'c' -> 3. 'd' -> -4. 'e' -> 1. 'f' -> 2. 'g' -> 10 }
 !
@@ -739,6 +749,10 @@ collection
 		yourself
 !
 
+collectionSize
+	^ 4
+!
+
 collectionWithDuplicates
 	^ Dictionary new
 		at: 1 put: 1;
@@ -889,19 +903,6 @@ testRemoveKeyIfAbsent
 	self assert: (d removeKey: key ifAbsent: [ 42 ] ) equals: 42.
 !
 
-testSize
-	| d |
-
-	d := Dictionary new.
-	self assert: d size equals: 0.
-
-	d at: 1 put: 2.
-	self assert: d size equals: 1.
-
-	d at: 2 put: 3.
-	self assert: d size equals: 2.
-!
-
 testValues
 	| d |
 
@@ -1046,6 +1047,10 @@ collectionLastTwo
 	^ #(3 -4)
 !
 
+collectionSize
+	^ 4
+!
+
 collectionWithDuplicates
 	^ #('a' 'b' 'c' 1 2 1 'a')
 !
@@ -1169,6 +1174,10 @@ collectionLastTwo
 	^ 'lo'
 !
 
+collectionSize
+	^ 5
+!
+
 collectionWithDuplicates
 	^ 'abbaerte'
 !
@@ -1324,11 +1333,6 @@ testSelect
 		as: newCollection
 !
 
-testSize
-	self assert: 'smalltalk' size equals: 9.
-	self assert: '' size equals: 0
-!
-
 testStreamContents
 	self
 		assert: (String streamContents: [ :aStream |