From: Lucas Bajolet Date: Mon, 10 Aug 2015 15:24:45 +0000 (-0400) Subject: tests: Added test for fixed-size integers X-Git-Tag: v0.7.8~89^2 X-Git-Url: http://nitlanguage.org tests: Added test for fixed-size integers Signed-off-by: Lucas Bajolet --- diff --git a/tests/sav/test_fix_int.res b/tests/sav/test_fix_int.res new file mode 100644 index 0000000..e35445d --- /dev/null +++ b/tests/sav/test_fix_int.res @@ -0,0 +1,84 @@ + +-128 +-128 +0x80 +127 +127 +0x7f +127 +127 +127 +127 + + +-32768 +-32768 +0x00 +32767 +32767 +0xff +-1 +32767 +32767 +32767 + + +0 +0 +0x00 +65535 +65535 +0xff +-1 +-1 +65535 +65535 + + +-2147483648 +-2147483648 +0x00 +2147483647 +2147483647 +0xff +-1 +-1 +65535 +2147483647 + + +0 +0 +0x00 +4294967295 +4294967295 +0xff +-1 +-1 +65535 +-1 + + +0x00 +0 +0x00 +0xff +255 +0xff +-1 +255 +255 +255 + + +256 +256 +0x00 +255 +255 +0xff +-1 +255 +255 +255 + diff --git a/tests/test_fix_int.nit b/tests/test_fix_int.nit new file mode 100644 index 0000000..f7ecfa7 --- /dev/null +++ b/tests/test_fix_int.nit @@ -0,0 +1,79 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# This file is free software, which comes along with NIT. This software is +# distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; +# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. You can modify it is you want, provided this header +# is kept unaltered, and a notification of the changes is added. +# You are allowed to redistribute it and sell it, alone or is a part of +# another product. + +# Tests for the fixed-length integers variant of standard +module test_fix_int + +private fun test_int(i, j, l: Numeric) do + print "" + var k = i + j + + print k + print k.to_i + print k.to_b + + k = l + j + + print k + print k.to_i + print k.to_b + + print k.to_i8 + print k.to_i16 + print k.to_u16 + print k.to_i32 + print "" +end + +var i: Numeric +var j: Numeric +var l: Numeric + +j = 126i8 +i = 2i8 +l = 1i8 + +test_int(i, j, l) + +j = 32766i16 +i = 2i16 +l = 1i16 + +test_int(i, j, l) + +j = 65534u16 +i = 2u16 +l = 1u16 + +test_int(i, j, l) + +j = 2147483646i32 +i = 2i32 +l = 1i32 + +test_int(i, j, l) + +j = 4294967294u32 +i = 2u32 +l = 1u32 + +test_int(i, j, l) + +j = 254u8 +i = 2u8 +l = 1u8 + +test_int(i, j, l) + +j = 254 +i = 2 +l = 1 + +test_int(i, j, l)