Пример #1
0
static char* test_scaling_equivalence()
{
    load_histograms();

    mu_assert(
            "Averages should be equivalent",
            compare_values(
                    hdr_mean(cor_histogram) * 512,
                    hdr_mean(scaled_cor_histogram),
                    0.000001));

    mu_assert(
            "Total count should be equivalent",
            compare_int64(
                    cor_histogram->total_count,
                    scaled_cor_histogram->total_count));

    int64_t expected_99th = hdr_value_at_percentile(cor_histogram, 99.0) * 512;
    int64_t scaled_99th = hdr_value_at_percentile(scaled_cor_histogram, 99.0);
    mu_assert(
            "99%'iles should be equivalent",
            compare_int64(
                    hdr_lowest_equivalent_value(cor_histogram, expected_99th),
                    hdr_lowest_equivalent_value(scaled_cor_histogram, scaled_99th)));

    return 0;
}
Пример #2
0
bool occurs_in_tree(const Value val, const Node *const pt_to_node) {
    if (!pt_to_node)
        return false;
    if (compare_values(val, pt_to_node->value) == 0)
        return true;
    return occurs_in_tree(val, pt_to_node->pt_to_left_node) ||
        occurs_in_tree(val, pt_to_node->pt_to_right_node);
}
Пример #3
0
void insert_in_sorted_list(const Value value, Node **const pt_to_pt_to_node) {
    Node *const pt_to_new_node = create_node(value);
    if (!*pt_to_pt_to_node) {
        *pt_to_pt_to_node = pt_to_new_node;
        return;
    }
    Node *pt_to_node = *pt_to_pt_to_node;
    if (compare_values(pt_to_node->value, value) >= 0) {
        pt_to_new_node->pt_to_next_node = pt_to_node;
        *pt_to_pt_to_node = pt_to_new_node;
        return;
    }
    while (pt_to_node->pt_to_next_node && compare_values(pt_to_node->pt_to_next_node->value, value) < 0)
        pt_to_node = pt_to_node->pt_to_next_node;
    pt_to_new_node->pt_to_next_node = pt_to_node->pt_to_next_node;
    pt_to_node->pt_to_next_node = pt_to_new_node;
}
Пример #4
0
bool insert_in_list_before(const Value value_1, Node **const pt_to_pt_to_node, const Value value_2) {
    if (!*pt_to_pt_to_node)
        return false;
    if (!compare_values((*pt_to_pt_to_node)->value, value_2)) {
        prepend_to_list(value_1, pt_to_pt_to_node);
        return true;
    }
    Node *pt_to_node = *pt_to_pt_to_node;
    while (pt_to_node->pt_to_next_node && compare_values(pt_to_node->pt_to_next_node->value, value_2))
        pt_to_node = pt_to_node->pt_to_next_node;
    if (!pt_to_node->pt_to_next_node)
        return false;
    Node *const pt_to_new_node = create_node(value_1);
    pt_to_new_node->pt_to_next_node = pt_to_node->pt_to_next_node;
    pt_to_node->pt_to_next_node = pt_to_new_node;
    return true;
}
Пример #5
0
void op_ne()
{
 bool result;

 result = !compare_values(TEST_EQ, TRUE);

 InitDescr(e_stack, INTEGER);
 (e_stack++)->data.value = (long int)result;
}
Пример #6
0
int position_of_value_in_list(const Value value, Node *pt_to_node) {
    int position = 0;
    while (pt_to_node) {
        if (!compare_values(pt_to_node->value, value))
            return position;
        ++position;
        pt_to_node = pt_to_node->pt_to_next_node;
    }
    return -1;
}
Пример #7
0
bool list_is_sorted(const Node *pt_to_node) {
    if (!pt_to_node)
        return true;
    while (pt_to_node->pt_to_next_node) {
        if (compare_values(pt_to_node->value, pt_to_node->pt_to_next_node->value) > 0)
            return false;
        pt_to_node = pt_to_node->pt_to_next_node;
    }
    return true;
}
Пример #8
0
bool remove_from_list(const Value value, Node **const pt_to_pt_to_node) {
    if (!*pt_to_pt_to_node)
        return false;
    Node *pt_to_node = *pt_to_pt_to_node;
    if (!compare_values(pt_to_node->value, value)) {
        *pt_to_pt_to_node = pt_to_node->pt_to_next_node;
        free(pt_to_node);
        return true;
    }
    if (!pt_to_node->pt_to_next_node)
        return false;
    while (compare_values(pt_to_node->pt_to_next_node->value, value) && pt_to_node->pt_to_next_node->pt_to_next_node)
        pt_to_node = pt_to_node->pt_to_next_node;
    if (compare_values(pt_to_node->pt_to_next_node->value, value))
        return false;
    Node *const pt_to_found_node = pt_to_node->pt_to_next_node;
    pt_to_node->pt_to_next_node = pt_to_found_node->pt_to_next_node;
    free(pt_to_found_node);
    return true;
}
Пример #9
0
PyObject * labelCompare (PyObject * self, PyObject * args)
{
    char *v1, *r1, *v2, *r2;
    const char *e1, *e2;
    int rc;

    if (!PyArg_ParseTuple(args, "(zzz)(zzz)",
			&e1, &v1, &r1, &e2, &v2, &r2))
	return NULL;

    if (e1 == NULL)	e1 = "0";
    if (e2 == NULL)	e2 = "0";

    rc = compare_values(e1, e2);
    if (!rc) {
	rc = compare_values(v1, v2);
	if (!rc)
	    rc = compare_values(r1, r2);
    }
    return Py_BuildValue("i", rc);
}
Пример #10
0
bool insert_in_bst(const Value value, Node **const pt_to_pt_to_node) {
    if (!*pt_to_pt_to_node) {
        *pt_to_pt_to_node = create_node(value);
        return true;
    }
    Node *pt_to_node = *pt_to_pt_to_node;
    if (compare_values(pt_to_node->value, value) == 0)
        return false;
    if (compare_values(value, pt_to_node->value) < 0) {
        if (!pt_to_node->pt_to_left_node) {
            pt_to_node->pt_to_left_node = create_node(value);
            return true;
        }
        return insert_in_bst(value, &pt_to_node->pt_to_left_node);
    }
    if (!pt_to_node->pt_to_right_node) {
        pt_to_node->pt_to_right_node = create_node(value);
        return true;
    }
    return insert_in_bst(value, &pt_to_node->pt_to_right_node);
}
Пример #11
0
static gboolean
test_comparison (const gfloat        *reference,
                 const gfloat        *test_case,
                 const CompareResult *expected_result)
{
  GeglBuffer    *src_ref_buffer;
  GeglBuffer    *src_aux_buffer;
  GeglRectangle  extent;
  const Babl    *input_format = babl_format ("R'G'B'A float");
  GeglNode      *graph, *source_ref, *source_aux, *comparison;
  gint           test_result;

  /* Set up all buffers */
  extent = *GEGL_RECTANGLE (0, 0, NUM_COLS, NUM_ROWS);

  src_ref_buffer = gegl_buffer_new (&extent, input_format);
  src_aux_buffer = gegl_buffer_new (&extent, input_format);

  gegl_buffer_set (src_ref_buffer, &extent, 0, input_format,
                   reference, GEGL_AUTO_ROWSTRIDE);
  gegl_buffer_set (src_aux_buffer, &extent, 0, input_format,
                   test_case, GEGL_AUTO_ROWSTRIDE);

  /* Build the test graph */
  graph = gegl_node_new ();
  source_ref = gegl_node_new_child (graph,
                                    "operation", "gegl:buffer-source",
                                    "buffer", src_ref_buffer,
                                    NULL);
  source_aux = gegl_node_new_child (graph,
                                    "operation", "gegl:buffer-source",
                                    "buffer", src_aux_buffer,
                                    NULL);
  comparison = gegl_node_new_child (graph,
                                    "operation", "gegl:image-compare",
                                    NULL);

  gegl_node_link_many (source_ref, comparison, NULL);
  gegl_node_connect_to (source_aux, "output",  comparison, "aux");

  gegl_node_process (comparison);

  /* Compare with reference */
  test_result = compare_values (comparison, expected_result);

  /* We are done, clean and quit */
  g_object_unref (graph);
  g_object_unref (src_aux_buffer);
  g_object_unref (src_ref_buffer);

  return test_result;
}
Пример #12
0
	inline bool operator<(const ValueArray& x, const ValueArray& y)
	{
		return compare_values(x, y) < 0;
	}
