I'm doing an assignment in Eiffel and I'm having trouble implementing my ensure clause. Is there some special syntax you need to include a variable or function?
This is my code at the moment for my 'put' function
put(key: K; value: V)
require
key /= void
local
tmp:ITEM[K,V]
do
create tmp.make(key, value)
list.put_front (tmp)
count := count + 1
ensure
count = old count + 1 and list.has(key, value)
end
This is the code for the 'has' function
has(key:K; val:V):BOOLEAN
require
key /= void
local
flag: INTEGER
do
flag := 0
from
list.start
until
list.exhausted
loop
if list.item.getkey = key then
if list.item.getvalue = val then
flag := 1
end
end
list.forth
end
if flag = 1 then
Result := true
else
Result := false
end
ensure
--???
end
The assignment is to implement a map adt via linked list. The 'put' function inserts item(key, value) into the list. The 'has' function checks whether the list contains (key value) pair.
Any help will be greatly appreciated.