static int test_filter(struct event_format *event,
		       struct filter_arg *arg, struct pevent_record *record)
{
	switch (arg->type) {
	case FILTER_ARG_BOOLEAN:
		/* easy case */
		return arg->boolean.value;

	case FILTER_ARG_OP:
		return test_op(event, arg, record);

	case FILTER_ARG_NUM:
		return test_num(event, arg, record);

	case FILTER_ARG_STR:
		return test_str(event, arg, record);

	case FILTER_ARG_EXP:
	case FILTER_ARG_VALUE:
	case FILTER_ARG_FIELD:
		/*
		 * Expressions, fields and values evaluate
		 * to true if they return non zero
		 */
		return !!get_arg_value(event, arg, record);

	default:
		die("oops!");
		/* ?? */
		return 0;
	}
}
예제 #2
0
static void
run_tests (void)
{
    int i;

    for (i = 0; i < 50; i++)
    {
        gnc_numeric n;
        gnc_numeric n1;

        n = get_random_gnc_numeric (GNC_DENOM_AUTO);
        IS_VALID_NUM(n, n);
        test_num (n);

        n1 = gnc_numeric_mul (n, n, n.denom, GNC_HOW_RND_ROUND_HALF_UP);
        IS_VALID_NUM(n1, n);
        test_num (n);

        n1 = gnc_numeric_mul (n, n, n.denom, GNC_HOW_RND_ROUND_HALF_UP);
        IS_VALID_NUM(n1, n);
        test_num (n);
    }
}
int main(void)
{
	test_null();
	test_num();
	test_bytes();
	test_appendNum();
	test_appendBytes();
	test_toByte();
	test_toByte_4bitpadding();
	test_size();

	report();

	return 0;
}
예제 #4
0
int main()
{
    int answer = 0;
    int test = 2520;

    while (!answer) {
        if (test_num(test))
            answer = test;
        test += 20;
    }

    printf("The answer is: %d\n", answer);

    return 0;
}
예제 #5
0
int main(int argc, char **argv)
{
	test_null();
	test_num();
	test_bytes();
	test_appendNum();
	test_appendBytes();
	test_toByte();
	test_toByte_4bitpadding();
	test_size();
	test_append();

	report();

	return 0;
}
예제 #6
0
파일: test.c 프로젝트: 0xroot/radare2
int main() {
	struct r_num_t num;
	num.callback = num_callback;
	num.userptr = NULL;

#if 1
	test_num(&num, "33", 33);
	test_num(&num, "0x24", 36);
	test_num(&num, "44o", 0x24);
	test_num(&num, "foo", 11);
	test_num(&num, "1+2", 3);
	test_num(&num, "3+3*2", 12);
	test_num(&num, "3+(3*2)", 9);
	test_num(&num, "(3*2)+3", 9);
	test_num(&num, "(3*2)+(3*2)", 12);
	test_num(&num, "3+(3*2+(4*2))", 17);
	test_num(&num, "8/2+(9*2)+(4*2)+(23+(43-18))", 78);
	test_num(&num, "8+(9*2)", 26);
	test_num(&num, "8/2+(9*2)", 22);
#endif
	test_num(&num, "(9*2)+(4*2)", 26);

	return 0;
}
예제 #7
0
파일: add.c 프로젝트: 198767/cyy3
//add the two numbers
char* add_nums(const char* num1,const char* base1,const char* num2,const char* base2)
{
	const char* base_str[2];
	const char* num_str[2];
	char *p,*q;
	int base_gcd;
	int i,test_res;
	int base[2];
	ln numerator[3],denominator[3];
	vector digits;

	//test bases
	base_str[0]=base1;
	base_str[1]=base2;
	for(i=0;i<2;i++)
	{
		base[i]=test_base(base_str[i]);
		if(base[i]==-1)
		{
			printf("Error: invalid base [%s]!\n",base_str[i]);
			return NULL;
		}
		else if(base[i]==-2)
		{
			printf("Error: base [%s] is out of range "MACRO2STR(MIN_BASE)"-"MACRO2STR(MAX_BASE)"!\n",base_str[i]);
			return NULL;
		}
	}

	//test numbers 
	num_str[0]=num1;
	num_str[1]=num2;
	for(i=0;i<2;i++)
	{
		test_res=test_num(num_str[i],base[i]);
		if(test_res==0)
		{
			printf("Error: invalid number [%s],the number should match the regular expression [0-9]+(.[0-9]+)? !\n",num_str[i]);
			return NULL;
		}
		else if(test_res==2)
		{
			printf("Error: invalid number [%s] in base %d !\n",num_str[i],base[i]);
			return NULL;
		}
	}

	//convert the two numbers into fraction form
	for(i=0;i<2;i++)
	{
		denominator[i]=get_denominator(num_str[i],base[i]);
		numerator[i]=get_numerator(num_str[i],base[i]);
	}

	for(i=0;i<2;i++)
	{
		p=ln2str(numerator[i]);
		q=ln2str(denominator[i]);
		printf("operand in fraction:%s/%s\n",p,q);
		fflush(stdout);
		free(p);
		free(q);
	}
	//compute the fraction
	denominator[2]=ln_multiply(denominator[0],denominator[1],newln);
	numerator[0]=ln_multiply(numerator[0],denominator[1],firstln);
	numerator[1]=ln_multiply(numerator[1],denominator[0],firstln);
	numerator[2]=ln_add(numerator[0],numerator[1],newln);
	//free unused numbers
	for(i=0;i<2;i++)
	{
		ln_free(&(numerator[i]));
		ln_free(&(denominator[i]));
	}


	p=ln2str(numerator[2]);
	q=ln2str(denominator[2]);
	printf("result in fraction:%s/%s\n",p,q);


	//simplifying the result fraction
	base_gcd=gcd(base[0],base[1]);
	if(base_gcd !=1)
	{
		while(ln_divideable_num(numerator[2],base_gcd)==1 && ln_divideable_num(denominator[2],base_gcd)==1)
		{

			ln_divide_int(numerator[2],base_gcd,0,trunc_res,firstln);
			ln_divide_int(denominator[2],base_gcd,0,trunc_res,firstln);
		}
	}

	p=ln2str(numerator[2]);
	q=ln2str(denominator[2]);
	printf("result in fraction:%s/%s\n",p,q);
	fflush(stdout);
	if(strcmp(q,"1")==0)
	{
		free(q);
		q=(char*)malloc(strlen(p)+4);
		if(!q)
		{
			ln_free(&(numerator[2]));
			ln_free(&(denominator[2]));
			printf("Error: coverting fraction to decimal number failed at line %d",__LINE__);
			return NULL;
		}
		sprintf(q,"%s 10",p);
		free(p);
		return q;
	}




	free(p);
	free(q);
	digits=get_decimal_digit(numerator[2],denominator[2]);
	if(!digits)
	{
		ln_free(&(numerator[2]));
		ln_free(&(denominator[2]));
		printf("Error: coverting fraction to decimal number failed at line %d",__LINE__);
		return NULL;
	}

	p=get_decimalstr(digits,denominator[2]);
	if(!p)
	{
		ln_free(&(numerator[2]));
		ln_free(&(denominator[2]));
		free_digit(digits);
		printf("Error: coverting fraction to decimal number failed at line %d",__LINE__);
		return NULL;
	}
	return p;
}