#include #include "testhashmap.h" #include "../hashmap.h" void test_Empty_after_creation() { HashMap hashmap; assert( hashmap.empty() ); } void test_Insert_makes_size_increase() { HashMap hashmap; hashmap.insert( "foo", 15 ); assert( hashmap.size() == 1 ); hashmap.insert( "bar", 31 ); assert( hashmap.size() == 2 ); } void test_Clashing_insert_still_makes_size_increase() { HashMap hashmap; hashmap.insert( "foo", 15 ); assert( hashmap.size() == 1 ); hashmap.insert( "oof", 12 ); // I happen to know these hash to the same num assert( hashmap.size() == 2 ); } void test_Insert_same_key_does_not_affect_size() { HashMap hashmap; hashmap.insert( "foo", 15 ); assert( hashmap.size() == 1 ); hashmap.insert( "foo", 31 ); assert( hashmap.size() == 1 ); } void test_Find_returns_the_relevant_value() { HashMap hashmap; hashmap.insert( "foo", 15 ); assert( hashmap.size() == 1 ); hashmap.insert( "bar", 31 ); assert( hashmap.size() == 2 ); assert( hashmap.find( "foo" ) != NULL ); assert( hashmap.find( "bar" ) != NULL ); assert( *( hashmap.find( "foo" ) ) == 15 ); assert( *( hashmap.find( "bar" ) ) == 31 ); } void test_Find_missing_key_returns_null() { HashMap hashmap; hashmap.insert( "foo", 15 ); hashmap.insert( "bar", 31 ); assert( hashmap.find( "qux" ) == NULL ); } void test_hashmap() { test_Empty_after_creation(); test_Insert_makes_size_increase(); test_Clashing_insert_still_makes_size_increase(); test_Insert_same_key_does_not_affect_size(); test_Find_returns_the_relevant_value(); test_Find_missing_key_returns_null(); }