aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasilis Kalintiris <ehostunreach@gmail.com>2013-12-07 14:43:50 +0200
committerVasilis Kalintiris <ehostunreach@gmail.com>2013-12-07 19:35:59 +0200
commit0fc6c9d2e6356e5b39328f4c93255cc34e0acd72 (patch)
tree5c7db083b30fe7d4350206f610999d8af8257cc8
parentdce3bb354dd13d1e9bae962b925b0941c9744837 (diff)
Use do_run_from_file() for test_bsearch
-rw-r--r--tests/core/test_bsearch.in47
-rw-r--r--tests/core/test_bsearch.out10
-rw-r--r--tests/test_core.py51
3 files changed, 60 insertions, 48 deletions
diff --git a/tests/core/test_bsearch.in b/tests/core/test_bsearch.in
new file mode 100644
index 00000000..285210bd
--- /dev/null
+++ b/tests/core/test_bsearch.in
@@ -0,0 +1,47 @@
+
+ #include <stdlib.h>
+ #include <stdio.h>
+
+ int cmp(const void* key, const void* member) {
+ return *(int *)key - *(int *)member;
+ }
+
+ void printResult(int* needle, int* haystack, unsigned int len) {
+ void *result = bsearch(needle, haystack, len, sizeof(unsigned int), cmp);
+
+ if (result == NULL) {
+ printf("null\n");
+ } else {
+ printf("%d\n", *(unsigned int *)result);
+ }
+ }
+
+ int main() {
+ int a[] = { -2, -1, 0, 6, 7, 9 };
+ int b[] = { 0, 1 };
+
+ /* Find all keys that exist. */
+ for(int i = 0; i < 6; i++) {
+ int val = a[i];
+
+ printResult(&val, a, 6);
+ }
+
+ /* Keys that are covered by the range of the array but aren't in
+ * the array cannot be found.
+ */
+ int v1 = 3;
+ int v2 = 8;
+ printResult(&v1, a, 6);
+ printResult(&v2, a, 6);
+
+ /* Keys outside the range of the array cannot be found. */
+ int v3 = -1;
+ int v4 = 2;
+
+ printResult(&v3, b, 2);
+ printResult(&v4, b, 2);
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_bsearch.out b/tests/core/test_bsearch.out
new file mode 100644
index 00000000..cc6a3205
--- /dev/null
+++ b/tests/core/test_bsearch.out
@@ -0,0 +1,10 @@
+-2
+-1
+0
+6
+7
+9
+null
+null
+null
+null \ No newline at end of file
diff --git a/tests/test_core.py b/tests/test_core.py
index 827cbf7d..ea25d83f 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -2584,55 +2584,10 @@ The current type of b is: 9
def test_bsearch(self):
if Settings.QUANTUM_SIZE == 1: return self.skip('Test cannot work with q1')
- src = '''
- #include <stdlib.h>
- #include <stdio.h>
-
- int cmp(const void* key, const void* member) {
- return *(int *)key - *(int *)member;
- }
-
- void printResult(int* needle, int* haystack, unsigned int len) {
- void *result = bsearch(needle, haystack, len, sizeof(unsigned int), cmp);
-
- if (result == NULL) {
- printf("null\\n");
- } else {
- printf("%d\\n", *(unsigned int *)result);
- }
- }
-
- int main() {
- int a[] = { -2, -1, 0, 6, 7, 9 };
- int b[] = { 0, 1 };
-
- /* Find all keys that exist. */
- for(int i = 0; i < 6; i++) {
- int val = a[i];
-
- printResult(&val, a, 6);
- }
-
- /* Keys that are covered by the range of the array but aren't in
- * the array cannot be found.
- */
- int v1 = 3;
- int v2 = 8;
- printResult(&v1, a, 6);
- printResult(&v2, a, 6);
-
- /* Keys outside the range of the array cannot be found. */
- int v3 = -1;
- int v4 = 2;
-
- printResult(&v3, b, 2);
- printResult(&v4, b, 2);
-
- return 0;
- }
- '''
+ test_path = path_from_root('tests', 'core', 'test_bsearch')
+ src, output = (test_path + s for s in ('.in', '.out'))
- self.do_run(src, '-2\n-1\n0\n6\n7\n9\nnull\nnull\nnull\nnull')
+ self.do_run_from_file(src, output)
def test_nestedstructs(self):
src = '''