zoukankan      html  css  js  c++  java
  • pre-condition & post-condition

    As we will see, the two statements work together: The precondition indicates what must be true before the function is called.  The postcondition indicates what will be true when the function finishes its work.

    example:

    void write_sqrt(double x) 

    //   Precondition:  x  >=  0.

    //   Postcondition:  The square root of x has been written to the standard output.

    This is an example of a small function which simply writes the square root of a number.  The number is given as a parameter to the function, called x.   For example, if we call write_sqrt(9), then we would expect the function to print 3 (which is the square root of 9).

    What needs to be true in order for this function to successfully carry out its work?  Since negative numbers don't have a square root, we need to ensure that the argument, x, is not negative.  This requirement is expressed in the precondition:

            Precondition: x  >=  0.

    The postcondition is simply a statement expressing what work has been accomplished by the function.  This work might involve reading or writing data, changing the values of variable parameters, or other actions.

    Notice that the information shown on this slide is enough for you to use the function.  You don't need to know what occurs in the function body.

  • 相关阅读:
    前端开发浏览器兼容问题
    pc端页面打包成安卓apk
    AJAX
    webpack
    【javascript】数据结构-集合
    【javascript】数据结构-队列
    【前端】display: box布局教程 [转]
    【前端】Flex 布局教程:语法篇 [转]
    【前端】几种实现水平垂直居中的方法总结
    【前端】jQuery选择器$()的实现原理
  • 原文地址:https://www.cnblogs.com/qingsunny/p/3296766.html
Copyright © 2011-2022 走看看