summaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-04-06 09:20:56 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-04-06 09:20:56 +0200
commitca2051a26b74e1140cf2ca3ea0c82c1eed5bce28 (patch)
tree5556fde7a3efda42823ee2a8b98e15d94c4e20f2 /src/tests
parente62227977bbc161d2d0ae49951f9a4fbf02a354e (diff)
Reduce explicitely recursion
When evaluating permissions, the recursive algorithm is replaced with an algorithm that eliminates the tail recursion. Change-Id: I3298c42fa658498a954f4bf7dedfad87f00ab736 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/test-perm/test-perm.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/tests/test-perm/test-perm.c b/src/tests/test-perm/test-perm.c
index 8d63e3c7..c9b60473 100644
--- a/src/tests/test-perm/test-perm.c
+++ b/src/tests/test-perm/test-perm.c
@@ -108,12 +108,13 @@ void mke(int value, int bits, char *buffer)
case 3: add(buffer, "(%c or not %c) ", c, c); break;
}
} else if (val0 != val1) {
+ if (val0 && val1)
+ add(buffer, "(");
if (val0) {
add(buffer, "not %c", c);
if (val0 != smask) {
- add(buffer, " and (");
+ add(buffer, " and ");
mke(val0, bits - 1, buffer);
- add(buffer, ")");
}
}
if (val0 && val1)
@@ -121,11 +122,12 @@ void mke(int value, int bits, char *buffer)
if (val1) {
add(buffer, "%c", c);
if (val1 != smask) {
- add(buffer, " and (");
+ add(buffer, " and ");
mke(val1, bits - 1, buffer);
- add(buffer, ")");
}
}
+ if (val0 && val1)
+ add(buffer, ")");
} else {
mke(val0, bits - 1, buffer);
}
@@ -150,10 +152,11 @@ int fulltest()
for (i = 0 ; i < 65536 ; i++) {
makeexpr(i, buffer);
j = test(buffer);
- printf("[[[ %d %s %d ]]]\n", i, i==j?"==":"!=", j);
+ printf("[[[ %d %s %d ]]] %d %s\n", i, i==j?"==":"!=", j, (int)strlen(buffer), buffer);
if (i != j)
r = 1;
}
+ return r;
}
int main()