In test number 4 i get the following error:
Based in the information of set method:
set(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.
If we have to avoid setting the new value if the key already exist, then the "set(2,2)" should be ignored and the output would be [1,-1].
Or maybe the set method explanation needs to be more clarifying.
You are close, but are interpreting the instructions incorrectly.
Read it like this:
Set the value, or insert the value if the key is not already present.
You do not ignore it, but it differs in that if the value is present, you do not insert another element with the same key; you just replace the object that key maps to. However, if it isn't present, then you obviously can't set the object for that key, since the key doesn't exist. Therefore, you must insert it.