CSC/ECE 517 Fall 2010/ch6 6b yc: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 10: Line 10:
<blockquote> "''An imperfect solution is better than none. - B. Meyer ''"[1]</blockquote>
<blockquote> "''An imperfect solution is better than none. - B. Meyer ''"[1]</blockquote>


Assertions are formal constraints on software systems which are inserted as annotations in the source program text. They had their origin in program verification [2]. Program correctness is usually defined in relation to a specification and assertions can encode the semantic properties of a specification. Using assertions to show program correctness is in general a non-trivial task and therefore it is hardly followed in practice. However, many key properties of a program can still be encoded in a simple assertion language. In such a scenario, if a program executes without any assertion violation, it can give some confidence about the program’s correctness. In a sense, assertions test a program without using any test data.
Assertions are formal constraints on software systems which are inserted as annotations in the source program text. They had their origin in program verification [2]. Program correctness is usually defined in relation to a specification and assertions can encode the semantic properties of a specification. Using assertions to show program correctness is in general a non-trivial task and therefore it is hardly followed in practice. However, many key properties of a program can still be encoded in a simple assertion language. In such a scenario, if a program executes without any assertion violation, it can give some confidence about the program’s correctness. In a sense, assertions test a program without using any test data. <br/>


== Example ==
== Example ==


Following is a simple example of an assertion in Java.
Following is a simple example of an assertion in Java. <br/>


<pre>
class Person
  attr_reader :name, :age, :occupation
  def initialize(name, age, occupation)
    @name, @age, @occupation = name, age, occupation
  end
  def mild_mannered?
    true
  end
end
jimmy = Person.new('Jimmy Olsen', 21, 'cub reporter')
clark = Person.new('Clark Kent', 35, 'reporter')
puts jimmy.mild_mannered?
puts clark.mild_mannered?
>> true
>> true
</pre>





Revision as of 14:52, 17 November 2010

Support for Assertions in Various O-O Programming Languages

Problem Statement

"Compare the support for assertions in various o-o programming languages. How well is it integrated with the language (instead of being supplied by libraries)? How many kinds of assertions are supported? How are assertions used in the various flavors of xUnit testing frameworks?"

Introduction

Definition

"An imperfect solution is better than none. - B. Meyer "[1]

Assertions are formal constraints on software systems which are inserted as annotations in the source program text. They had their origin in program verification [2]. Program correctness is usually defined in relation to a specification and assertions can encode the semantic properties of a specification. Using assertions to show program correctness is in general a non-trivial task and therefore it is hardly followed in practice. However, many key properties of a program can still be encoded in a simple assertion language. In such a scenario, if a program executes without any assertion violation, it can give some confidence about the program’s correctness. In a sense, assertions test a program without using any test data.

Example

Following is a simple example of an assertion in Java.


class Person
  attr_reader :name, :age, :occupation

   def initialize(name, age, occupation)
     @name, @age, @occupation = name, age, occupation
   end

   def mild_mannered?
     true
   end
end

jimmy = Person.new('Jimmy Olsen', 21, 'cub reporter')
clark = Person.new('Clark Kent', 35, 'reporter')
puts jimmy.mild_mannered?
puts clark.mild_mannered?

>> true
>> true


References

  • [1] B. Meyer, Object Oriented Software Construction, Prentice Hall, 1997.
  • [2] C. A. R. Hoare, An Axiomatic Basis for Computer Programming, Communications of the ACM, Vol. 12, No. 10, pp. 576–580,583, October 1969.