Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

User Tools

Site Tools

Assignment 10: Mapping Model to Code

Task 02 and Task 05 are optional again!
Task 03 is optional as well, but …
Task 04 is meant to be fun 8-) If you need help or tips, don't hesitate to ask on the mailing list.

Task 01: Mapping class diagrams to code

4 points

Map the following simple model to code strictly following the mapping presented in the lecture:

A simple domain object model of employees

We will evaluate the mapping of the three different associations and the presence of the getter and setter methods for the attributes. As explained in the lecture there is a benefit in not being creative here. Explain this in one or two sentences.

Task 02: Benefits of this mapping expressed in OCL (Optional)

3 points

The mapping of the associations is constructed to fulfill certain invariants. Describe for each of the three associations the invariants the construction guarantees. Remember: Constraints are only expected to be fulfilled on well defined points in time. Add a note for each constraint when it will be valid and when it is invalid.

3 points

We presented three alternatives to map a class hierarchy to a relational database. Describe the three alternatives and how the tables would look like for the classes Person, Employee, Manager and Worker. Discuss the benefits or drawbacks with respect to performance of queries (runtime), changes to the attributes (evolution), storage consumption.

Task 04: Testing

4 points

(Evaluation: 0,5 points for every two wrong implementations identified by your tests. -2 points if a test fails for the correct implementation.)


  • Imagine you have to test the class Triangle, whose source code you do not know.
  • The class's only public method of interest is Triangle.contains(Triangle t) and it is supposed to check if the triangle contains some other triangle t. For example the green triangle on the right contains the red one, i.e. greenTriangle.contains(redTriangle) should be true. On the other hand the red doesn't contain the green one, i.e. redTriangle.contains(greenTriangle) should be false.

Optional Preparation: Test-First Implementation

You may optionally implement the contains method yourself in a Test-First manner1). You don't need to do it, but this will strongly increase your chances to solve the task. Finding the correct implementation is not that easy. The main point of this preparation is to get some experience with finding test cases.

Debunk the Faulty Implementations

Your company decided that it is too difficult2) to develop the contains(..) method within the company. So they announced that they want to buy an implementation. In response they got 17 implementations, but they doubt that many of them are correct. You got the job to find the implementation that is working. Of course you didn't get the source code, but you are a smart tester. Write some tests to find the implementation your company should actually buy. If you did the optional step, you can use the tests that your produced. Here is your guide to the source code:

  • Check out the project A10T04_Triangles
    • The folder cls contains the implementations Triangle00 till Triangle16.
    • In the folder tst you find the class geometry.TriangleTest. This test exercises all the implementations using the same test methods for each.3)
  • Run the test.
    • You see some tests failing for the class Triangle14 and Triangle16.4)
    • Review the test methods and decide whether they make sense. If they do, Triangle14 and Triangle16 are out.
  • The test method ifOneTriangleIsVeryLargeAndTheOtherVerySmall is annotated with @Ignore and therefore ignored.
    • Is the test method correct? If yes: Remove the @Ignore annotation and run the tests again.
  • Implement some of your test cases from your plan. That is: Pick one to three representatives for each equivalence class and decide about the expected result. Create the triangles5) and add assertions for the expected results.
    • Run your tests and find out which implementation are wrong.
    • We heard that some implementations have only minor errors, so finding the single correct implementation is probably quite hard.
    • You should be able to reduce the number of implementations significantly.
  • Have fun with this exercise :-)

Task 05: Specify the contract of a Map with OCL (Optional)

3 points

Describe the contract of a Map in OCL. Describe in particular the methods V get(Object key), V put(K key, V value), remove(Object key), void clear().


The rules for Test-First are simple:
  1. Write a test describing some expected behavior of the method.
  2. Run the test and see it failing.
  3. Add just enough code to the method to make the test succeed. Not one line more!
  4. Run the test and see it suceeding.
  5. If you can think of another test or think the implementation is not yet complete, start from 1.
They didn't listen to you :-(
There is quite some JUnit 4 and Java Reflection Magic behind the mechanism to run the test for each of the implementations. You don't need to understand that. The only thing to remember is, that you should use the createTriangle(..) method to create triangles. Don't use the constructors directly!
Remember to use the createTriangle(..) method to create triangles!
teaching/lectures/oosc/2012/assignment_10.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2019