Пример #13
0
int
do_compare(int type, struct bu_vls *vls, Tcl_Obj *obj1, Tcl_Obj *obj2, char *obj_name)
{
    Tcl_Obj *key1, *val1, *key2, *val2;
    int len1, len2, found, junk;
    int i, j;
    int start_index;
    int found_diffs = 0;
    int ev = 0;

    if (Tcl_ListObjLength(INTERP, obj1, &len1) == TCL_ERROR) {
	fprintf(stderr, "Error getting length of TCL object!!!\n");
	fprintf(stderr, "%s\n", Tcl_GetStringResult(INTERP));
	bu_exit (1, NULL);
    }
    if (Tcl_ListObjLength(INTERP, obj2, &len2) == TCL_ERROR) {
	fprintf(stderr, "Error getting length of TCL object!!!\n");
	fprintf(stderr, "%s\n", Tcl_GetStringResult(INTERP));
	bu_exit (1, NULL);
    }

    if (!len1 && !len2)
	return 0;

    if (type == ATTRS) {
	start_index = 0;
    } else {
	start_index = 1;
    }

    /* check for changed values from object 1 to object2 */
    for (i=start_index; i<len1; i+=2) {
	if (Tcl_ListObjIndex(INTERP, obj1, i, &key1) == TCL_ERROR) {
	    fprintf(stderr, "Error getting word #%d in TCL object!!! (%s)\n", i, Tcl_GetStringFromObj(obj1, &junk));
	    fprintf(stderr, "%s\n", Tcl_GetStringResult(INTERP));
	    bu_exit (1, NULL);
	}

	if (Tcl_ListObjIndex(INTERP, obj1, i+1, &val1) == TCL_ERROR) {
	    fprintf(stderr, "Error getting word #%d in TCL object!!! (%s)\n", i+1, Tcl_GetStringFromObj(obj1, &junk));
	    fprintf(stderr, "%s\n", Tcl_GetStringResult(INTERP));
	    bu_exit (1, NULL);
	}

	found = 0;
	for (j=start_index; j<len2; j += 2) {
	    if (Tcl_ListObjIndex(INTERP, obj2, j, &key2) == TCL_ERROR) {
		fprintf(stderr, "Error getting word #%d in TCL object!!! (%s)\n", j, Tcl_GetStringFromObj(obj2, &junk));
		fprintf(stderr, "%s\n", Tcl_GetStringResult(INTERP));
		bu_exit (1, NULL);
	    }
	    if (BU_STR_EQUAL(Tcl_GetStringFromObj(key1, &junk), Tcl_GetStringFromObj(key2, &junk))) {

		found = 1;
		if (Tcl_ListObjIndex(INTERP, obj2, j+1, &val2) == TCL_ERROR) {
		    fprintf(stderr, "Error getting word #%d in TCL object!!! (%s)\n", j+1, Tcl_GetStringFromObj(obj2, &junk));
		    fprintf(stderr, "%s\n", Tcl_GetStringResult(INTERP));
		    bu_exit (1, NULL);
		}

		/* check if this value has changed */
		ev = compare_values(type, val1, val2);
		if (ev) {
		    if (!found_diffs++) {
			if (mode == HUMAN) {
			    printf("%s has changed:\n", obj_name);
			}
		    }
		    if (mode == HUMAN) {
			if (type == PARAMS) {
			    printf("\tparameter %s has changed from:\n\t\t%s\n\tto:\n\t\t%s\n",
				   Tcl_GetStringFromObj(key1, &junk),
				   Tcl_GetStringFromObj(val1, &junk),
				   Tcl_GetStringFromObj(val2, &junk));
			} else {
			    printf("\t%s attribute \"%s\" has changed from:\n\t\t%s\n\tto:\n\t\t%s\n",
				   obj_name,
				   Tcl_GetStringFromObj(key1, &junk),
				   Tcl_GetStringFromObj(val1, &junk),
				   Tcl_GetStringFromObj(val2, &junk));
			}
		    } else {
			int val_len;

			if (type == ATTRS) {
			    bu_vls_printf(vls, "attr set %s ", obj_name);
			} else {
			    bu_vls_strcat(vls, " ");
			}
			bu_vls_strcat(vls, Tcl_GetStringFromObj(key1, &junk));
			bu_vls_strcat(vls, " ");
			if (Tcl_ListObjLength(INTERP, val2, &val_len) == TCL_ERROR) {
			    fprintf(stderr, "Error getting length of TCL object!!\n");
			    fprintf(stderr, "%s\n", Tcl_GetStringResult(INTERP));
			    bu_exit(1, NULL);
			}
			if (val_len > 1)
			    bu_vls_putc(vls, '{');
			bu_vls_strcat(vls, Tcl_GetStringFromObj(val2, &junk));
			if (val_len > 1)
			    bu_vls_putc(vls, '}');
			if (type == ATTRS) {
			    bu_vls_putc(vls, '\n');
			}
		    }
		}
		break;
	    }
	}
	if (!found) {
	    /* this keyword value pair has been eliminated */
	    if (!found_diffs++) {
		if (mode == HUMAN) {
		    printf("%s has changed:\n", obj_name);
		}
	    }
	    if (mode == HUMAN) {
		if (type == PARAMS) {
		    printf("\tparameter %s has been eliminated\n",
			   Tcl_GetStringFromObj(key1, &junk));
		} else {
		    printf("\tattribute \"%s\" has been eliminated from %s\n",
			   Tcl_GetStringFromObj(key1, &junk), obj_name);
		}
	    } else {
		if (type == ATTRS) {
		    bu_vls_printf(vls, "attr rm %s %s\n", obj_name,
				  Tcl_GetStringFromObj(key1, &junk));
		} else {
		    bu_vls_strcat(vls, " ");
		    bu_vls_strcat(vls, Tcl_GetStringFromObj(key1, &junk));
		    bu_vls_strcat(vls, " none");
		}
	    }
	}
    }

    /* check for keyword value pairs in object 2 that don't appear in object 1 */
    for (i=start_index; i<len2; i+= 2) {
	/* get keyword/value pairs from object 2 */
	if (Tcl_ListObjIndex(INTERP, obj2, i, &key2) == TCL_ERROR) {
	    fprintf(stderr, "Error getting word #%d in TCL object!!! (%s)\n", i, Tcl_GetStringFromObj(obj2, &junk));
	    fprintf(stderr, "%s\n", Tcl_GetStringResult(INTERP));
	    bu_exit (1, NULL);
	}

	if (Tcl_ListObjIndex(INTERP, obj2, i+1, &val2) == TCL_ERROR) {
	    fprintf(stderr, "Error getting word #%d in TCL object!!! (%s)\n", i+1, Tcl_GetStringFromObj(obj2, &junk));
	    fprintf(stderr, "%s\n", Tcl_GetStringResult(INTERP));
	    bu_exit (1, NULL);
	}

	found = 0;
	/* look for this keyword in object 1 */
	for (j=start_index; j<len1; j += 2) {
	    if (Tcl_ListObjIndex(INTERP, obj1, j, &key1) == TCL_ERROR) {
		fprintf(stderr, "Error getting word #%d in TCL object!!! (%s)\n", i, Tcl_GetStringFromObj(obj1, &junk));
		fprintf(stderr, "%s\n", Tcl_GetStringResult(INTERP));
		bu_exit (1, NULL);
	    }
	    if (BU_STR_EQUAL(Tcl_GetStringFromObj(key1, &junk), Tcl_GetStringFromObj(key2, &junk))) {
		found = 1;
		break;
	    }
	}
	if (found)
	    continue;

	/* This keyword/value pair in object 2 is not in object 1 */
	if (!found_diffs++) {
	    if (mode == HUMAN) {
		printf("%s has changed:\n", obj_name);
	    }
	}
	if (mode == HUMAN) {
	    if (type == PARAMS) {
		printf("\t%s has new parameter \"%s\" with value %s\n",
		       obj_name,
		       Tcl_GetStringFromObj(key2, &junk),
		       Tcl_GetStringFromObj(val2, &junk));
	    } else {
		printf("\t%s has new attribute \"%s\" with value {%s}\n",
		       obj_name,
		       Tcl_GetStringFromObj(key2, &junk),
		       Tcl_GetStringFromObj(val2, &junk));
	    }
	} else {
	    int val_len;

	    if (type == ATTRS) {
		bu_vls_printf(vls, "attr set %s ", obj_name);
	    } else {
		bu_vls_strcat(vls, " ");
	    }
	    bu_vls_strcat(vls, Tcl_GetStringFromObj(key2, &junk));
	    bu_vls_strcat(vls, " ");
	    if (Tcl_ListObjLength(INTERP, val2, &val_len) == TCL_ERROR) {
		fprintf(stderr, "Error getting length of TCL object!!\n");
		fprintf(stderr, "%s\n", Tcl_GetStringResult(INTERP));
		bu_exit(1, NULL);
	    }
	    if (val_len > 1)
		bu_vls_putc(vls, '{');
	    bu_vls_strcat(vls, Tcl_GetStringFromObj(val2, &junk));
	    if (val_len > 1)
		bu_vls_putc(vls, '}');
	    if (type == ATTRS)
		bu_vls_putc(vls, '\n');
	}
    }

    if (evolutionary && found_diffs)
	bu_vls_strcat(vls, ev == 2 ? " (Evolutionary)" : " (Reworked)");

    return found_diffs;
}
Пример #14
0
static void
run_test (struct sockaddr_in *addr)
{
    CLIENT *clnt;
    char value_val1[] = "Hello, world.";
    char value_val2[] = "Goodbye, world.";
    bamboo_put_args put_args;
    bamboo_get_args get_args;
    bamboo_get_res  *get_result;
    int first;

    memset (&put_args, 0, sizeof (put_args));
    memset (&get_args, 0, sizeof (get_args));

    srand (1);

    clnt = connect_to_server (addr);
    do_null_call (clnt);

    // Do a first put.

    random_key (put_args.key, sizeof (put_args.key));
    put_args.value.bamboo_value_val = value_val1;
    put_args.value.bamboo_value_len = sizeof (value_val1);
    do_put (clnt, &put_args);

    // Check that the data's there.

    memcpy (get_args.key, put_args.key, sizeof (get_args.key));
    get_result = do_get (clnt, &get_args);

    if (get_result->values.values_len != 1) {
        printf ("Get failed: returned %d values.\n", 
                get_result->values.values_len);
        exit (1);
    }
    if (compare_values (&(get_result->values.values_val [0]),
             value_val1, sizeof (value_val1)) != 0) {
        printf ("Get failed: values don't match: %s vs %s\n", 
                value_val1,
                get_result->values.values_val [0].bamboo_value_val);
        exit (1);
    }
    printf ("Get successful.\n");

    // Do a second put with the same key.

    put_args.value.bamboo_value_val = value_val2;
    put_args.value.bamboo_value_len = sizeof (value_val2);
    do_put (clnt, &put_args);

    // Check that both values are there.

    get_result = do_get (clnt, &get_args); 
    if (get_result->values.values_len != 1) {
        printf ("Get failed: returned %d values.\n", 
                get_result->values.values_len);
        exit (1);
    }

    printf ("Get returned value %s.\n", 
            get_result->values.values_val [0].bamboo_value_val);

    if (compare_values (&(get_result->values.values_val [0]),
             value_val1, sizeof (value_val1)) == 0) {
        printf ("Get returned first value.\n");
        first = TRUE;
    }
    else if (compare_values (&(get_result->values.values_val [0]),
                    value_val2, sizeof (value_val2)) == 0) {
        printf ("Get second first value.\n");
        first = FALSE;
    }
    else {
        printf ("Get failed: returned neither value.\n");
        exit (1);
    }

    get_args.placemark.bamboo_placemark_val = 
        get_result->placemark.bamboo_placemark_val;
    get_args.placemark.bamboo_placemark_len = 
        get_result->placemark.bamboo_placemark_len;

    get_result = do_get (clnt, &get_args); 
    if (get_result->values.values_len != 1) {
        printf ("Get failed: returned %d values.\n", 
                get_result->values.values_len);
        exit (1);
    }

    printf ("Get returned value %s.\n", 
            get_result->values.values_val [0].bamboo_value_val);

    if (first) {
        if (compare_values (&(get_result->values.values_val [0]),
                value_val2, sizeof (value_val2)) != 0) {
        printf ("Get failed: second value doesn't match: %s vs %s\n", 
                value_val2,
                get_result->values.values_val [0].bamboo_value_val);
        exit (1);
        }
    }
    else if (compare_values (&(get_result->values.values_val [0]),
                value_val1, sizeof (value_val1)) != 0) {
        printf ("Get failed: second value doesn't match: %s vs %s\n", 
                value_val1,
                get_result->values.values_val [0].bamboo_value_val);
        exit (1);
    }

    printf ("Get successful.\n");

    // Do a put with a different key.

    random_key (put_args.key, sizeof (put_args.key));
    do_put (clnt, &put_args);

    // Check that the data's there.

    memcpy (get_args.key, put_args.key, sizeof (get_args.key));
    get_args.placemark.bamboo_placemark_val = NULL;
    get_args.placemark.bamboo_placemark_len = 0;
    get_result = do_get (clnt, &get_args);

    if (get_result->values.values_len != 1) {
        printf ("Get failed: returned %d values.\n", 
                get_result->values.values_len);
        exit (1);
    }
    if (compare_values (&(get_result->values.values_val [0]),
             value_val2, sizeof (value_val2)) != 0) {
        printf ("Get failed: values don't match: %s vs %s\n", 
                value_val2,
                get_result->values.values_val [0].bamboo_value_val);
        exit (1);
    }
    printf ("Get successful.\n");

    clnt_destroy (clnt);
}
Пример #15
0
bool compare_percentile(int64_t a, double b, double variation)
{
    return compare_values((double) a, b, variation);
    // return fabs(a - b) <= b * variation;
}
Пример #16
0
/* Evaluate EXPR on RECORD in AU->le.
   Return 1 if EXPR is true, 0 if it false or if it fails.
   (No error reporting facility is provided; an invalid term is considered to
   be false; e.g. !invalid is true.) */
