Commit c39a1cb1 authored by Pavel Tvrdik's avatar Pavel Tvrdik
Browse files

filter/test.conf: Extend tests

parent 0ed1e850
Loading
Loading
Loading
Loading
+214 −153
Original line number Diff line number Diff line
@@ -28,96 +28,6 @@ function onef(int a)



/*
 * 	Testing defined() function
 * 	--------------------------
 */

function test_undef(int a)
int b;
{
	if a = 3 then {
		b = 4;
		bt_assert(defined(b));
	}
	else {
		bt_assert(!defined(b));
	}
}

function t_define()
int i;
{
	test_undef(2);
	test_undef(3);
	test_undef(2);

	bt_assert(defined(1));
	bt_assert(defined(1.2.3.4));
}

bt_test_suite(t_define, "Testing defined() function");




/*
 *	 Testing calling functions
 *	 -------------------------
 */

function callme(int arg1; int arg2)
int i;
{
	case arg1 {
	1, 42: return 42;
	else: return arg1 * arg2;
	}

	return 0;
}

function fifteen()
{
	return 15;
}

function t_call_function()
{
	bt_assert(fifteen() = 15);

	bt_assert(callme(1, 2) = 42);
	bt_assert(callme(42, 2) = 42);

	bt_assert(callme(2, 2) = 4);
	bt_assert(callme(3, 2) = 6);
	bt_assert(callme(4, 4) = 16);
	bt_assert(callme(7, 2) = 14);
}

bt_test_suite(t_call_function, "Testing calling functions");




/*
 * 	Test including another config file
 * 	----------------------------------
 */

function t_include()
int i;
{
  i = 1;
  include "test.conf.inc";
  bt_assert(i = 42);
}

bt_test_suite(t_include, "Testing including another config file");




/*
 * 	Testing boolean expressions
 * 	---------------------------
@@ -175,31 +85,6 @@ int i;

	bt_assert(format(i) = "1234");

	if (i = 4) then
		bt_assert(false);
	else
		bt_assert(true);

	if !(i = 3) then
		bt_assert(true);
	else
		bt_assert(false);

	if 1234 = i then
		bt_assert(true);
	else
		bt_assert(false);

	if 1 <= 1 then
		bt_assert(true);
	else
		bt_assert(false);

	if 1234 < 1234 then
		bt_assert(false);
	else
		bt_assert(true);

	i = 4200000000;
	bt_assert(i = 4200000000);
	bt_assert(i > 4100000000);
@@ -213,6 +98,10 @@ int i;

	bt_assert(1 != "a");
	bt_assert(1 != (0,1));

	bt_assert(!(i = 4));
	bt_assert(1 <= 1);
	bt_assert(!(1234 < 1234));
}

bt_test_suite(t_int, "Testing integers");
@@ -314,6 +203,7 @@ function t_pair()
pair pp;
{
	pp = (1, 2);
	bt_assert(format(pp) = "(1,2)");
	bt_assert((1,2) = pp);
	bt_assert((1,1+1) = pp);
	bt_assert('mkpair-a'(2) = pp);
@@ -594,6 +484,9 @@ bgppath p2;
	pm1 =  / 4 3 2 1 /;
	pm2 = [= 4 3 2 1 =];

	bt_assert(pm1 = pm2);
	bt_assert(format(pm2) = "[= 4 3 2 1 =]");

	bt_assert(+empty+ = +empty+);
	bt_assert(10 !~ +empty+);

@@ -656,6 +549,7 @@ define p23 = (2, 3);
function t_clist()
clist l;
clist l2;
clist r;
{
	l = - empty -;
	bt_assert(l !~ [(*,*)]);
@@ -722,25 +616,32 @@ clist l2;
	l = filter(l2, [(3,1..4)]);
	l2 = filter(l2, [(3,3..6)]);

	#  lclist A (10,20,30)
	#  clist A (10,20,30)
	bt_assert(format(l) = "(clist (3,1) (3,2) (3,3) (3,4))");
	bt_assert(l = add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)));

	#  lclist B (30,40,50)
	#  clist B (30,40,50)
	bt_assert(format(l2) = "(clist (3,3) (3,4) (3,5) (3,6))");
	bt_assert(l2 = add(add(add(add(-empty-, (3,3)), (3,4)), (3,5)), (3,6)));

	#  lclist A union B
	bt_assert(format(add(l, l2)) = "(clist (3,1) (3,2) (3,3) (3,4) (3,5) (3,6))");
	bt_assert(add(l, l2) = add(add(add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)), (3,5)), (3,6)));
	#  clist A union B
	r = add(l, l2);
	bt_assert(format(r) = "(clist (3,1) (3,2) (3,3) (3,4) (3,5) (3,6))");
	bt_assert(r = add(add(add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)), (3,5)), (3,6)));

	#  lclist A isect B
	bt_assert(format(filter(l, l2)) = "(clist (3,3) (3,4))");
	bt_assert(filter(l, l2) = add(add(-empty-, (3,3)), (3,4)));
	#  clist A isect B
	r = filter(l, l2);
	bt_assert(format(r) = "(clist (3,3) (3,4))");
	bt_assert(r = add(add(-empty-, (3,3)), (3,4)));

	#  lclist A \ B
	bt_assert(format(delete(l, l2)) = "(clist (3,1) (3,2))");
	bt_assert(delete(l, l2) = add(add(-empty-, (3,1)), (3,2)));
	#  clist A \ B
	r = delete(l, l2);
	bt_assert(format(r) = "(clist (3,1) (3,2))");
	bt_assert(r = add(add(-empty-, (3,1)), (3,2)));

	#  clist in c set
	r = filter(l, [(3,1), (*,2)]);
	bt_assert(r = add(add(-empty-, (3,1)), (3,2)));
}

bt_test_suite(t_clist, "Testing lists of communities");
@@ -781,6 +682,7 @@ bt_test_suite(t_ec, "Testing extended communities");
function t_eclist()
eclist el;
eclist el2;
eclist r;
{
	el = -- empty --;
	el = add(el, (rt, 10, 20));
@@ -827,16 +729,23 @@ eclist el2;
	bt_assert(el2 = add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)));

	#  eclist A union B
	bt_assert(format(add(el2, el)) = "(eclist (rt, 10, 30) (rt, 10, 40) (rt, 10, 50) (rt, 10, 1))");
	bt_assert(add(el2, el) =  add(add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)), (rt, 10, 1)));
	r = add(el2, el);
	bt_assert(format(r) = "(eclist (rt, 10, 30) (rt, 10, 40) (rt, 10, 50) (rt, 10, 1))");
	bt_assert(r = add(add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)), (rt, 10, 1)));

	#  eclist A isect B
	bt_assert(format(filter(el, el2)) = "(eclist (rt, 10, 30) (rt, 10, 40))");
	bt_assert(filter(el, el2) = add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)));
	r = filter(el, el2);
	bt_assert(format(r) = "(eclist (rt, 10, 30) (rt, 10, 40))");
	bt_assert(r = add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)));

	#  eclist A \ B
	bt_assert(format(delete(el, el2)) = "(eclist (rt, 10, 1))");
	bt_assert(delete(el, el2) = add(--empty--, (rt, 10, 1)));
	r = delete(el, el2);
	bt_assert(format(r) = "(eclist (rt, 10, 1))");
	bt_assert(r = add(--empty--, (rt, 10, 1)));

	#  eclist in ec set
	r = filter(el, [(rt, 10, 1), (rt, 10, 25..30), (ro, 10, 40)]);
	bt_assert(r = add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)));
}

bt_test_suite(t_eclist, "Testing lists of extended communities");
@@ -879,8 +788,8 @@ bt_test_suite(t_ec_set, "Testing sets of extended communities");


/*
 * 	Testing Long Communities
 * 	------------------------
 * 	Testing Large Communities
 * 	-------------------------
 */

