Sort the letters of string in alphabetical order: Difference between revisions
Content added Content deleted
Line 428: | Line 428: | ||
Notice the use of Design-by-Contract in the "ensure" at the end of `sort_string'. At testing runtime, we want the routine itself to ensure that the resulting string has no space character and that every character that we passed in the `s' argument is represented in the result string. We even go so far as to ensure that repeating characters are all represented. We could go further, but we felt these contracts |
Notice the use of Design-by-Contract in the "ensure" at the end of `sort_string'. At testing runtime, we want the routine itself to ensure that the resulting string has no space character and that every character that we passed in the `s' argument is represented in the result string. We even go so far as to ensure that repeating characters are all represented. We could go further, but we felt these contracts |
||
were sufficient to get the point of Design-by-Contract across to you as the reader. |
were sufficient to get the point of Design-by-Contract across to you as the reader. |
||
Also note the unicode characters of ⟳ .. ⟲ and ∀. These are called across-loops and we have used the "symbolic form" of them. The first one simple says, "Across all items in l_list as c, perform the code between the ¦ and closing ⟲. In the case of the ∀, this is a loop stating that every member of the Result STRING must hold true for the Boolean expression. For example, in the "no_spaces" contract, we are saying that each character "c" must not be equal to a space (e.g. ' '). |
|||
And the Test Code to operate it. |
And the Test Code to operate it. |