Kernel-Tests.st 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. TestCase subclass: #StringTest
  2. instanceVariableNames: ''
  3. category: 'Kernel-Tests'!
  4. !StringTest methodsFor: 'tests'!
  5. testJoin
  6. self assert: 'hello,world' equals: (',' join: #('hello' 'world'))
  7. !
  8. testStreamContents
  9. self
  10. assert: 'hello world'
  11. equals: (String streamContents: [:aStream| aStream
  12. nextPutAll: 'hello'; space;
  13. nextPutAll: 'world'])
  14. !
  15. testIncludesSubString
  16. self assert: ('jtalk' includesSubString: 'alk').
  17. self deny: ('jtalk' includesSubString: 'zork').
  18. ! !
  19. TestCase subclass: #DictionaryTest
  20. instanceVariableNames: ''
  21. category: 'Kernel-Tests'!
  22. !DictionaryTest methodsFor: 'tests'!
  23. testPrintString
  24. self
  25. assert: 'a Dictionary(''firstname'' -> ''James'' , ''lastname'' -> ''Bond'')'
  26. equals: (Dictionary new
  27. at:'firstname' put: 'James';
  28. at:'lastname' put: 'Bond';
  29. printString)
  30. ! !
  31. TestCase subclass: #BooleanTest
  32. instanceVariableNames: ''
  33. category: 'Kernel-Tests'!
  34. !BooleanTest methodsFor: 'not yet classified'!
  35. testLogic
  36. "Trivial logic table"
  37. self assert: (true & true); deny: (true & false); deny: (false & true); deny: (false & false).
  38. self assert: (true | true); assert: (true | false); assert: (false | true); deny: (false | false).
  39. "Checking that expressions work fine too"
  40. self assert: (true & (1 > 0)); deny: ((1 > 0) & false); deny: ((1 > 0) & (1 > 2)).
  41. self assert: (false | (1 > 0)); assert: ((1 > 0) | false); assert: ((1 > 0) | (1 > 2))
  42. ! !
  43. TestCase subclass: #NumberTest
  44. instanceVariableNames: ''
  45. category: 'Kernel-Tests'!
  46. !NumberTest methodsFor: 'not yet classified'!
  47. testPrintShowingDecimalPlaces
  48. self assert: '23.00' equals: (23 printShowingDecimalPlaces: 2).
  49. self assert: '23.57' equals: (23.5698 printShowingDecimalPlaces: 2).
  50. self assert: '-234.56700' equals:( 234.567 negated printShowingDecimalPlaces: 5).
  51. self assert: '23' equals: (23.4567 printShowingDecimalPlaces: 0).
  52. self assert: '24' equals: (23.5567 printShowingDecimalPlaces: 0).
  53. self assert: '-23' equals: (23.4567 negated printShowingDecimalPlaces: 0).
  54. self assert: '-24' equals: (23.5567 negated printShowingDecimalPlaces: 0).
  55. self assert: '100000000.0' equals: (100000000 printShowingDecimalPlaces: 1).
  56. self assert: '0.98000' equals: (0.98 printShowingDecimalPlaces: 5).
  57. self assert: '-0.98' equals: (0.98 negated printShowingDecimalPlaces: 2).
  58. self assert: '2.57' equals: (2.567 printShowingDecimalPlaces: 2).
  59. self assert: '-2.57' equals: (-2.567 printShowingDecimalPlaces: 2).
  60. self assert: '0.00' equals: (0 printShowingDecimalPlaces: 2).
  61. ! !