So what does glass box testing mean if it cant go

Info icon This preview shows pages 7–9. Sign up to view the full content.

So what does glass box testing mean, if it can’t go beyond the spec? It means you are try- ing to find new test cases that exercise different parts of the implementation, but still checking those test cases in an implementation-independent way. CPEN 221 – Fall 2016
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

The Need for Specifications 8 5 Specifications for Mutating Methods We will later discuss mutable vs. immutable objects, but here we will briefly mention the role of specification when dealing with mutability. Our specifications of find didn’t give us the opportunity to illustrate how to describe side-effects — changes to mutable data — in the postcondition. Here’s a specification that describes a method that mutates an object: static boolean addAll(List<T> list1, List<T> list2) requires: list1 != list2 effects: modifies list1 by adding the elements of list2 to the end of it, and returns true if list1 changed as a result of call We’ve taken this, slightly simplified, from the Java List interface. First, look at the postcondition. It gives two constraints: the first telling us how list1 is modified, and the second telling us how the return value is determined. Second, look at the precondition. It tells us that the behaviour of the method if you attempt to add the elements of a list to itself is undefined. You can easily imagine why the implementor of the method would want to impose this constraint: it’s not likely to rule out any useful applications of the method, and it makes it easier to implement. The specification allows a simple implementation in which you take an element from list2 and add it to list1 , then go on to the next element of list2 until you get to the end. If list1 and list2 are the same list, this algorithm will not terminate — an outcome permitted by the specification. Remember also our implicit precondition that list1 and list2 must be valid objects, rather than null . We’ll usually omit saying this because it’s virtually always required of object references. Here is another example of a mutating method: static void sort(List<String> lst) requires: nothing effects: puts lst in sorted order, i.e. lst[i] <= lst[j] for all 0 <= i < j < lst.size() And an example of a method that does not mutate its argument: CPEN 221 – Fall 2016
Image of page 8
The Need for Specifications 9 static List<String> toLowerCase(List<String> lst) requires: nothing effects: returns a new list t where t[i] = lst[i].toLowerCase() Just as we’ve said that null is implicitly disallowed unless stated otherwise, we will also use the convention that mutation is disallowed unless stated otherwise . The spec of toLowerCase could explicitly state as an effect that “lst is not modified”, but in the absence of a postcondition describing mutation, we demand no mutation of the inputs. CPEN 221 – Fall 2016
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.
  • Fall '17
  • satish
  • Method, Val, specification

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern