Exemple #1
0
void
test_map_pairs (void* data)
{
	Map* map = Map_new(runtime);

	Map_put(map, hash_for(NIL), NIL, TRUE);
	Map_put(map, hash_for(TRUE), TRUE, FALSE);
	Map_put(map, hash_for(FALSE), FALSE, NIL);

	Vector* pairs = Map_pairs(map);

	for (uint64_t i = 0; i < Vector_length(pairs); i++) {
		Tuple* pair = Vector_get(pairs, i);

		if (is_nil(Tuple_get(pair, 0))) {
			tt_assert(is_true(Tuple_get(pair, 1)));
		}
		else if (is_true(Tuple_get(pair, 0))) {
			tt_assert(is_false(Tuple_get(pair, 1)));
		}
		else if (is_false(Tuple_get(pair, 0))) {
			tt_assert(is_nil(Tuple_get(pair, 1)));
		}
	}

end:
	Map_destroy(map);
}
Exemple #2
0
/* Normalize the Vector to unit length */
void Vector_normalize(Vector *v) {
  double l;
  l = Vector_length(v);
  if (l != 0) {
    v->v[0] = v->v[0] / l;
    v->v[1] = v->v[1] / l;
    v->v[2] = v->v[2] / l;
    v->v[3] = 0.0;
  }
}
Exemple #3
0
int
Stack_pop(Stack s, void *value)
{
	int ret = Vector_get(&s->vector, Vector_length(&s->vector) - 1, value);

	/* Only truncate the vector (shrink by 1) if getting the value succeeded. */
	if (!ret)
		ret = Vector_truncate(&s->vector, -1);

	return ret;
}
Exemple #4
0
void
test_map_values (void* data)
{
	Map* map = Map_new(runtime);

	Map_put(map, hash_for(NIL), NIL, TRUE);
	Map_put(map, hash_for(TRUE), TRUE, FALSE);
	Map_put(map, hash_for(FALSE), FALSE, NIL);

	Vector* values = Map_values(map);

	for (uint64_t i = 0; i < Vector_length(values); i++) {
		Value* value = Vector_get(values, i);

		tt_assert(is_nil(value) || is_true(value) || is_false(value));
	}

end:
	Map_destroy(map);
}
int Vector3f_norm (Vector3f *v, float *result)
{
	CHECK_VECTOR3F(v);

	return Vector_length (v, result);
}
Exemple #6
0
int
Stack_peek(Stack s, void *value)
{
	return Vector_get(&s->vector, Vector_length(&s->vector) - 1, value);
}
Exemple #7
0
ptrdiff_t
Stack_height(Stack s)
{
	return Vector_length(&s->vector);
}
int EulerAngles_norm (EulerAngles *e, float *result)
{
	CHECK_EULERANGLES(e);

	return Vector_length (e, result);
}
Exemple #9
0
static inline uintL StackVectorString_length (const StackVectorString* v)
{
  return Vector_length(&v->rep);
}