2
0
Kaynağa Gözat

AssociationTest: add tests for Association class

mkroehnert 12 yıl önce
ebeveyn
işleme
13d56fe2db
3 değiştirilmiş dosya ile 144 ekleme ve 0 silme
  1. 48 0
      js/Kernel-Tests.deploy.js
  2. 63 0
      js/Kernel-Tests.js
  3. 33 0
      st/Kernel-Tests.st

+ 48 - 0
js/Kernel-Tests.deploy.js

@@ -65,6 +65,54 @@ smalltalk.ArrayTest);
 
 
 
+smalltalk.addClass('AssociationTest', smalltalk.TestCase, [], 'Kernel-Tests');
+smalltalk.addMethod(
+"_testEqualAssociations",
+smalltalk.method({
+selector: "testEqualAssociations",
+fn: function (){
+var self=this;
+var anAssociation=nil;
+var anotherAssociation=nil;
+(anAssociation=smalltalk.send((smalltalk.Association || Association), "_key_value_", ["KEY", "VALUE"]));
+(anotherAssociation=smalltalk.send((smalltalk.Association || Association), "_key_value_", ["KEY", "VALUE"]));
+smalltalk.send(self, "_assert_", [smalltalk.send(anAssociation, "__eq", [anotherAssociation])]);
+return self;}
+}),
+smalltalk.AssociationTest);
+
+smalltalk.addMethod(
+"_testNotEqualAssociations",
+smalltalk.method({
+selector: "testNotEqualAssociations",
+fn: function (){
+var self=this;
+var anAssociation=nil;
+var anotherAssociation=nil;
+(anAssociation=smalltalk.send((smalltalk.Association || Association), "_key_value_", ["KEY", "VALUE"]));
+(anotherAssociation=smalltalk.send((smalltalk.Association || Association), "_key_value_", ["KEY2", "VALUE2"]));
+smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(anAssociation, "__eq", [anotherAssociation]), "_not", [])]);
+return self;}
+}),
+smalltalk.AssociationTest);
+
+smalltalk.addMethod(
+"_testPrintString",
+smalltalk.method({
+selector: "testPrintString",
+fn: function (){
+var self=this;
+var anAssociation=nil;
+var returnString=nil;
+(anAssociation=smalltalk.send((smalltalk.Association || Association), "_key_value_", ["KEY", "VALUE"]));
+(returnString=smalltalk.send(anAssociation, "_printString", []));
+smalltalk.send(self, "_assert_", [smalltalk.send("'KEY'->'VALUE'", "__eq", [returnString])]);
+return self;}
+}),
+smalltalk.AssociationTest);
+
+
+
 smalltalk.addClass('BlockClosureTest', smalltalk.TestCase, [], 'Kernel-Tests');
 smalltalk.addMethod(
 "_testCompiledSource",

+ 63 - 0
js/Kernel-Tests.js

@@ -85,6 +85,69 @@ smalltalk.ArrayTest);
 
 
 
