diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core/test_intvars.in | 50 | ||||
-rw-r--r-- | tests/core/test_intvars.out | 5 | ||||
-rw-r--r-- | tests/test_core.py | 53 |
3 files changed, 58 insertions, 50 deletions
diff --git a/tests/core/test_intvars.in b/tests/core/test_intvars.in new file mode 100644 index 00000000..7cf7df89 --- /dev/null +++ b/tests/core/test_intvars.in @@ -0,0 +1,50 @@ + + #include <stdio.h> + int global = 20; + int *far; + int main() + { + int x = 5; + int y = x+17; + int z = (y-1)/2; // Should stay an integer after division! + y += 1; + int w = x*3+4; + int k = w < 15 ? 99 : 101; + far = &k; + *far += global; + int i = k > 100; // Should be an int, not a bool! + int j = i << 6; + j >>= 1; + j = j ^ 5; + int h = 1; + h |= 0; + int p = h; + p &= 0; + printf("*%d,%d,%d,%d,%d,%d,%d,%d,%d*\n", x, y, z, w, k, i, j, h, p); + + long hash = -1; + size_t perturb; + int ii = 0; + for (perturb = hash; ; perturb >>= 5) { + printf("%d:%d", ii, perturb); + ii++; + if (ii == 9) break; + printf(","); + } + printf("*\n"); + printf("*%.1d,%.2d*\n", 56, 9); + + // Fixed-point math on 64-bit ints. Tricky to support since we have no 64-bit shifts in JS + { + struct Fixed { + static int Mult(int a, int b) { + return ((long long)a * (long long)b) >> 16; + } + }; + printf("fixed:%d\n", Fixed::Mult(150000, 140000)); + } + + printf("*%ld*%p\n", (long)21, &hash); // The %p should not enter an infinite loop! + return 0; + } +
\ No newline at end of file diff --git a/tests/core/test_intvars.out b/tests/core/test_intvars.out new file mode 100644 index 00000000..9d1cada7 --- /dev/null +++ b/tests/core/test_intvars.out @@ -0,0 +1,5 @@ +*5,23,10,19,121,1,37,1,0* +0:-1,1:134217727,2:4194303,3:131071,4:4095,5:127,6:3,7:0,8:0* +*56,09* +fixed:320434 +*21*
\ No newline at end of file diff --git a/tests/test_core.py b/tests/test_core.py index fde5c8ca..9f5f5a4c 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -20,57 +20,10 @@ class T(RunnerCore): # Short name, to make it more fun to use manually on the co def test_intvars(self): if self.emcc_args == None: return self.skip('needs ta2') - src = ''' - #include <stdio.h> - int global = 20; - int *far; - int main() - { - int x = 5; - int y = x+17; - int z = (y-1)/2; // Should stay an integer after division! - y += 1; - int w = x*3+4; - int k = w < 15 ? 99 : 101; - far = &k; - *far += global; - int i = k > 100; // Should be an int, not a bool! - int j = i << 6; - j >>= 1; - j = j ^ 5; - int h = 1; - h |= 0; - int p = h; - p &= 0; - printf("*%d,%d,%d,%d,%d,%d,%d,%d,%d*\\n", x, y, z, w, k, i, j, h, p); - - long hash = -1; - size_t perturb; - int ii = 0; - for (perturb = hash; ; perturb >>= 5) { - printf("%d:%d", ii, perturb); - ii++; - if (ii == 9) break; - printf(","); - } - printf("*\\n"); - printf("*%.1d,%.2d*\\n", 56, 9); - - // Fixed-point math on 64-bit ints. Tricky to support since we have no 64-bit shifts in JS - { - struct Fixed { - static int Mult(int a, int b) { - return ((long long)a * (long long)b) >> 16; - } - }; - printf("fixed:%d\\n", Fixed::Mult(150000, 140000)); - } + test_path = path_from_root('tests', 'core', 'test_intvars') + src, output = (test_path + s for s in ('.in', '.out')) - printf("*%ld*%p\\n", (long)21, &hash); // The %p should not enter an infinite loop! - return 0; - } - ''' - self.do_run(src, '*5,23,10,19,121,1,37,1,0*\n0:-1,1:134217727,2:4194303,3:131071,4:4095,5:127,6:3,7:0,8:0*\n*56,09*\nfixed:320434\n*21*') + self.do_run_from_file(src, output) def test_sintvars(self): Settings.CORRECT_SIGNS = 1 # Relevant to this test |