So I'm trying to figure out why my get method doesn't pass its test.
This is my attempt at the get method:
public Value get(Object key) { //Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
for (Pair<Key,Value> item : list) {
if (item.key.equals(key)) {
return item.value;
}
}
return null;
}
public Value put(Key key, Value value) { //Associates the specified value with the specified key in the map.
for (Pair<Key,Value> item : list) {
if (containsKey(key)==true) { //A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.
return item.value;
}
}
size++;
return null;
}
My put method:
public Value put(Key key, Value value) { //Associates the specified value with the specified key in the map.
for (Pair<Key,Value> item : list) {
if (containsKey(key)==true) { //A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.
return item.value;
}
}
size++;
return null;
}
My clear method:
public void clear() {
list.clear();
}
The get test method:
public void testGet() {
map.clear();
map.put("All These Things That I Have Done","Killers");
map.put("Human","Killers");
map.put("Evil","Interpol");
assertThat(map.get("Evil"), is("Interpol"));
assertThat(map.get("Human"), is("Killers"));
}
The test fails. I'm not sure if the get method test fails because the put or clear methods are wrong, or if it's just the get method...
This is the error I get:
java.lang.AssertionError:
Expected is: "Interpol"
but: was null
I would really appreciate any help at all, even small suggestions. I'm pretty lost if you can't tell. :(