summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVasilis Kalintiris <ehostunreach@gmail.com>2013-12-06 22:46:25 +0200
committerVasilis Kalintiris <ehostunreach@gmail.com>2013-12-07 19:35:51 +0200
commit63678388a4028a93c7bdd0ac45263faf509ce955 (patch)
tree87de05bfd8b9f4ea5edf61d51b9cc096f7bd911b /tests
parentd2b62ebf3f225d543c40d2ef566c9a1af5003615 (diff)
Use do_run_from_file() for test_frexp
Diffstat (limited to 'tests')
-rw-r--r--tests/core/test_frexp.in32
-rw-r--r--tests/core/test_frexp.out7
-rw-r--r--tests/test_core.py41
3 files changed, 42 insertions, 38 deletions
diff --git a/tests/core/test_frexp.in b/tests/core/test_frexp.in
new file mode 100644
index 00000000..d3facca8
--- /dev/null
+++ b/tests/core/test_frexp.in
@@ -0,0 +1,32 @@
+
+ #include <stdio.h>
+ #include <math.h>
+ #include <assert.h>
+
+ static const double tol=1e-16;
+
+ void test_value(double value)
+ {
+ int exponent;
+ double x=frexp(value, &exponent);
+ double expected=x*pow(2.0, exponent);
+
+ printf("%f=%f*2^%d\n", value, x, exponent);
+
+ assert(fabs(expected-value)<tol);
+ assert(x==0 || (fabs(x)>=5e-1 && fabs(x)<1)); // x has a magnitude in the interval [1/2, 1)
+ }
+
+ int main()
+ {
+ test_value(0);
+ test_value(100.1);
+ test_value(-100.1);
+ test_value(.5);
+ test_value(-.5);
+ test_value(1-1e-16);
+ test_value(-(1-1e-16));
+
+ return 0;
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_frexp.out b/tests/core/test_frexp.out
new file mode 100644
index 00000000..341b790e
--- /dev/null
+++ b/tests/core/test_frexp.out
@@ -0,0 +1,7 @@
+0.000000=0.000000*2^0
+100.100000=0.782031*2^7
+-100.100000=-0.782031*2^7
+0.500000=0.500000*2^0
+-0.500000=-0.500000*2^0
+1.000000=1.000000*2^0
+-1.000000=-1.000000*2^0 \ No newline at end of file
diff --git a/tests/test_core.py b/tests/test_core.py
index 5d827234..3610ca6a 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -819,45 +819,10 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co
self.do_run(src, expected)
def test_frexp(self):
- src = '''
- #include <stdio.h>
- #include <math.h>
- #include <assert.h>
-
- static const double tol=1e-16;
-
- void test_value(double value)
- {
- int exponent;
- double x=frexp(value, &exponent);
- double expected=x*pow(2.0, exponent);
-
- printf("%f=%f*2^%d\\n", value, x, exponent);
-
- assert(fabs(expected-value)<tol);
- assert(x==0 || (fabs(x)>=5e-1 && fabs(x)<1)); // x has a magnitude in the interval [1/2, 1)
- }
-
- int main()
- {
- test_value(0);
- test_value(100.1);
- test_value(-100.1);
- test_value(.5);
- test_value(-.5);
- test_value(1-1e-16);
- test_value(-(1-1e-16));
+ test_path = path_from_root('tests', 'core', 'test_frexp')
+ src, output = (test_path + s for s in ('.in', '.out'))
- return 0;
- }
- '''
- self.do_run(src, '''0.000000=0.000000*2^0
-100.100000=0.782031*2^7
--100.100000=-0.782031*2^7
-0.500000=0.500000*2^0
--0.500000=-0.500000*2^0
-1.000000=1.000000*2^0
--1.000000=-1.000000*2^0''')
+ self.do_run_from_file(src, output)
def test_rounding(self):
src = '''