Exercise 2

1 Functions

We want to search through an array of names and find the position of a particular name. The function should have two arguments, an array of names and the name we are looking for. The output will be the index where the name where found or an error will occur if the name was not found.





Write a class that tests the previous function.



1.1 Hint

Assert can be used to check wether the result has been found or not and if it has not been found, the message in the second argument will be shown otherwise.


1.2

1.2.1 findName



1.2.2 testFindName


1.2.3 Simulation of testFindName

We see that the name "Lisp" exist in the array and is on position 2.



1.2.4 testFindName2


1.2.5 Simulation of testFindName2

When searching for a name that is not in the array, the simulation is aborted. We see in the dslog.txt that the assertion fails.