function mktrip(int a)
@@ -891,6 +800,7 @@ function mktrip(int a)
function t_lclist()
lclist ll;
lclist ll2;
lclist r;
{
	bt_assert(---empty--- = ---empty---);
	bt_assert((10, 20, 30) !~ ---empty---);
@@ -906,17 +816,6 @@ lclist ll2;
	bt_assert(mktrip(1000) ~ ll);
	bt_assert(mktrip(100) !~ ll);

	bt_assert(ll ~ [(5,10,15), (10,20,30)]);
	bt_assert(ll ~ [(10,15..25,*)]);
	bt_assert(ll ~ [(ten, *, *)]);

	bt_assert(ll !~ [(5,10,15), (10,21,30)]);
	bt_assert(ll !~ [(10,21..25,*)]);
	bt_assert(ll !~ [(11, *, *)]);

	ll2 = filter(ll, [(5..15, *, *), (100000, 500..500000, *)]);
	bt_assert(ll2 = add(add(---empty---, (10, 20, 30)), (100000, 200000, 300000)));

	ll = --- empty ---;
	ll = add(ll, (10, 10, 10));
	ll = add(ll, (20, 20, 20));
@@ -927,25 +826,187 @@ lclist ll2;
	ll2 = add(ll2, (30, 30, 30));
	ll2 = add(ll2, (40, 40, 40));

	#  lclist A (10, 20, 30)
	bt_assert(format(ll) = "(lclist (10, 10, 10) (20, 20, 20) (30, 30, 30))");

	#  lclist B (20, 30, 40)
	bt_assert(format(ll2) = "(lclist (20, 20, 20) (30, 30, 30) (40, 40, 40))");

	bt_assert(format(add(ll, ll2)) = "(lclist (10, 10, 10) (20, 20, 20) (30, 30, 30) (40, 40, 40))");
	bt_assert(add(ll, ll2) = add(add(add(add(---empty---, (10,10,10)), (20,20,20)), (30,30,30)), (40,40,40)));
	#  lclist A union B
	r = add(ll, ll2);
	bt_assert(format(r) = "(lclist (10, 10, 10) (20, 20, 20) (30, 30, 30) (40, 40, 40))");
	bt_assert(r = add(add(add(add(---empty---, (10,10,10)), (20,20,20)), (30,30,30)), (40,40,40)));

	bt_assert(format(filter(ll, ll2)) = "(lclist (20, 20, 20) (30, 30, 30))");
	bt_assert(filter(ll, ll2) = add(add(---empty---, (20, 20, 20)), (30, 30, 30)));
	#  lclist A isect B
	r = filter(ll, ll2);
	bt_assert(format(r) = "(lclist (20, 20, 20) (30, 30, 30))");
	bt_assert(r = add(add(---empty---, (20, 20, 20)), (30, 30, 30)));

	#  lclist A \ B
	r = delete(ll, ll2);
	bt_assert(format(r) = "(lclist (10, 10, 10))");
	bt_assert(r = add(---empty---, (10, 10, 10)));

	#  lclist in lc set
	r = filter(ll, [(5..15, *, *), (20, 15..25, *)]);
	bt_assert(r = add(add(---empty---, (10, 10, 10)), (20, 20, 20)));
}

