[m-rev.] diff: add tests of uint8 to decimal string conversion

Julien Fischer jfischer at opturion.com
Sun Oct 31 19:54:12 AEDT 2021


Add tests of uint8 to decimal string conversion.

tests/hard_coded/uint8_to_string.{m,exp}:
tests/hard_coded/Mmakefile:
     Add the new test.

Julien.

diff --git a/tests/hard_coded/Mmakefile b/tests/hard_coded/Mmakefile
index 465020d..b9b5bb0 100644
--- a/tests/hard_coded/Mmakefile
+++ b/tests/hard_coded/Mmakefile
@@ -470,6 +470,7 @@ ORDINARY_PROGS = \
  	uint64_switch_test \
  	uint64_to_string \
  	uint8_switch_test \
+	uint8_to_string \
  	uint_string_conv \
  	uint_switch_test \
  	unicode_test \
diff --git a/tests/hard_coded/uint8_to_string.exp b/tests/hard_coded/uint8_to_string.exp
new file mode 100644
index 0000000..1380c50
--- /dev/null
+++ b/tests/hard_coded/uint8_to_string.exp
@@ -0,0 +1,23 @@
+0
+1
+2
+7
+8
+9
+10
+11
+14
+15
+16
+31
+32
+63
+64
+99
+100
+101
+126
+127
+128
+254
+255
diff --git a/tests/hard_coded/uint8_to_string.m b/tests/hard_coded/uint8_to_string.m
new file mode 100644
index 0000000..51db1b0
--- /dev/null
+++ b/tests/hard_coded/uint8_to_string.m
@@ -0,0 +1,63 @@
+%---------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%---------------------------------------------------------------------------%
+%
+% A test of uint8 to decimal string conversion.
+%
+%---------------------------------------------------------------------------%
+
+:- module uint8_to_string.
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module list.
+:- import_module string.
+:- import_module uint8.
+
+%---------------------------------------------------------------------------%
+
+main(!IO) :-
+    P = (pred(U::in, !.IO::di, !:IO::uo) is det :-
+        io.print_line(uint8_to_string(U), !IO)
+    ),
+    list.foldl(P, test_numbers, !IO).
+
+:- func test_numbers = list(uint8).
+
+test_numbers = [
+    0u8,
+    1u8,
+    2u8,
+    7u8,
+    8u8,
+    9u8,
+    10u8,
+    11u8,
+    14u8,
+    15u8,
+    16u8,
+    31u8,
+    32u8,
+    63u8,
+    64u8,
+    99u8,
+    100u8,
+    101u8,
+    126u8,  % max_int8 - 1
+    127u8,  % max_int8
+    128u8,  % max_int8 + 1
+    254u8,  % max_uint8 - 1
+    255u8   % max_uint8
+].
+
+%---------------------------------------------------------------------------%
+:- end_module uint8_to_string.
+%---------------------------------------------------------------------------%




More information about the reviews mailing list