Browse Source

Added unit tests for Number.

Matthias Springer 10 years ago
parent
commit
8b16b0cbea
3 changed files with 70 additions and 2 deletions
  1. 25 1
      js/Kernel-Tests.deploy.js
  2. 35 1
      js/Kernel-Tests.js
  3. 10 0
      st/Kernel-Tests.st

+ 25 - 1
js/Kernel-Tests.deploy.js

@@ -1,5 +1,6 @@
 (function(smalltalk,nil,_st){
 smalltalk.addPackage('Kernel-Tests');
+
 smalltalk.addClass('BlockClosureTest', smalltalk.TestCase, [], 'Kernel-Tests');
 smalltalk.addMethod(
 smalltalk.method({
@@ -1753,6 +1754,19 @@ return self}, function($ctx1) {$ctx1.fill(self,"testAsArray",{},smalltalk.String
 messageSends: ["assert:equals:", "asArray"]}),
 smalltalk.StringTest);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "testAsNumber",
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+self._assert_equals_("3"._asNumber(),(3));
+self._assert_equals_("-3"._asNumber(),(-3));
+self._assert_equals_("-1.5"._asNumber(),(-1.5));
+return self}, function($ctx1) {$ctx1.fill(self,"testAsNumber",{},smalltalk.StringTest)})},
+messageSends: ["assert:equals:", "asNumber"]}),
+smalltalk.StringTest);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "testAt",
@@ -2842,6 +2856,17 @@ return self}, function($ctx1) {$ctx1.fill(self,"testArithmetic",{},smalltalk.Num
 messageSends: ["assert:equals:", "+", "-", "/", "*"]}),
 smalltalk.NumberTest);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "testAsNumber",
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+self._assert_equals_((3)._asNumber(),(3));
+return self}, function($ctx1) {$ctx1.fill(self,"testAsNumber",{},smalltalk.NumberTest)})},
+messageSends: ["assert:equals:", "asNumber"]}),
+smalltalk.NumberTest);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "testComparison",
@@ -4078,5 +4103,4 @@ messageSends: ["assert:", "isNil", "deny:", "notNil"]}),
 smalltalk.UndefinedTest);
 
 
-
 })(global_smalltalk,global_nil,global__st);

+ 35 - 1
js/Kernel-Tests.js

@@ -1,5 +1,6 @@
 (function(smalltalk,nil,_st){
 smalltalk.addPackage('Kernel-Tests');
+
 smalltalk.addClass('BlockClosureTest', smalltalk.TestCase, [], 'Kernel-Tests');
 smalltalk.addMethod(
 smalltalk.method({
@@ -2188,6 +2189,24 @@ referencedClasses: []
 }),
 smalltalk.StringTest);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "testAsNumber",
+category: 'tests',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+self._assert_equals_("3"._asNumber(),(3));
+self._assert_equals_("-3"._asNumber(),(-3));
+self._assert_equals_("-1.5"._asNumber(),(-1.5));
+return self}, function($ctx1) {$ctx1.fill(self,"testAsNumber",{},smalltalk.StringTest)})},
+args: [],
+source: "testAsNumber\x0a\x09self assert: '3' asNumber equals: 3.\x0a\x09self assert: '-3' asNumber equals: -3.\x0a\x09self assert: '-1.5' asNumber equals: -1.5.",
+messageSends: ["assert:equals:", "asNumber"],
+referencedClasses: []
+}),
+smalltalk.StringTest);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "testAt",
@@ -3617,6 +3636,22 @@ referencedClasses: []
 }),
 smalltalk.NumberTest);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "testAsNumber",
+category: 'tests',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+self._assert_equals_((3)._asNumber(),(3));
+return self}, function($ctx1) {$ctx1.fill(self,"testAsNumber",{},smalltalk.NumberTest)})},
+args: [],
+source: "testAsNumber\x0a\x09self assert: 3 asNumber equals: 3.",
+messageSends: ["assert:equals:", "asNumber"],
+referencedClasses: []
+}),
+smalltalk.NumberTest);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "testComparison",
@@ -5179,5 +5214,4 @@ referencedClasses: []
 smalltalk.UndefinedTest);
 
 
-
 })(global_smalltalk,global_nil,global__st);

+ 10 - 0
st/Kernel-Tests.st

@@ -840,6 +840,12 @@ testAsArray
 	self assert: 'hello' asArray equals: #('h' 'e' 'l' 'l' 'o').
 !
 
+testAsNumber
+	self assert: '3' asNumber equals: 3.
+	self assert: '-3' asNumber equals: -3.
+	self assert: '-1.5' asNumber equals: -1.5.
+!
+
 testAt
 	self assert: ('hello' at: 1) equals: 'h'.
 	self assert: ('hello' at: 5) equals: 'o'.
@@ -1356,6 +1362,10 @@ testArithmetic
 	self assert: 1 + (2 * 3) equals: 7
 !
 
+testAsNumber
+	self assert: 3 asNumber equals: 3.
+!
+
 testComparison
 
 	self assert: 3 > 2.