1
0
Kaynağa Gözat

Collection >> testContains is generic

Herbert Vojčík 11 yıl önce
ebeveyn
işleme
9f071e04cd
2 değiştirilmiş dosya ile 41 ekleme ve 89 silme
  1. 34 73
      js/Kernel-Tests.js
  2. 7 16
      st/Kernel-Tests.st

+ 34 - 73
js/Kernel-Tests.js

@@ -1464,6 +1464,40 @@ referencedClasses: []
 }),
 smalltalk.CollectionTest);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "testContains",
+category: 'tests',
+fn: function (){
+var self=this;
+var anyOne;
+function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
+return smalltalk.withContext(function($ctx1) { 
+var $1,$3,$2;
+$1=self._collection();
+$ctx1.sendIdx["collection"]=1;
+anyOne=_st($1)._anyOne();
+$3=self._collection();
+$ctx1.sendIdx["collection"]=2;
+$2=_st($3)._contains_((function(each){
+return smalltalk.withContext(function($ctx2) {
+return _st(each).__eq(anyOne);
+$ctx2.sendIdx["="]=1;
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
+$ctx1.sendIdx["contains:"]=1;
+self._assert_($2);
+self._deny_(_st(self._collection())._contains_((function(each){
+return smalltalk.withContext(function($ctx2) {
+return _st(each).__eq(_st($Object())._new());
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)})})));
+return self}, function($ctx1) {$ctx1.fill(self,"testContains",{anyOne:anyOne},smalltalk.CollectionTest)})},
+args: [],
+source: "testContains\x0a\x09| anyOne |\x0a\x09anyOne := self collection anyOne.\x0a\x09self assert: (self collection contains: [ :each | each = anyOne ]).\x0a\x09self deny: (self collection contains: [ :each | each = Object new ])",
+messageSends: ["anyOne", "collection", "assert:", "contains:", "=", "deny:", "new"],
+referencedClasses: ["Object"]
+}),
+smalltalk.CollectionTest);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "testDetect",
@@ -1792,42 +1826,6 @@ referencedClasses: []
 }),
 smalltalk.IndexableCollectionTest);
 
-smalltalk.addMethod(
-smalltalk.method({
-selector: "testContains",
-category: 'tests',
-fn: function (){
-var self=this;
-var collection;
-function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
-return smalltalk.withContext(function($ctx1) { 
-var $2,$4,$3,$1;
-collection=self._collection();
-$ctx1.sendIdx["collection"]=1;
-$2=self._collection();
-$ctx1.sendIdx["collection"]=2;
-$1=_st($2)._contains_((function(each){
-return smalltalk.withContext(function($ctx2) {
-$4=self._collection();
-$ctx2.sendIdx["collection"]=3;
-$3=_st($4)._first();
-return _st(each).__eq($3);
-$ctx2.sendIdx["="]=1;
-}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
-$ctx1.sendIdx["contains:"]=1;
-self._assert_($1);
-self._deny_(_st(self._collection())._contains_((function(each){
-return smalltalk.withContext(function($ctx2) {
-return _st(each).__eq(_st($Object())._new());
-}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)})})));
-return self}, function($ctx1) {$ctx1.fill(self,"testContains",{collection:collection},smalltalk.IndexableCollectionTest)})},
-args: [],
-source: "testContains\x0a\x09| collection |\x0a\x09collection := self collection.\x0a\x09\x0a\x09self assert: (self collection contains: [ :each | each = self collection first ]).\x0a\x09self deny: (self collection contains: [ :each | each = Object new ])",
-messageSends: ["collection", "assert:", "contains:", "=", "first", "deny:", "new"],
-referencedClasses: ["Object"]
-}),
-smalltalk.IndexableCollectionTest);
-
 smalltalk.addMethod(
 smalltalk.method({
 selector: "testIndexOf",
@@ -1983,43 +1981,6 @@ referencedClasses: ["Error"]
 }),
 smalltalk.HashedCollectionTest);
 
-smalltalk.addMethod(
-smalltalk.method({
-selector: "testContains",
-category: 'tests',
-fn: function (){
-var self=this;
-var collection;
-function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
-return smalltalk.withContext(function($ctx1) { 
-var $2,$5,$4,$3,$1;
-collection=self._collection();
-$ctx1.sendIdx["collection"]=1;
-$2=self._collection();
-$ctx1.sendIdx["collection"]=2;
-$1=_st($2)._contains_((function(each){
-return smalltalk.withContext(function($ctx2) {
-$5=self._collection();
-$ctx2.sendIdx["collection"]=3;
-$4=_st($5)._values();
-$3=_st($4)._first();
-return _st(each).__eq($3);
-$ctx2.sendIdx["="]=1;
-}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
-$ctx1.sendIdx["contains:"]=1;
-self._assert_($1);
-self._deny_(_st(self._collection())._contains_((function(each){
-return smalltalk.withContext(function($ctx2) {
-return _st(each).__eq(_st($Object())._new());
-}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)})})));
-return self}, function($ctx1) {$ctx1.fill(self,"testContains",{collection:collection},smalltalk.HashedCollectionTest)})},
-args: [],
-source: "testContains\x0a\x09| collection |\x0a\x09collection := self collection.\x0a\x09\x0a\x09self assert: (self collection contains: [ :each | each = self collection values first ]).\x0a\x09self deny: (self collection contains: [ :each | each = Object new ])",
-messageSends: ["collection", "assert:", "contains:", "=", "first", "values", "deny:", "new"],
-referencedClasses: ["Object"]
-}),
-smalltalk.HashedCollectionTest);
-
 smalltalk.addMethod(
 smalltalk.method({
 selector: "testFrom",

+ 7 - 16
st/Kernel-Tests.st

@@ -451,6 +451,13 @@ testCollect
 		as: newCollection
 !
 
+testContains
+	| anyOne |
+	anyOne := self collection anyOne.
+	self assert: (self collection contains: [ :each | each = anyOne ]).
+	self deny: (self collection contains: [ :each | each = Object new ])
+!
+
 testDetect
 	self assert: (self collection detect: [ :each | each < 0 ]) equals: -4.
 	self
@@ -532,14 +539,6 @@ testAtIfAbsent
 	self assert: (self collection at: (self collection size + 1) ifAbsent: [ 'none' ]) equals: 'none'
 !
 
-testContains
-	| collection |
-	collection := self collection.
-	
-	self assert: (self collection contains: [ :each | each = self collection first ]).
-	self deny: (self collection contains: [ :each | each = Object new ])
-!
-
 testIndexOf
 	self assert: (self collection indexOf: 2) equals: 2.
 	self should: [ self collection indexOf: 999 ] raise: Error.
@@ -579,14 +578,6 @@ testAt
 	self should: [ self collection at: 5 ] raise: Error
 !
 
-testContains
-	| collection |
-	collection := self collection.
-	
-	self assert: (self collection contains: [ :each | each = self collection values first ]).
-	self deny: (self collection contains: [ :each | each = Object new ])
-!
-
 testFrom
 "Accept a collection of associations."
 | associations |