bt_test_suite(t_lclist, "Testing lists of large communities");




/*
 * 	Testing sets of Large Communities
 * 	---------------------------------
 */

function t_lclist_set()
lclist ll;
lc set lls;
{
	ll = --- empty ---;
	ll = add(ll, (10, 20, 30));
	ll = add(ll, (1000, 2000, 3000));
	ll = add(ll, mktrip(100000));

	bt_assert(ll ~ [(5,10,15), (10,20,30)]);
	bt_assert(ll ~ [(10,15..25,*)]);
	bt_assert(ll ~ [(ten, *, *)]);

	bt_assert(ll !~ [(5,10,15), (10,21,30)]);
	bt_assert(ll !~ [(10,21..25,*)]);
	bt_assert(ll !~ [(11, *, *)]);

	lls = [(10, 10, 10), (20, 20, 15..25), (30, 30, *), (40, 35..45, *), (50, *, *), (55..65, *, *)];
	bt_assert((10, 10, 10)  ~ lls);
	bt_assert((20, 20, 25)  ~ lls);
	bt_assert((20, 20, 26) !~ lls);
	bt_assert((30, 30,  0)  ~ lls);
	bt_assert((40, 35, 40)  ~ lls);
	bt_assert((40, 34, 40) !~ lls);
	bt_assert((50,  0,  0)  ~ lls);
	bt_assert((60, 60, 60)  ~ lls);
	bt_assert((70, 60, 60) !~ lls);
}

bt_test_suite(t_lclist_set, "Testing sets of large communities");




/*
 * 	Testing defined() function
 * 	--------------------------
 */

	bt_assert(format(delete(ll, ll2)) = "(lclist (10, 10, 10))");
	bt_assert(delete(ll, ll2) = add(---empty---, (10, 10, 10)));
function test_undef(int a)
int b;
{
	if a = 3 then {
		b = 4;
		bt_assert(defined(b));
	}
	else {
		bt_assert(!defined(b));
	}
}

bt_test_suite(t_lclist, "Testing lists of long communities");
function t_define()
int i;
{
	test_undef(2);
	test_undef(3);
	test_undef(2);

	bt_assert(defined(1));
	bt_assert(defined(1.2.3.4));
}

bt_test_suite(t_define, "Testing defined() function");




/*
 *	 Testing calling functions
 *	 -------------------------
 */

function callme(int arg1; int arg2)
int i;
{
	case arg1 {
	1, 42: return 42;
	else: return arg1 * arg2;
	}

	return 0;
}

function fifteen()
{
	return 15;
}

function t_call_function()
{
	bt_assert(fifteen() = 15);

	bt_assert(callme(1, 2) = 42);
	bt_assert(callme(42, 2) = 42);

	bt_assert(callme(2, 2) = 4);
	bt_assert(callme(3, 2) = 6);
	bt_assert(callme(4, 4) = 16);
	bt_assert(callme(7, 2) = 14);
}

bt_test_suite(t_call_function, "Testing calling functions");




/*
 * 	Test including another config file
 * 	----------------------------------
 */

function t_include()
int i;
{
  i = 1;
  include "test.conf.inc";
  bt_assert(i = 42);
}

bt_test_suite(t_include, "Testing including another config file");




/*
 * 	Test if-else statement
 * 	----------------------
 */

function t_if_else()
int i;
{
	if true then
		bt_assert(true);

	if false then
		bt_assert(false);
	else if true then
		bt_assert(true);
	else
		bt_assert(false);
}

bt_test_suite(t_if_else, "Testing if-else statement");

/* t_lc_set */