Esempio n. 1
0
void hashmap_test_add_hash_collision() {
	hashmap *map = new_hashmap();
	// these two generate the same index
	put( map, "foo", "this is foo" );
	put( map, "poo", "this is poo" );
	assert_equals_str( "this is poo", get( map, "poo" ), "add_hash_collisions" );
	assert_equals_str( "this is foo", get( map, "foo" ), "add_hash_collisions" );
	destroy_hashmap(map);
}
Esempio n. 2
0
void test_assertions ()
{
        char *c;

        assert(1+1 == 2);
        assert(1+1 == 3);

        assert_true(1+1 == 2);
        assert_true(1+1 == 3);

        assert_false(1+1 == 3);
        assert_false(1+1 == 2);
        
        assert_equals_int(1, 1);
        assert_equals_int(1, 2);

        assert_not_equals_int(1, 2);
        assert_not_equals_int(1, 1);
        
        assert_equals_int(1, 1);
        assert_equals_int(1, 2);

        assert_not_equals_int(1, 2);
        assert_not_equals_int(1, 1);

        assert_equals_str("abc", "abc");
        assert_equals_str("abc", "def");

        assert_not_equals_str("abc", "def");
        assert_not_equals_str("abc", "abc");

        c = NULL;
        assert_null(c);
        c = malloc(sizeof(char));
        assert_null(c);

        c = malloc(sizeof(char));
        assert_not_null(c);
        c = NULL;
        assert_not_null(c);

        assert_equals_float(2.0, 2.0);
        assert_equals_float(2.0, 2.1);

        assert_not_equals_float(2.0, 2.1);
        assert_not_equals_float(2.0, 2.0);

        assert_equals_double(2.0, 2.0);
        assert_equals_double(2.0, 2.1);

        assert_not_equals_double(2.0, 2.1);
        assert_not_equals_double(2.0, 2.0);
}
Esempio n. 3
0
void hashmap_test_add_key_collision() {
	hashmap *map = new_hashmap();
	char *expected = "this is now foo";
	put( map, "foo", "this was foo" );
	put( map, "foo", expected );
	assert_equals_str( expected, get( map, "foo" ), "add_key_overwrite" );
	destroy_hashmap(map);
}
Esempio n. 4
0
void hashmap_test_auto_scaling() {
	hashmap *map = new_hashmap();
	int i;
	char *desc = "auto_scaling";
	char *keys[] = { "test", "poo", "bar", "tweak", "fark", "adama", "close", "duck", "goose", "chode" };
	char *values[] = { "this is a test", "this is anoo", "bar bar bar", "YOUR TAUNTAUN", "frack", "leeeeeee", "getting closer", "allhands", "ryuangant", "aundra" };
	
	for( i = 0; i < sizeof( keys )/sizeof( char * ); i++ ) {
		put( map, keys[i], values[i] );
	}
	
	for( i = 0; i < sizeof( keys )/sizeof( char * ); i++ ) {
		assert_equals_str( values[i], get( map, keys[i] ), desc );
	}
	destroy_hashmap(map);
}
Esempio n. 5
0
void hashmap_test_holds_any_value() {
	hashmap *map = new_hashmap();
	// Make an arbitrarily typed blob
	typedef struct {
		int i;
		int j;
		char* string;
	} blob;
	blob *foo = malloc( sizeof(blob) );

	foo->i = 99;
	foo->j = 253087;
	foo->string = "trololololo";

	put( map, "foo", foo );

	// Get the thing we've stored in foo and cast it to blob* type
	blob *newfoo = (blob*) get(map, "foo");
	assert_equals_str( "trololololo", newfoo->string, "holds_any_value" );
	free(foo);
	destroy_hashmap(map);
}
Esempio n. 6
0
void hashmap_test_add() {
	hashmap *map = new_hashmap();
	put( map, "foo", "this is foo" );
	assert_equals_str( "this is foo", get( map, "foo" ), "add" );
	destroy_hashmap(map);
}