2
0

Kernel-Tests.st 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  1. Smalltalk current createPackage: 'Kernel-Tests' properties: #{}!
  2. TestCase subclass: #StringTest
  3. instanceVariableNames: ''
  4. category: 'Kernel-Tests'!
  5. !StringTest methodsFor: 'tests'!
  6. testJoin
  7. self assert: 'hello,world' equals: (',' join: #('hello' 'world'))
  8. !
  9. testStreamContents
  10. self
  11. assert: 'hello world'
  12. equals: (String streamContents: [:aStream| aStream
  13. nextPutAll: 'hello'; space;
  14. nextPutAll: 'world'])
  15. !
  16. testIncludesSubString
  17. self assert: ('amber' includesSubString: 'ber').
  18. self deny: ('amber' includesSubString: 'zork').
  19. !
  20. testEquality
  21. self assert: 'hello' = 'hello'.
  22. self deny: 'hello' = 'world'.
  23. self assert: 'hello' = 'hello' yourself.
  24. self assert: 'hello' yourself = 'hello'.
  25. "test JS falsy value"
  26. self deny: '' = 0
  27. !
  28. testCopyWithoutAll
  29. self
  30. assert: 'hello world'
  31. equals: ('*hello* *world*' copyWithoutAll: '*')
  32. !
  33. testAt
  34. self assert: ('hello' at: 1) = 'h'.
  35. self assert: ('hello' at: 5) = 'o'.
  36. self assert: ('hello' at: 6 ifAbsent: [nil]) = nil
  37. !
  38. testAtPut
  39. "String instances are read-only"
  40. self should: ['hello' at: 1 put: 'a'] raise: Error
  41. !
  42. testSize
  43. self assert: 'smalltalk' size equals: 9.
  44. self assert: '' size equals: 0
  45. !
  46. testAddRemove
  47. self should: ['hello' add: 'a'] raise: Error.
  48. self should: ['hello' remove: 'h'] raise: Error
  49. ! !
  50. TestCase subclass: #DictionaryTest
  51. instanceVariableNames: ''
  52. category: 'Kernel-Tests'!
  53. !DictionaryTest methodsFor: 'tests'!
  54. testPrintString
  55. self
  56. assert: 'a Dictionary(''firstname'' -> ''James'' , ''lastname'' -> ''Bond'')'
  57. equals: (Dictionary new
  58. at:'firstname' put: 'James';
  59. at:'lastname' put: 'Bond';
  60. printString)
  61. !
  62. testEquality
  63. | d1 d2 |
  64. self assert: Dictionary new = Dictionary new.
  65. d1 := Dictionary new at: 1 put: 2; yourself.
  66. d2 := Dictionary new at: 1 put: 2; yourself.
  67. self assert: d1 = d2.
  68. d2 := Dictionary new at: 1 put: 3; yourself.
  69. self deny: d1 = d2.
  70. d2 := Dictionary new at: 2 put: 2; yourself.
  71. self deny: d1 = d2.
  72. d2 := Dictionary new at: 1 put: 2; at: 3 put: 4; yourself.
  73. self deny: d1 = d2.
  74. !
  75. testDynamicDictionaries
  76. self assert: #{1 -> 'hello'. 2 -> 'world'} = (Dictionary with: 1 -> 'hello' with: 2 -> 'world')
  77. !
  78. testAccessing
  79. | d |
  80. d := Dictionary new.
  81. d at: 'hello' put: 'world'.
  82. self assert: (d at: 'hello') = 'world'.
  83. self assert: (d at: 'hello' ifAbsent: [nil]) = 'world'.
  84. self deny: (d at: 'foo' ifAbsent: [nil]) = 'world'.
  85. d at: 1 put: 2.
  86. self assert: (d at: 1) = 2.
  87. d at: 1@3 put: 3.
  88. self assert: (d at: 1@3) = 3
  89. !
  90. testSize
  91. | d |
  92. d := Dictionary new.
  93. self assert: d size = 0.
  94. d at: 1 put: 2.
  95. self assert: d size = 1.
  96. d at: 2 put: 3.
  97. self assert: d size = 2.
  98. !
  99. testValues
  100. | d |
  101. d := Dictionary new.
  102. d at: 1 put: 2.
  103. d at: 2 put: 3.
  104. d at: 3 put: 4.
  105. self assert: d values = #(2 3 4)
  106. !
  107. testKeys
  108. | d |
  109. d := Dictionary new.
  110. d at: 1 put: 2.
  111. d at: 2 put: 3.
  112. d at: 3 put: 4.
  113. self assert: d keys = #(1 2 3)
  114. ! !
  115. TestCase subclass: #BooleanTest
  116. instanceVariableNames: ''
  117. category: 'Kernel-Tests'!
  118. !BooleanTest methodsFor: 'tests'!
  119. testLogic
  120. "Trivial logic table"
  121. self assert: (true & true); deny: (true & false); deny: (false & true); deny: (false & false).
  122. self assert: (true | true); assert: (true | false); assert: (false | true); deny: (false | false).
  123. "Checking that expressions work fine too"
  124. self assert: (true & (1 > 0)); deny: ((1 > 0) & false); deny: ((1 > 0) & (1 > 2)).
  125. self assert: (false | (1 > 0)); assert: ((1 > 0) | false); assert: ((1 > 0) | (1 > 2))
  126. !
  127. testEquality
  128. "We're on top of JS...just be sure to check the basics!!"
  129. self deny: 0 = false.
  130. self deny: false = 0.
  131. self deny: '' = false.
  132. self deny: false = ''.
  133. self assert: true = true.
  134. self deny: false = true.
  135. self deny: true = false.
  136. self assert: false = false.
  137. "JS may do some type coercing after sending a message"
  138. self assert: true yourself = true.
  139. self assert: true yourself = true yourself
  140. !
  141. testLogicKeywords
  142. "Trivial logic table"
  143. self
  144. assert: (true and: [ true]);
  145. deny: (true and: [ false ]);
  146. deny: (false and: [ true ]);
  147. deny: (false and: [ false ]).
  148. self
  149. assert: (true or: [ true ]);
  150. assert: (true or: [ false ]);
  151. assert: (false or: [ true ]);
  152. deny: (false or: [ false ]).
  153. "Checking that expressions work fine too"
  154. self
  155. assert: (true and: [ 1 > 0 ]);
  156. deny: ((1 > 0) and: [ false ]);
  157. deny: ((1 > 0) and: [ 1 > 2 ]).
  158. self
  159. assert: (false or: [ 1 > 0 ]);
  160. assert: ((1 > 0) or: [ false ]);
  161. assert: ((1 > 0) or: [ 1 > 2 ])
  162. !
  163. testIfTrueIfFalse
  164. self assert: (true ifTrue: ['alternative block']) = 'alternative block'.
  165. self assert: (true ifFalse: ['alternative block']) = nil.
  166. self assert: (false ifTrue: ['alternative block']) = nil.
  167. self assert: (false ifFalse: ['alternative block']) = 'alternative block'.
  168. self assert: (false ifTrue: ['alternative block'] ifFalse: ['alternative block2']) = 'alternative block2'.
  169. self assert: (false ifFalse: ['alternative block'] ifTrue: ['alternative block2']) = 'alternative block'.
  170. self assert: (true ifTrue: ['alternative block'] ifFalse: ['alternative block2']) = 'alternative block'.
  171. self assert: (true ifFalse: ['alternative block'] ifTrue: ['alternative block2']) = 'alternative block2'.
  172. ! !
  173. TestCase subclass: #NumberTest
  174. instanceVariableNames: ''
  175. category: 'Kernel-Tests'!
  176. !NumberTest methodsFor: 'tests'!
  177. testPrintShowingDecimalPlaces
  178. self assert: '23.00' equals: (23 printShowingDecimalPlaces: 2).
  179. self assert: '23.57' equals: (23.5698 printShowingDecimalPlaces: 2).
  180. self assert: '-234.56700' equals:( 234.567 negated printShowingDecimalPlaces: 5).
  181. self assert: '23' equals: (23.4567 printShowingDecimalPlaces: 0).
  182. self assert: '24' equals: (23.5567 printShowingDecimalPlaces: 0).
  183. self assert: '-23' equals: (23.4567 negated printShowingDecimalPlaces: 0).
  184. self assert: '-24' equals: (23.5567 negated printShowingDecimalPlaces: 0).
  185. self assert: '100000000.0' equals: (100000000 printShowingDecimalPlaces: 1).
  186. self assert: '0.98000' equals: (0.98 printShowingDecimalPlaces: 5).
  187. self assert: '-0.98' equals: (0.98 negated printShowingDecimalPlaces: 2).
  188. self assert: '2.57' equals: (2.567 printShowingDecimalPlaces: 2).
  189. self assert: '-2.57' equals: (-2.567 printShowingDecimalPlaces: 2).
  190. self assert: '0.00' equals: (0 printShowingDecimalPlaces: 2).
  191. !
  192. testEquality
  193. self assert: 1 = 1.
  194. self assert: 0 = 0.
  195. self deny: 1 = 0.
  196. self assert: 1 yourself = 1.
  197. self assert: 1 = 1 yourself.
  198. self assert: 1 yourself = 1 yourself.
  199. self deny: 0 = false.
  200. self deny: false = 0.
  201. self deny: '' = 0.
  202. self deny: 0 = ''
  203. !
  204. testArithmetic
  205. "We rely on JS here, so we won't test complex behavior, just check if
  206. message sends are corrects"
  207. self assert: 1.5 + 1 = 2.5.
  208. self assert: 2 - 1 = 1.
  209. self assert: -2 - 1 = -3.
  210. self assert: 12 / 2 = 6.
  211. self assert: 3 * 4 = 12.
  212. "Simple parenthesis and execution order"
  213. self assert: 1 + 2 * 3 = 9.
  214. self assert: 1 + (2 * 3) = 7
  215. !
  216. testRounded
  217. self assert: 3 rounded = 3.
  218. self assert: 3.212 rounded = 3.
  219. self assert: 3.51 rounded = 4
  220. !
  221. testNegated
  222. self assert: 3 negated = -3.
  223. self assert: -3 negated = 3
  224. !
  225. testComparison
  226. self assert: 3 > 2.
  227. self assert: 2 < 3.
  228. self deny: 3 < 2.
  229. self deny: 2 > 3.
  230. self assert: 3 >= 3.
  231. self assert: 3.1 >= 3.
  232. self assert: 3 <= 3.
  233. self assert: 3 <= 3.1
  234. !
  235. testTruncated
  236. self assert: 3 truncated = 3.
  237. self assert: 3.212 truncated = 3.
  238. self assert: 3.51 truncated = 3
  239. !
  240. testCopying
  241. self assert: 1 copy == 1.
  242. self assert: 1 deepCopy == 1
  243. !
  244. testMinMax
  245. self assert: (2 max: 5) equals: 5.
  246. self assert: (2 min: 5) equals: 2
  247. !
  248. testIdentity
  249. self assert: 1 == 1.
  250. self assert: 0 == 0.
  251. self deny: 1 == 0.
  252. self assert: 1 yourself == 1.
  253. self assert: 1 == 1 yourself.
  254. self assert: 1 yourself == 1 yourself.
  255. self deny: 1 == 2
  256. !
  257. testSqrt
  258. self assert: 4 sqrt = 2.
  259. self assert: 16 sqrt = 4
  260. !
  261. testSquared
  262. self assert: 4 squared = 16
  263. !
  264. testTimesRepeat
  265. | i |
  266. i := 0.
  267. 0 timesRepeat: [i := i + 1].
  268. self assert: i equals: 0.
  269. 5 timesRepeat: [i := i + 1].
  270. self assert: i equals: 5
  271. !
  272. testTo
  273. self assert: (1 to: 5) equals: #(1 2 3 4 5)
  274. !
  275. testToBy
  276. self assert: (0 to: 6 by: 2) equals: #(0 2 4 6).
  277. self should: [1 to: 4 by: 0] raise: Error
  278. ! !
  279. TestCase subclass: #JSObjectProxyTest
  280. instanceVariableNames: ''
  281. category: 'Kernel-Tests'!
  282. !JSObjectProxyTest methodsFor: 'accessing'!
  283. jsObject
  284. <return jsObject = {a: 1, b: function() {return 2;}, c: function(object) {return object;}}>
  285. ! !
  286. !JSObjectProxyTest methodsFor: 'tests'!
  287. testMethodWithArguments
  288. self deny: ('body' asJQuery hasClass: 'amber').
  289. 'body' asJQuery addClass: 'amber'.
  290. self assert: ('body' asJQuery hasClass: 'amber').
  291. 'body' asJQuery removeClass: 'amber'.
  292. self deny: ('body' asJQuery hasClass: 'amber').
  293. !
  294. testYourself
  295. |body|
  296. body := 'body' asJQuery
  297. addClass: 'amber';
  298. yourself.
  299. self assert: (body hasClass: 'amber').
  300. body removeClass: 'amber'.
  301. self deny: (body hasClass: 'amber').
  302. !
  303. testPropertyThatReturnsEmptyString
  304. <document.location.hash = ''>.
  305. self assert: '' equals: document location hash.
  306. document location hash: 'test'.
  307. self assert: '#test' equals: document location hash.
  308. !
  309. testDNU
  310. self should: [self jsObject foo] raise: MessageNotUnderstood
  311. !
  312. testMessageSend
  313. self assert: self jsObject a equals: 1.
  314. self assert: self jsObject b equals: 2.
  315. self assert: (self jsObject c: 3) equals: 3
  316. !
  317. testPrinting
  318. self assert: self jsObject printString = '[object Object]'
  319. ! !
  320. TestCase subclass: #PackageTest
  321. instanceVariableNames: 'zorkPackage grulPackage backUpCommitPathJs backUpCommitPathSt'
  322. category: 'Kernel-Tests'!
  323. !PackageTest methodsFor: 'running'!
  324. setUp
  325. backUpCommitPathJs := Package defaultCommitPathJs.
  326. backUpCommitPathSt := Package defaultCommitPathSt.
  327. Package resetCommitPaths.
  328. zorkPackage := Package new name: 'Zork'.
  329. grulPackage := Package new
  330. name: 'Grul';
  331. commitPathJs: 'server/grul/js';
  332. commitPathSt: 'grul/st';
  333. yourself
  334. !
  335. tearDown
  336. Package
  337. defaultCommitPathJs: backUpCommitPathJs;
  338. defaultCommitPathSt: backUpCommitPathSt
  339. ! !
  340. !PackageTest methodsFor: 'tests'!
  341. testGrulCommitPathStShouldBeGrulSt
  342. self assert: 'grul/st' equals: grulPackage commitPathSt
  343. !
  344. testZorkCommitPathStShouldBeSt
  345. self assert: 'st' equals: zorkPackage commitPathSt
  346. !
  347. testZorkCommitPathJsShouldBeJs
  348. self assert: 'js' equals: zorkPackage commitPathJs
  349. !
  350. testGrulCommitPathJsShouldBeServerGrulJs
  351. self assert: 'server/grul/js' equals: grulPackage commitPathJs
  352. ! !
  353. PackageTest subclass: #PackageWithDefaultCommitPathChangedTest
  354. instanceVariableNames: ''
  355. category: 'Kernel-Tests'!
  356. !PackageWithDefaultCommitPathChangedTest methodsFor: 'running'!
  357. setUp
  358. super setUp.
  359. Package
  360. defaultCommitPathJs: 'javascripts/';
  361. defaultCommitPathSt: 'smalltalk/'.
  362. ! !
  363. !PackageWithDefaultCommitPathChangedTest methodsFor: 'tests'!
  364. testGrulCommitPathJsShouldBeServerGrulJs
  365. self assert: 'server/grul/js' equals: grulPackage commitPathJs
  366. !
  367. testGrulCommitPathStShouldBeGrulSt
  368. self assert: 'grul/st' equals: grulPackage commitPathSt
  369. !
  370. testZorkCommitPathJsShouldBeJavascript
  371. self assert: 'javascripts/' equals: zorkPackage commitPathJs
  372. !
  373. testZorkCommitPathStShouldBeSmalltalk
  374. self assert: 'smalltalk/' equals: zorkPackage commitPathSt
  375. ! !
  376. !PackageWithDefaultCommitPathChangedTest class methodsFor: 'accessing'!
  377. shouldInheritSelectors
  378. ^ false
  379. ! !
  380. TestCase subclass: #BlockClosureTest
  381. instanceVariableNames: ''
  382. category: 'Kernel-Tests'!
  383. !BlockClosureTest methodsFor: 'tests'!
  384. testValue
  385. self assert: ([1+1] value) equals: 2.
  386. self assert: ([:x | x +1] value: 2) equals: 3.
  387. self assert: ([:x :y | x*y] value: 2 value: 4) equals: 8.
  388. "Arguments are optional in Amber. This isn't ANSI compliant."
  389. self assert: ([:a :b :c | 1] value) equals: 1
  390. !
  391. testOnDo
  392. self assert: ([Error new signal] on: Error do: [:ex | true])
  393. !
  394. testEnsure
  395. self assert: ([Error new] ensure: [true])
  396. !
  397. testNumArgs
  398. self assert: [] numArgs equals: 0.
  399. self assert: [:a :b | ] numArgs equals: 2
  400. !
  401. testValueWithPossibleArguments
  402. self assert: ([1] valueWithPossibleArguments: #(3 4)) equals: 1.
  403. self assert: ([:a | a + 4] valueWithPossibleArguments: #(3 4)) equals: 7.
  404. self assert: ([:a :b | a + b] valueWithPossibleArguments: #(3 4 5)) equals: 7.
  405. !
  406. testWhileTrue
  407. | i |
  408. i := 0.
  409. [i < 5] whileTrue: [i := i + 1].
  410. self assert: i equals: 5.
  411. i := 0.
  412. [i := i + 1. i < 5] whileTrue.
  413. self assert: i equals: 5
  414. !
  415. testWhileFalse
  416. | i |
  417. i := 0.
  418. [i > 5] whileFalse: [i := i + 1].
  419. self assert: i equals: 6.
  420. i := 0.
  421. [i := i + 1. i > 5] whileFalse.
  422. self assert: i equals: 6
  423. !
  424. testCompiledSource
  425. self assert: ([1+1] compiledSource includesSubString: 'function')
  426. ! !
  427. TestCase subclass: #ObjectTest
  428. instanceVariableNames: ''
  429. category: 'Kernel-Tests'!
  430. !ObjectTest methodsFor: 'tests'!
  431. testEquality
  432. | o |
  433. o := Object new.
  434. self deny: o = Object new.
  435. self assert: o = o.
  436. self assert: o yourself = o.
  437. self assert: o = o yourself
  438. !
  439. testIdentity
  440. | o |
  441. o := Object new.
  442. self deny: o == Object new.
  443. self assert: o == o
  444. !
  445. testHalt
  446. self should: [Object new halt] raise: Error
  447. !
  448. testBasicAccess
  449. | o |
  450. o := Object new.
  451. o basicAt: 'a' put: 1.
  452. self assert: (o basicAt: 'a') equals: 1.
  453. self assert: (o basicAt: 'b') equals: nil
  454. !
  455. testNilUndefined
  456. "nil in Smalltalk is the undefined object in JS"
  457. self assert: nil = undefined
  458. !
  459. testidentityHash
  460. | o1 o2 |
  461. o1 := Object new.
  462. o2 := Object new.
  463. self assert: o1 identityHash == o1 identityHash.
  464. self deny: o1 identityHash == o2 identityHash
  465. !
  466. testBasicPerform
  467. | o |
  468. o := Object new.
  469. o basicAt: 'func' put: ['hello'].
  470. o basicAt: 'func2' put: [:a | a + 1].
  471. self assert: (o basicPerform: 'func') equals: 'hello'.
  472. self assert: (o basicPerform: 'func2' withArguments: #(3)) equals: 4
  473. !
  474. testIfNil
  475. self deny: Object new isNil.
  476. self deny: (Object new ifNil: [true]) = true.
  477. self assert: (Object new ifNotNil: [true]) = true.
  478. self assert: (Object new ifNil: [false] ifNotNil: [true]) = true.
  479. self assert: (Object new ifNotNil: [true] ifNil: [false]) = true
  480. !
  481. testInstVars
  482. | o |
  483. o := ObjectMock new.
  484. self assert: (o instVarAt: #foo) equals: nil.
  485. o instVarAt: #foo put: 1.
  486. self assert: (o instVarAt: #foo) equals: 1.
  487. self assert: (o instVarAt: 'foo') equals: 1
  488. !
  489. testYourself
  490. | o |
  491. o := ObjectMock new.
  492. self assert: o yourself == o
  493. !
  494. testDNU
  495. self should: [Object new foo] raise: MessageNotUnderstood
  496. ! !
  497. TestCase subclass: #SymbolTest
  498. instanceVariableNames: ''
  499. category: 'Kernel-Tests'!
  500. !SymbolTest methodsFor: 'tests'!
  501. testEquality
  502. self assert: #hello = #hello.
  503. self deny: #hello = #world.
  504. self assert: #hello = #hello yourself.
  505. self assert: #hello yourself = #hello.
  506. self deny: #hello = 'hello'.
  507. self deny: 'hello' = #hello.
  508. !
  509. testAt
  510. self assert: (#hello at: 1) = 'h'.
  511. self assert: (#hello at: 5) = 'o'.
  512. self assert: (#hello at: 6 ifAbsent: [nil]) = nil
  513. !
  514. testAtPut
  515. "Symbol instances are read-only"
  516. self should: ['hello' at: 1 put: 'a'] raise: Error
  517. !
  518. testIdentity
  519. self assert: #hello == #hello.
  520. self deny: #hello == #world.
  521. self assert: #hello = #hello yourself.
  522. self assert: #hello yourself = #hello asString asSymbol
  523. !
  524. testComparing
  525. self assert: #ab > #aa.
  526. self deny: #ab > #ba.
  527. self assert: #ab < #ba.
  528. self deny: #bb < #ba.
  529. self assert: #ab >= #aa.
  530. self deny: #ab >= #ba.
  531. self assert: #ab <= #ba.
  532. self deny: #bb <= #ba
  533. !
  534. testSize
  535. self assert: #a size equals: 1.
  536. self assert: #aaaaa size equals: 5
  537. !
  538. testAsString
  539. self assert: #hello asString equals: 'hello'
  540. !
  541. testAsSymbol
  542. self assert: #hello == #hello asSymbol
  543. !
  544. testCopying
  545. self assert: #hello copy == #hello.
  546. self assert: #hello deepCopy == #hello
  547. !
  548. testIsSymbolIsString
  549. self assert: #hello isSymbol.
  550. self deny: 'hello' isSymbol.
  551. self deny: #hello isString.
  552. self assert: 'hello' isString
  553. ! !
  554. Object subclass: #ObjectMock
  555. instanceVariableNames: 'foo bar'
  556. category: 'Kernel-Tests'!
  557. !ObjectMock methodsFor: 'not yet classified'!
  558. foo
  559. ^foo
  560. !
  561. foo: anObject
  562. foo := anObject
  563. ! !
  564. TestCase subclass: #UndefinedTest
  565. instanceVariableNames: ''
  566. category: 'Kernel-Tests'!
  567. !UndefinedTest methodsFor: 'tests'!
  568. testIsNil
  569. self assert: nil isNil.
  570. self deny: nil notNil.
  571. !
  572. testIfNil
  573. self assert: (nil ifNil: [true]) equals: true.
  574. self deny: (nil ifNotNil: [true]) = true.
  575. self assert: (nil ifNil: [true] ifNotNil: [false]) equals: true.
  576. self deny: (nil ifNotNil: [true] ifNil: [false]) = true
  577. !
  578. testCopying
  579. self assert: nil copy equals: nil
  580. !
  581. testDeepCopy
  582. self assert: nil deepCopy = nil
  583. ! !
  584. TestCase subclass: #PointTest
  585. instanceVariableNames: ''
  586. category: 'Kernel-Tests'!
  587. !PointTest methodsFor: 'tests'!
  588. testAccessing
  589. self assert: (Point x: 3 y: 4) x equals: 3.
  590. self assert: (Point x: 3 y: 4) y equals: 4.
  591. self assert: (Point new x: 3) x equals: 3.
  592. self assert: (Point new y: 4) y equals: 4
  593. !
  594. testAt
  595. self assert: 3@4 equals: (Point x: 3 y: 4)
  596. !
  597. testEgality
  598. self assert: 3@4 = (3@4).
  599. self deny: 3@5 = (3@6)
  600. !
  601. testArithmetic
  602. self assert: 3@4 * (3@4 ) equals: (Point x: 9 y: 16).
  603. self assert: 3@4 + (3@4 ) equals: (Point x: 6 y: 8).
  604. self assert: 3@4 - (3@4 ) equals: (Point x: 0 y: 0).
  605. self assert: 6@8 / (3@4 ) equals: (Point x: 2 y: 2)
  606. ! !
  607. TestCase subclass: #RandomTest
  608. instanceVariableNames: ''
  609. category: 'Kernel-Tests'!
  610. !RandomTest methodsFor: 'tests'!
  611. textNext
  612. 10000 timesRepeat: [
  613. | current next |
  614. next := Random new next.
  615. self assert: (next >= 0).
  616. self assert: (next < 1).
  617. self deny: current = next.
  618. next = current]
  619. ! !
  620. TestCase subclass: #ClassBuilderTest
  621. instanceVariableNames: 'builder theClass'
  622. category: 'Kernel-Tests'!
  623. !ClassBuilderTest methodsFor: 'running'!
  624. setUp
  625. builder := ClassBuilder new
  626. !
  627. tearDown
  628. theClass ifNotNil: [Smalltalk current removeClass: theClass. theClass := nil]
  629. !
  630. testClassCopy
  631. theClass := builder copyClass: ObjectMock named: 'ObjectMock2'.
  632. self assert: theClass superclass == ObjectMock superclass.
  633. self assert: theClass instanceVariableNames == ObjectMock instanceVariableNames.
  634. self assert: theClass name equals: 'ObjectMock2'.
  635. self assert: theClass package == ObjectMock package.
  636. self assert: theClass methodDictionary keys equals: ObjectMock methodDictionary keys
  637. !
  638. testInstanceVariableNames
  639. self assert: (builder instanceVariableNamesFor: ' hello world ') equals: #('hello' 'world')
  640. ! !
  641. TestCase subclass: #SetTest
  642. instanceVariableNames: ''
  643. category: 'Kernel-Tests'!
  644. !SetTest methodsFor: 'tests'!
  645. testUnicity
  646. | set |
  647. set := Set new.
  648. set add: 21.
  649. set add: 'hello'.
  650. set add: 21.
  651. self assert: set size = 2.
  652. set add: 'hello'.
  653. self assert: set size = 2.
  654. self assert: set asArray equals: #(21 'hello')
  655. !
  656. testAt
  657. self should: [Set new at: 1 put: 2] raise: Error
  658. !
  659. testAddRemove
  660. | set |
  661. set := Set new.
  662. self assert: set isEmpty.
  663. set add: 3.
  664. self assert: (set includes: 3).
  665. set add: 5.
  666. self assert: (set includes: 5).
  667. set remove: 3.
  668. self deny: (set includes: 3)
  669. !
  670. testSize
  671. self assert: Set new size equals: 0.
  672. self assert: (Set withAll: #(1 2 3 4)) size equals: 4.
  673. self assert: (Set withAll: #(1 1 1 1)) size equals: 1
  674. ! !