aboutsummaryrefslogtreecommitdiffstats
path: root/test/mppa/sort/test.c
diff options
context:
space:
mode:
authorCyril SIX <cyril.six@kalray.eu>2018-04-17 15:33:14 +0200
committerCyril SIX <cyril.six@kalray.eu>2018-04-17 15:33:14 +0200
commit1b8cf73abc25b1bb167db770a622704f0d672691 (patch)
tree50582ad9bde220947d3b30d3262d314fb27bb554 /test/mppa/sort/test.c
parenteb1e1c79fa3fc882b68c67d781f7b64e74e00828 (diff)
downloadcompcert-kvx-1b8cf73abc25b1bb167db770a622704f0d672691.tar.gz
compcert-kvx-1b8cf73abc25b1bb167db770a622704f0d672691.zip
MPPA - added merge sort + corrected bug in insertion + testing them together
Diffstat (limited to 'test/mppa/sort/test.c')
-rw-r--r--test/mppa/sort/test.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/mppa/sort/test.c b/test/mppa/sort/test.c
new file mode 100644
index 00000000..e5e14fef
--- /dev/null
+++ b/test/mppa/sort/test.c
@@ -0,0 +1,33 @@
+#include "../lib/prng.h"
+#include "../lib/types.h"
+
+#include "test.h"
+#include "insertion.h"
+#include "selection.h"
+#include "merge.h"
+
+int main(void){
+ uint64_t T[SIZE];
+ uint64_t res1[SIZE], res2[SIZE], res3[SIZE];
+ srand(42);
+
+ for (int i = 0 ; i < SIZE ; i++)
+ T[i] = randlong();
+
+ /* insertion sort */
+ if (insert_sort(res1, T) < 0) return -1;
+
+ /* selection sort */
+ if (select_sort(res2, T) < 0) return -2;
+
+ /* merge sort */
+ if (merge_sort(res3, T) < 0) return -3;
+
+ /* We should have: res1[i] == res2[i] == res3[i] */
+ for (int i = 0 ; i < SIZE ; i++){
+ if (!(res1[i] == res2[i] && res2[i] == res3[i]))
+ return -4;
+ }
+
+ return 0;
+}