[ENH] Assertion

Stephan Rudlof sr at evolgo.de
Sat May 27 23:12:47 UTC 2000


Lex,

Lex Spoon wrote:
> 
> Stephan Rudlof <sr at evolgo.de> wrote:
> > >     self failIf: [a > 0]
> > >     self failIf: [a > 0] with: 'illegal value for a'
> > >
> 
> Adding an explanation is a great idea.  However, how about using a more
> meaningful word than a generic "with" or "that".  For instance:
> 
>         self assert: [ x <= 0 ] explanation: 'x should be positive'
> 
> -Lex

I think you have meaned
	self assert: [ x > 0 ] explanation: 'x should be positive'
, is this true?

I think it should be clear, if the explanation is the description of the
fulfilled or failed or both assertion cases; e.g.:
	self assert: [ x > 0 ] explanation: 'x should be positive'
	self assert: [ x > 0 ] explanationIfFalse: 'x should be positive, but
is currently negative or zero'
	self assert: [ x > 0 ] explanationIfTrue: 'x should be positive and is
currently positive'
	
	self failIf: [ x <= 0 ] explanation: 'x should be positive'
	self failIf: [ x <= 0 ] explanationIfFalse: 'x should be positive, and
is currently positive'
	self failIf: [ x <= 0 ] explanationIfTrue: 'x should be positive, but
is currently negative or zero'

Probably this should be simplified by reducing the number of methods:
	self assert: [ x > 0 ] explanation: 'x should be positive'
	self assert: [ x > 0 ] explanationIfFalse: 'x should be positive, but
is currently negative or zero'
	
	self failIf: [ x <= 0 ] explanation: 'x should be positive'
	self failIf: [ x <= 0 ] explanationIfTrue: 'x should be positive, but
is currently negative or zero'
, and renaming:
	self assert: [ x > 0 ] explanation: 'x should be positive'
	self assert: [ x > 0 ] failExplanation: 'x should be positive, but is
currently negative or zero'
	
	self failIf: [ x <= 0 ] explanation: 'x should be positive'
	self failIf: [ x <= 0 ] failExplanation: 'x should be positive, but is
currently negative or zero'
; possibly the best is just using
	self assert: [ x > 0 ] failExplanation: 'x should be positive, but is
currently negative or zero'
	self failIf: [ x <= 0 ] failExplanation: 'x should be positive, but is
currently negative or zero'
.
In addition it could be renamed
- #assert: to #assertThat:, - exclusive - or
- #failIf: to #fail:.


Stephan
-- 
Stephan Rudlof (sr at evolgo.de)
   "Genius doesn't work on an assembly line basis.
    You can't simply say, 'Today I will be brilliant.'"
    -- Kirk, "The Ultimate Computer", stardate 4731.3





More information about the Squeak-dev mailing list