int
expr_eval(auparse_state_t *au, rnode *record, const struct expr *expr)
{
	switch (expr->op) {
	case EO_NOT:
		return !expr_eval(au, record, expr->v.sub[0]);

	case EO_AND:
		return (expr_eval(au, record, expr->v.sub[0])
			&& expr_eval(au, record, expr->v.sub[1]));

	case EO_OR:
		return (expr_eval(au, record, expr->v.sub[0])
			|| expr_eval(au, record, expr->v.sub[1]));

	case EO_RAW_EQ: case EO_RAW_NE: {
		int free_it, ne;
		char *value;

		value = eval_raw_value(au, record, expr, &free_it);
		if (value == NULL)
			return 0;
		assert(expr->precomputed_value == 0);
		ne = strcmp(expr->v.p.value.string, value);
		if (free_it != 0)
			free(value);
		return expr->op == EO_RAW_EQ ? ne == 0 : ne != 0;
	}

	case EO_INTERPRETED_EQ: case EO_INTERPRETED_NE: {
		int free_it, ne;
		char *value;

		value = eval_interpreted_value(au, record, expr, &free_it);
		if (value == NULL)
			return 0;
		assert(expr->precomputed_value == 0);
		ne = strcmp(expr->v.p.value.string, value);
		if (free_it != 0)
			free(value);
		return expr->op == EO_INTERPRETED_EQ ? ne == 0 : ne != 0;
	}

	case EO_VALUE_EQ: case EO_VALUE_NE: case EO_VALUE_LT: case EO_VALUE_LE:
	case EO_VALUE_GT: case EO_VALUE_GE: {
		int err, cmp;

		cmp = compare_values(au, record, expr, &err);
		if (err != 0)
			return 0;
		switch (expr->op) {
		case EO_VALUE_EQ:
			return cmp == 0;

		case EO_VALUE_NE:
			return cmp != 0;

		case EO_VALUE_LT:
			return cmp < 0;

		case EO_VALUE_LE:
			return cmp <= 0;

		case EO_VALUE_GT:
			return cmp > 0;

		case EO_VALUE_GE:
			return cmp >= 0;

		default:
			abort();
		}
	}

	case EO_FIELD_EXISTS:
		assert(expr->virtual_field == 0);
		nvlist_first(&record->nv);
		return nvlist_find_name(&record->nv, expr->v.p.field.name) != 0;

	case EO_REGEXP_MATCHES:
		return regexec(expr->v.regexp, record->record, 0, NULL, 0) == 0;

	default:
		abort();
	}
}