+smalltalk.addClass('AssociationTest', smalltalk.TestCase, [], 'Kernel-Tests');
+smalltalk.addMethod(
+"_testEqualAssociations",
+smalltalk.method({
+selector: "testEqualAssociations",
+category: 'tests',
+fn: function (){
+var self=this;
+var anAssociation=nil;
+var anotherAssociation=nil;
+(anAssociation=smalltalk.send((smalltalk.Association || Association), "_key_value_", ["KEY", "VALUE"]));
+(anotherAssociation=smalltalk.send((smalltalk.Association || Association), "_key_value_", ["KEY", "VALUE"]));
+smalltalk.send(self, "_assert_", [smalltalk.send(anAssociation, "__eq", [anotherAssociation])]);
+return self;},
+args: [],
+source: "testEqualAssociations\x0a\x09\x22Test if two equal Association objects compare to true\x22\x0a\x09| anAssociation anotherAssociation |\x0a\x09anAssociation := Association key: 'KEY' value: 'VALUE'.\x0a\x09anotherAssociation := Association key: 'KEY' value: 'VALUE'.\x0a\x0a\x09self assert: (anAssociation = anotherAssociation).",
+messageSends: ["key:value:", "assert:", "="],
+referencedClasses: ["Association"]
+}),
+smalltalk.AssociationTest);
+
+smalltalk.addMethod(
+"_testNotEqualAssociations",
+smalltalk.method({
+selector: "testNotEqualAssociations",
+category: 'tests',
+fn: function (){
+var self=this;
+var anAssociation=nil;
+var anotherAssociation=nil;
+(anAssociation=smalltalk.send((smalltalk.Association || Association), "_key_value_", ["KEY", "VALUE"]));
+(anotherAssociation=smalltalk.send((smalltalk.Association || Association), "_key_value_", ["KEY2", "VALUE2"]));
+smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(anAssociation, "__eq", [anotherAssociation]), "_not", [])]);
+return self;},
+args: [],
+source: "testNotEqualAssociations\x0a\x09\x22Test if two unequal Association objects compare to false\x22\x0a\x09| anAssociation anotherAssociation |\x0a\x09anAssociation := Association key: 'KEY' value: 'VALUE'.\x0a\x09anotherAssociation := Association key: 'KEY2' value: 'VALUE2'.\x0a\x0a\x09self assert: (anAssociation = anotherAssociation) not.",
+messageSends: ["key:value:", "assert:", "not", "="],
+referencedClasses: ["Association"]
+}),
+smalltalk.AssociationTest);
+
+smalltalk.addMethod(
+"_testPrintString",
+smalltalk.method({
+selector: "testPrintString",
+category: 'tests',
+fn: function (){
+var self=this;
+var anAssociation=nil;
+var returnString=nil;
+(anAssociation=smalltalk.send((smalltalk.Association || Association), "_key_value_", ["KEY", "VALUE"]));
+(returnString=smalltalk.send(anAssociation, "_printString", []));
+smalltalk.send(self, "_assert_", [smalltalk.send("'KEY'->'VALUE'", "__eq", [returnString])]);
+return self;},
+args: [],
+source: "testPrintString\x0a\x09\x22Test if the output of the printString message is correct\x22\x0a\x09| anAssociation returnString |\x0a\x09anAssociation := Association key: 'KEY' value: 'VALUE'.\x0a\x09returnString := anAssociation printString.\x0a\x0a\x09self assert: ('''KEY''->''VALUE''' = returnString).",
+messageSends: ["key:value:", "printString", "assert:", "="],
+referencedClasses: ["Association"]
+}),
+smalltalk.AssociationTest);
+
+
+
 smalltalk.addClass('BlockClosureTest', smalltalk.TestCase, [], 'Kernel-Tests');
 smalltalk.addMethod(
 "_testCompiledSource",

+ 33 - 0
st/Kernel-Tests.st

@@ -40,6 +40,39 @@ testPrintString
 	self assert: 'a Array (''foo'' 3 3)' equals: ( array printString ).
 ! !
 
+TestCase subclass: #AssociationTest
+	instanceVariableNames: ''
+	package: 'Kernel-Tests'!
+
+!AssociationTest methodsFor: 'tests'!
+
+testEqualAssociations
+	"Test if two equal Association objects compare to true"
+	| anAssociation anotherAssociation |
+	anAssociation := Association key: 'KEY' value: 'VALUE'.
+	anotherAssociation := Association key: 'KEY' value: 'VALUE'.
+
+	self assert: (anAssociation = anotherAssociation).
+!
+
+testNotEqualAssociations
+	"Test if two unequal Association objects compare to false"
+	| anAssociation anotherAssociation |
+	anAssociation := Association key: 'KEY' value: 'VALUE'.
+	anotherAssociation := Association key: 'KEY2' value: 'VALUE2'.
+
+	self assert: (anAssociation = anotherAssociation) not.
+!
+
+testPrintString
+	"Test if the output of the printString message is correct"
+	| anAssociation returnString |
+	anAssociation := Association key: 'KEY' value: 'VALUE'.
+	returnString := anAssociation printString.
+
+	self assert: ('''KEY''->''VALUE''' = returnString).
+! !
+
 TestCase subclass: #BlockClosureTest
 	instanceVariableNames: ''
 	package: 'Kernel-Tests'!