[m-rev.] diff: add basic tsts of 8-bit arithmetic
Julien Fischer
jfischer at opturion.com
Mon Aug 21 21:26:11 AEST 2017
Add tests of basic arithmetic for 8-bit integers.
tests/hard_coded/arith_int8.{m,exp}:
tests/hard_coded/arith_uint8.{m,exp}:
tests/hard_coded/Mmakefile:
As above.
diff --git a/tests/hard_coded/Mmakefile b/tests/hard_coded/Mmakefile
index 3448acfc9..20e12cfd4 100644
--- a/tests/hard_coded/Mmakefile
+++ b/tests/hard_coded/Mmakefile
@@ -618,6 +618,8 @@ ifeq "$(findstring profdeep,$(GRADE))" ""
NON_PROFDEEP_PROGS = \
$(NON_PROFDEEP_PROGS_2) \
allow_stubs \
+ arith_int8 \
+ arith_uint8 \
bitmap_empty \
bitmap_test \
bit_buffer_test \
diff --git a/tests/hard_coded/arith_int8.exp b/tests/hard_coded/arith_int8.exp
index e69de29bb..5bc2a5cb6 100644
--- a/tests/hard_coded/arith_int8.exp
+++ b/tests/hard_coded/arith_int8.exp
@@ -0,0 +1,891 @@
+*** Test unary operation '+' ***
+
++ -128 = -128
++ -16 = -16
++ -10 = -10
++ -8 = -8
++ -2 = -2
++ -1 = -1
++ 0 = 0
++ 1 = 1
++ 2 = 2
++ 8 = 8
++ 10 = 10
++ 16 = 16
++ 127 = 127
+
+*** Test unary operation '-' ***
+
+- -128 = -128
+- -16 = 16
+- -10 = 10
+- -8 = 8
+- -2 = 2
+- -1 = 1
+- 0 = 0
+- 1 = -1
+- 2 = -2
+- 8 = -8
+- 10 = -10
+- 16 = -16
+- 127 = -127
+
+*** Test binary operation '+' ***
+
+-128 + -128 = 0
+-128 + -16 = 112
+-128 + -10 = 118
+-128 + -8 = 120
+-128 + -2 = 126
+-128 + -1 = 127
+-128 + 0 = -128
+-128 + 1 = -127
+-128 + 2 = -126
+-128 + 8 = -120
+-128 + 10 = -118
+-128 + 16 = -112
+-128 + 127 = -1
+-16 + -128 = 112
+-16 + -16 = -32
+-16 + -10 = -26
+-16 + -8 = -24
+-16 + -2 = -18
+-16 + -1 = -17
+-16 + 0 = -16
+-16 + 1 = -15
+-16 + 2 = -14
+-16 + 8 = -8
+-16 + 10 = -6
+-16 + 16 = 0
+-16 + 127 = 111
+-10 + -128 = 118
+-10 + -16 = -26
+-10 + -10 = -20
+-10 + -8 = -18
+-10 + -2 = -12
+-10 + -1 = -11
+-10 + 0 = -10
+-10 + 1 = -9
+-10 + 2 = -8
+-10 + 8 = -2
+-10 + 10 = 0
+-10 + 16 = 6
+-10 + 127 = 117
+-8 + -128 = 120
+-8 + -16 = -24
+-8 + -10 = -18
+-8 + -8 = -16
+-8 + -2 = -10
+-8 + -1 = -9
+-8 + 0 = -8
+-8 + 1 = -7
+-8 + 2 = -6
+-8 + 8 = 0
+-8 + 10 = 2
+-8 + 16 = 8
+-8 + 127 = 119
+-2 + -128 = 126
+-2 + -16 = -18
+-2 + -10 = -12
+-2 + -8 = -10
+-2 + -2 = -4
+-2 + -1 = -3
+-2 + 0 = -2
+-2 + 1 = -1
+-2 + 2 = 0
+-2 + 8 = 6
+-2 + 10 = 8
+-2 + 16 = 14
+-2 + 127 = 125
+-1 + -128 = 127
+-1 + -16 = -17
+-1 + -10 = -11
+-1 + -8 = -9
+-1 + -2 = -3
+-1 + -1 = -2
+-1 + 0 = -1
+-1 + 1 = 0
+-1 + 2 = 1
+-1 + 8 = 7
+-1 + 10 = 9
+-1 + 16 = 15
+-1 + 127 = 126
+0 + -128 = -128
+0 + -16 = -16
+0 + -10 = -10
+0 + -8 = -8
+0 + -2 = -2
+0 + -1 = -1
+0 + 0 = 0
+0 + 1 = 1
+0 + 2 = 2
+0 + 8 = 8
+0 + 10 = 10
+0 + 16 = 16
+0 + 127 = 127
+1 + -128 = -127
+1 + -16 = -15
+1 + -10 = -9
+1 + -8 = -7
+1 + -2 = -1
+1 + -1 = 0
+1 + 0 = 1
+1 + 1 = 2
+1 + 2 = 3
+1 + 8 = 9
+1 + 10 = 11
+1 + 16 = 17
+1 + 127 = -128
+2 + -128 = -126
+2 + -16 = -14
+2 + -10 = -8
+2 + -8 = -6
+2 + -2 = 0
+2 + -1 = 1
+2 + 0 = 2
+2 + 1 = 3
+2 + 2 = 4
+2 + 8 = 10
+2 + 10 = 12
+2 + 16 = 18
+2 + 127 = -127
+8 + -128 = -120
+8 + -16 = -8
+8 + -10 = -2
+8 + -8 = 0
+8 + -2 = 6
+8 + -1 = 7
+8 + 0 = 8
+8 + 1 = 9
+8 + 2 = 10
+8 + 8 = 16
+8 + 10 = 18
+8 + 16 = 24
+8 + 127 = -121
+10 + -128 = -118
+10 + -16 = -6
+10 + -10 = 0
+10 + -8 = 2
+10 + -2 = 8
+10 + -1 = 9
+10 + 0 = 10
+10 + 1 = 11
+10 + 2 = 12
+10 + 8 = 18
+10 + 10 = 20
+10 + 16 = 26
+10 + 127 = -119
+16 + -128 = -112
+16 + -16 = 0
+16 + -10 = 6
+16 + -8 = 8
+16 + -2 = 14
+16 + -1 = 15
+16 + 0 = 16
+16 + 1 = 17
+16 + 2 = 18
+16 + 8 = 24
+16 + 10 = 26
+16 + 16 = 32
+16 + 127 = -113
+127 + -128 = -1
+127 + -16 = 111
+127 + -10 = 117
+127 + -8 = 119
+127 + -2 = 125
+127 + -1 = 126
+127 + 0 = 127
+127 + 1 = -128
+127 + 2 = -127
+127 + 8 = -121
+127 + 10 = -119
+127 + 16 = -113
+127 + 127 = -2
+
+*** Test binary operation '-' ***
+
+-128 - -128 = 0
+-128 - -16 = -112
+-128 - -10 = -118
+-128 - -8 = -120
+-128 - -2 = -126
+-128 - -1 = -127
+-128 - 0 = -128
+-128 - 1 = 127
+-128 - 2 = 126
+-128 - 8 = 120
+-128 - 10 = 118
+-128 - 16 = 112
+-128 - 127 = 1
+-16 - -128 = 112
+-16 - -16 = 0
+-16 - -10 = -6
+-16 - -8 = -8
+-16 - -2 = -14
+-16 - -1 = -15
+-16 - 0 = -16
+-16 - 1 = -17
+-16 - 2 = -18
+-16 - 8 = -24
+-16 - 10 = -26
+-16 - 16 = -32
+-16 - 127 = 113
+-10 - -128 = 118
+-10 - -16 = 6
+-10 - -10 = 0
+-10 - -8 = -2
+-10 - -2 = -8
+-10 - -1 = -9
+-10 - 0 = -10
+-10 - 1 = -11
+-10 - 2 = -12
+-10 - 8 = -18
+-10 - 10 = -20
+-10 - 16 = -26
+-10 - 127 = 119
+-8 - -128 = 120
+-8 - -16 = 8
+-8 - -10 = 2
+-8 - -8 = 0
+-8 - -2 = -6
+-8 - -1 = -7
+-8 - 0 = -8
+-8 - 1 = -9
+-8 - 2 = -10
+-8 - 8 = -16
+-8 - 10 = -18
+-8 - 16 = -24
+-8 - 127 = 121
+-2 - -128 = 126
+-2 - -16 = 14
+-2 - -10 = 8
+-2 - -8 = 6
+-2 - -2 = 0
+-2 - -1 = -1
+-2 - 0 = -2
+-2 - 1 = -3
+-2 - 2 = -4
+-2 - 8 = -10
+-2 - 10 = -12
+-2 - 16 = -18
+-2 - 127 = 127
+-1 - -128 = 127
+-1 - -16 = 15
+-1 - -10 = 9
+-1 - -8 = 7
+-1 - -2 = 1
+-1 - -1 = 0
+-1 - 0 = -1
+-1 - 1 = -2
+-1 - 2 = -3
+-1 - 8 = -9
+-1 - 10 = -11
+-1 - 16 = -17
+-1 - 127 = -128
+0 - -128 = -128
+0 - -16 = 16
+0 - -10 = 10
+0 - -8 = 8
+0 - -2 = 2
+0 - -1 = 1
+0 - 0 = 0
+0 - 1 = -1
+0 - 2 = -2
+0 - 8 = -8
+0 - 10 = -10
+0 - 16 = -16
+0 - 127 = -127
+1 - -128 = -127
+1 - -16 = 17
+1 - -10 = 11
+1 - -8 = 9
+1 - -2 = 3
+1 - -1 = 2
+1 - 0 = 1
+1 - 1 = 0
+1 - 2 = -1
+1 - 8 = -7
+1 - 10 = -9
+1 - 16 = -15
+1 - 127 = -126
+2 - -128 = -126
+2 - -16 = 18
+2 - -10 = 12
+2 - -8 = 10
+2 - -2 = 4
+2 - -1 = 3
+2 - 0 = 2
+2 - 1 = 1
+2 - 2 = 0
+2 - 8 = -6
+2 - 10 = -8
+2 - 16 = -14
+2 - 127 = -125
+8 - -128 = -120
+8 - -16 = 24
+8 - -10 = 18
+8 - -8 = 16
+8 - -2 = 10
+8 - -1 = 9
+8 - 0 = 8
+8 - 1 = 7
+8 - 2 = 6
+8 - 8 = 0
+8 - 10 = -2
+8 - 16 = -8
+8 - 127 = -119
+10 - -128 = -118
+10 - -16 = 26
+10 - -10 = 20
+10 - -8 = 18
+10 - -2 = 12
+10 - -1 = 11
+10 - 0 = 10
+10 - 1 = 9
+10 - 2 = 8
+10 - 8 = 2
+10 - 10 = 0
+10 - 16 = -6
+10 - 127 = -117
+16 - -128 = -112
+16 - -16 = 32
+16 - -10 = 26
+16 - -8 = 24
+16 - -2 = 18
+16 - -1 = 17
+16 - 0 = 16
+16 - 1 = 15
+16 - 2 = 14
+16 - 8 = 8
+16 - 10 = 6
+16 - 16 = 0
+16 - 127 = -111
+127 - -128 = -1
+127 - -16 = -113
+127 - -10 = -119
+127 - -8 = -121
+127 - -2 = -127
+127 - -1 = -128
+127 - 0 = 127
+127 - 1 = 126
+127 - 2 = 125
+127 - 8 = 119
+127 - 10 = 117
+127 - 16 = 111
+127 - 127 = 0
+
+*** Test binary operation '*' ***
+
+-128 * -128 = 0
+-128 * -16 = 0
+-128 * -10 = 0
+-128 * -8 = 0
+-128 * -2 = 0
+-128 * -1 = -128
+-128 * 0 = 0
+-128 * 1 = -128
+-128 * 2 = 0
+-128 * 8 = 0
+-128 * 10 = 0
+-128 * 16 = 0
+-128 * 127 = -128
+-16 * -128 = 0
+-16 * -16 = 0
+-16 * -10 = -96
+-16 * -8 = -128
+-16 * -2 = 32
+-16 * -1 = 16
+-16 * 0 = 0
+-16 * 1 = -16
+-16 * 2 = -32
+-16 * 8 = -128
+-16 * 10 = 96
+-16 * 16 = 0
+-16 * 127 = 16
+-10 * -128 = 0
+-10 * -16 = -96
+-10 * -10 = 100
+-10 * -8 = 80
+-10 * -2 = 20
+-10 * -1 = 10
+-10 * 0 = 0
+-10 * 1 = -10
+-10 * 2 = -20
+-10 * 8 = -80
+-10 * 10 = -100
+-10 * 16 = 96
+-10 * 127 = 10
+-8 * -128 = 0
+-8 * -16 = -128
+-8 * -10 = 80
+-8 * -8 = 64
+-8 * -2 = 16
+-8 * -1 = 8
+-8 * 0 = 0
+-8 * 1 = -8
+-8 * 2 = -16
+-8 * 8 = -64
+-8 * 10 = -80
+-8 * 16 = -128
+-8 * 127 = 8
+-2 * -128 = 0
+-2 * -16 = 32
+-2 * -10 = 20
+-2 * -8 = 16
+-2 * -2 = 4
+-2 * -1 = 2
+-2 * 0 = 0
+-2 * 1 = -2
+-2 * 2 = -4
+-2 * 8 = -16
+-2 * 10 = -20
+-2 * 16 = -32
+-2 * 127 = 2
+-1 * -128 = -128
+-1 * -16 = 16
+-1 * -10 = 10
+-1 * -8 = 8
+-1 * -2 = 2
+-1 * -1 = 1
+-1 * 0 = 0
+-1 * 1 = -1
+-1 * 2 = -2
+-1 * 8 = -8
+-1 * 10 = -10
+-1 * 16 = -16
+-1 * 127 = -127
+0 * -128 = 0
+0 * -16 = 0
+0 * -10 = 0
+0 * -8 = 0
+0 * -2 = 0
+0 * -1 = 0
+0 * 0 = 0
+0 * 1 = 0
+0 * 2 = 0
+0 * 8 = 0
+0 * 10 = 0
+0 * 16 = 0
+0 * 127 = 0
+1 * -128 = -128
+1 * -16 = -16
+1 * -10 = -10
+1 * -8 = -8
+1 * -2 = -2
+1 * -1 = -1
+1 * 0 = 0
+1 * 1 = 1
+1 * 2 = 2
+1 * 8 = 8
+1 * 10 = 10
+1 * 16 = 16
+1 * 127 = 127
+2 * -128 = 0
+2 * -16 = -32
+2 * -10 = -20
+2 * -8 = -16
+2 * -2 = -4
+2 * -1 = -2
+2 * 0 = 0
+2 * 1 = 2
+2 * 2 = 4
+2 * 8 = 16
+2 * 10 = 20
+2 * 16 = 32
+2 * 127 = -2
+8 * -128 = 0
+8 * -16 = -128
+8 * -10 = -80
+8 * -8 = -64
+8 * -2 = -16
+8 * -1 = -8
+8 * 0 = 0
+8 * 1 = 8
+8 * 2 = 16
+8 * 8 = 64
+8 * 10 = 80
+8 * 16 = -128
+8 * 127 = -8
+10 * -128 = 0
+10 * -16 = 96
+10 * -10 = -100
+10 * -8 = -80
+10 * -2 = -20
+10 * -1 = -10
+10 * 0 = 0
+10 * 1 = 10
+10 * 2 = 20
+10 * 8 = 80
+10 * 10 = 100
+10 * 16 = -96
+10 * 127 = -10
+16 * -128 = 0
+16 * -16 = 0
+16 * -10 = 96
+16 * -8 = -128
+16 * -2 = -32
+16 * -1 = -16
+16 * 0 = 0
+16 * 1 = 16
+16 * 2 = 32
+16 * 8 = -128
+16 * 10 = -96
+16 * 16 = 0
+16 * 127 = -16
+127 * -128 = -128
+127 * -16 = 16
+127 * -10 = 10
+127 * -8 = 8
+127 * -2 = 2
+127 * -1 = -127
+127 * 0 = 0
+127 * 1 = 127
+127 * 2 = -2
+127 * 8 = -8
+127 * 10 = -10
+127 * 16 = -16
+127 * 127 = 1
+
+*** Test binary operation '/' ***
+
+-128 / -128 = 1
+-128 / -16 = 8
+-128 / -10 = 12
+-128 / -8 = 16
+-128 / -2 = 64
+-128 / -1 = -128
+-128 / 0 = <<exception>>
+-128 / 1 = -128
+-128 / 2 = -64
+-128 / 8 = -16
+-128 / 10 = -12
+-128 / 16 = -8
+-128 / 127 = -1
+-16 / -128 = 0
+-16 / -16 = 1
+-16 / -10 = 1
+-16 / -8 = 2
+-16 / -2 = 8
+-16 / -1 = 16
+-16 / 0 = <<exception>>
+-16 / 1 = -16
+-16 / 2 = -8
+-16 / 8 = -2
+-16 / 10 = -1
+-16 / 16 = -1
+-16 / 127 = 0
+-10 / -128 = 0
+-10 / -16 = 0
+-10 / -10 = 1
+-10 / -8 = 1
+-10 / -2 = 5
+-10 / -1 = 10
+-10 / 0 = <<exception>>
+-10 / 1 = -10
+-10 / 2 = -5
+-10 / 8 = -1
+-10 / 10 = -1
+-10 / 16 = 0
+-10 / 127 = 0
+-8 / -128 = 0
+-8 / -16 = 0
+-8 / -10 = 0
+-8 / -8 = 1
+-8 / -2 = 4
+-8 / -1 = 8
+-8 / 0 = <<exception>>
+-8 / 1 = -8
+-8 / 2 = -4
+-8 / 8 = -1
+-8 / 10 = 0
+-8 / 16 = 0
+-8 / 127 = 0
+-2 / -128 = 0
+-2 / -16 = 0
+-2 / -10 = 0
+-2 / -8 = 0
+-2 / -2 = 1
+-2 / -1 = 2
+-2 / 0 = <<exception>>
+-2 / 1 = -2
+-2 / 2 = -1
+-2 / 8 = 0
+-2 / 10 = 0
+-2 / 16 = 0
+-2 / 127 = 0
+-1 / -128 = 0
+-1 / -16 = 0
+-1 / -10 = 0
+-1 / -8 = 0
+-1 / -2 = 0
+-1 / -1 = 1
+-1 / 0 = <<exception>>
+-1 / 1 = -1
+-1 / 2 = 0
+-1 / 8 = 0
+-1 / 10 = 0
+-1 / 16 = 0
+-1 / 127 = 0
+0 / -128 = 0
+0 / -16 = 0
+0 / -10 = 0
+0 / -8 = 0
+0 / -2 = 0
+0 / -1 = 0
+0 / 0 = <<exception>>
+0 / 1 = 0
+0 / 2 = 0
+0 / 8 = 0
+0 / 10 = 0
+0 / 16 = 0
+0 / 127 = 0
+1 / -128 = 0
+1 / -16 = 0
+1 / -10 = 0
+1 / -8 = 0
+1 / -2 = 0
+1 / -1 = -1
+1 / 0 = <<exception>>
+1 / 1 = 1
+1 / 2 = 0
+1 / 8 = 0
+1 / 10 = 0
+1 / 16 = 0
+1 / 127 = 0
+2 / -128 = 0
+2 / -16 = 0
+2 / -10 = 0
+2 / -8 = 0
+2 / -2 = -1
+2 / -1 = -2
+2 / 0 = <<exception>>
+2 / 1 = 2
+2 / 2 = 1
+2 / 8 = 0
+2 / 10 = 0
+2 / 16 = 0
+2 / 127 = 0
+8 / -128 = 0
+8 / -16 = 0
+8 / -10 = 0
+8 / -8 = -1
+8 / -2 = -4
+8 / -1 = -8
+8 / 0 = <<exception>>
+8 / 1 = 8
+8 / 2 = 4
+8 / 8 = 1
+8 / 10 = 0
+8 / 16 = 0
+8 / 127 = 0
+10 / -128 = 0
+10 / -16 = 0
+10 / -10 = -1
+10 / -8 = -1
+10 / -2 = -5
+10 / -1 = -10
+10 / 0 = <<exception>>
+10 / 1 = 10
+10 / 2 = 5
+10 / 8 = 1
+10 / 10 = 1
+10 / 16 = 0
+10 / 127 = 0
+16 / -128 = 0
+16 / -16 = -1
+16 / -10 = -1
+16 / -8 = -2
+16 / -2 = -8
+16 / -1 = -16
+16 / 0 = <<exception>>
+16 / 1 = 16
+16 / 2 = 8
+16 / 8 = 2
+16 / 10 = 1
+16 / 16 = 1
+16 / 127 = 0
+127 / -128 = 0
+127 / -16 = -7
+127 / -10 = -12
+127 / -8 = -15
+127 / -2 = -63
+127 / -1 = -127
+127 / 0 = <<exception>>
+127 / 1 = 127
+127 / 2 = 63
+127 / 8 = 15
+127 / 10 = 12
+127 / 16 = 7
+127 / 127 = 1
+
+*** Test binary operation 'rem' ***
+
+-128 rem -128 = 0
+-128 rem -16 = 0
+-128 rem -10 = -8
+-128 rem -8 = 0
+-128 rem -2 = 0
+-128 rem -1 = 0
+-128 rem 0 = <<exception>>
+-128 rem 1 = 0
+-128 rem 2 = 0
+-128 rem 8 = 0
+-128 rem 10 = -8
+-128 rem 16 = 0
+-128 rem 127 = -1
+-16 rem -128 = -16
+-16 rem -16 = 0
+-16 rem -10 = -6
+-16 rem -8 = 0
+-16 rem -2 = 0
+-16 rem -1 = 0
+-16 rem 0 = <<exception>>
+-16 rem 1 = 0
+-16 rem 2 = 0
+-16 rem 8 = 0
+-16 rem 10 = -6
+-16 rem 16 = 0
+-16 rem 127 = -16
+-10 rem -128 = -10
+-10 rem -16 = -10
+-10 rem -10 = 0
+-10 rem -8 = -2
+-10 rem -2 = 0
+-10 rem -1 = 0
+-10 rem 0 = <<exception>>
+-10 rem 1 = 0
+-10 rem 2 = 0
+-10 rem 8 = -2
+-10 rem 10 = 0
+-10 rem 16 = -10
+-10 rem 127 = -10
+-8 rem -128 = -8
+-8 rem -16 = -8
+-8 rem -10 = -8
+-8 rem -8 = 0
+-8 rem -2 = 0
+-8 rem -1 = 0
+-8 rem 0 = <<exception>>
+-8 rem 1 = 0
+-8 rem 2 = 0
+-8 rem 8 = 0
+-8 rem 10 = -8
+-8 rem 16 = -8
+-8 rem 127 = -8
+-2 rem -128 = -2
+-2 rem -16 = -2
+-2 rem -10 = -2
+-2 rem -8 = -2
+-2 rem -2 = 0
+-2 rem -1 = 0
+-2 rem 0 = <<exception>>
+-2 rem 1 = 0
+-2 rem 2 = 0
+-2 rem 8 = -2
+-2 rem 10 = -2
+-2 rem 16 = -2
+-2 rem 127 = -2
+-1 rem -128 = -1
+-1 rem -16 = -1
+-1 rem -10 = -1
+-1 rem -8 = -1
+-1 rem -2 = -1
+-1 rem -1 = 0
+-1 rem 0 = <<exception>>
+-1 rem 1 = 0
+-1 rem 2 = -1
+-1 rem 8 = -1
+-1 rem 10 = -1
+-1 rem 16 = -1
+-1 rem 127 = -1
+0 rem -128 = 0
+0 rem -16 = 0
+0 rem -10 = 0
+0 rem -8 = 0
+0 rem -2 = 0
+0 rem -1 = 0
+0 rem 0 = <<exception>>
+0 rem 1 = 0
+0 rem 2 = 0
+0 rem 8 = 0
+0 rem 10 = 0
+0 rem 16 = 0
+0 rem 127 = 0
+1 rem -128 = 1
+1 rem -16 = 1
+1 rem -10 = 1
+1 rem -8 = 1
+1 rem -2 = 1
+1 rem -1 = 0
+1 rem 0 = <<exception>>
+1 rem 1 = 0
+1 rem 2 = 1
+1 rem 8 = 1
+1 rem 10 = 1
+1 rem 16 = 1
+1 rem 127 = 1
+2 rem -128 = 2
+2 rem -16 = 2
+2 rem -10 = 2
+2 rem -8 = 2
+2 rem -2 = 0
+2 rem -1 = 0
+2 rem 0 = <<exception>>
+2 rem 1 = 0
+2 rem 2 = 0
+2 rem 8 = 2
+2 rem 10 = 2
+2 rem 16 = 2
+2 rem 127 = 2
+8 rem -128 = 8
+8 rem -16 = 8
+8 rem -10 = 8
+8 rem -8 = 0
+8 rem -2 = 0
+8 rem -1 = 0
+8 rem 0 = <<exception>>
+8 rem 1 = 0
+8 rem 2 = 0
+8 rem 8 = 0
+8 rem 10 = 8
+8 rem 16 = 8
+8 rem 127 = 8
+10 rem -128 = 10
+10 rem -16 = 10
+10 rem -10 = 0
+10 rem -8 = 2
+10 rem -2 = 0
+10 rem -1 = 0
+10 rem 0 = <<exception>>
+10 rem 1 = 0
+10 rem 2 = 0
+10 rem 8 = 2
+10 rem 10 = 0
+10 rem 16 = 10
+10 rem 127 = 10
+16 rem -128 = 16
+16 rem -16 = 0
+16 rem -10 = 6
+16 rem -8 = 0
+16 rem -2 = 0
+16 rem -1 = 0
+16 rem 0 = <<exception>>
+16 rem 1 = 0
+16 rem 2 = 0
+16 rem 8 = 0
+16 rem 10 = 6
+16 rem 16 = 0
+16 rem 127 = 16
+127 rem -128 = 127
+127 rem -16 = 15
+127 rem -10 = 7
+127 rem -8 = 7
+127 rem -2 = 1
+127 rem -1 = 0
+127 rem 0 = <<exception>>
+127 rem 1 = 0
+127 rem 2 = 1
+127 rem 8 = 7
+127 rem 10 = 7
+127 rem 16 = 15
+127 rem 127 = 0
diff --git a/tests/hard_coded/arith_int8.m b/tests/hard_coded/arith_int8.m
index e69de29bb..57540e6ea 100644
--- a/tests/hard_coded/arith_int8.m
+++ b/tests/hard_coded/arith_int8.m
@@ -0,0 +1,120 @@
+%---------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%---------------------------------------------------------------------------%
+
+% Test arithmetic operations for signed 8-bit integers.
+
+:- module arith_int8.
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is cc_multi.
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module int8.
+
+:- import_module exception.
+:- import_module list.
+:- import_module string.
+
+%---------------------------------------------------------------------------%
+
+main(!IO) :-
+ run_unop_test(int8.(+), "+", !IO),
+ io.nl(!IO),
+ run_unop_test(int8.(-), "-", !IO),
+ io.nl(!IO),
+ % int8.abs NYI.
+ %run_unop_test(int8.abs, "abs", !IO),
+ %io.nl(!IO),
+ run_binop_test((func(X, Y) = X + Y), "+", !IO),
+ io.nl(!IO),
+ run_binop_test((func(X, Y) = X - Y), "-", !IO),
+ io.nl(!IO),
+ run_binop_test((func(X, Y) = X * Y), "*", !IO),
+ io.nl(!IO),
+ run_binop_test((func(X, Y) = X / Y), "/", !IO),
+ io.nl(!IO),
+ run_binop_test((func(X, Y) = X rem Y), "rem", !IO).
+
+%---------------------------------------------------------------------------%
+
+:- pred run_unop_test((func(int8) = int8)::in, string::in,
+ io::di, io::uo) is cc_multi.
+
+run_unop_test(UnOpFunc, Desc, !IO) :-
+ io.format("*** Test unary operation '%s' ***\n\n", [s(Desc)], !IO),
+ As = numbers,
+ list.foldl(run_unop_test_2(UnOpFunc, Desc), As, !IO).
+
+:- pred run_unop_test_2((func(int8) = int8)::in, string::in, int8::in,
+ io::di, io::uo) is cc_multi.
+
+run_unop_test_2(UnOpFunc, Desc, A, !IO) :-
+ ( try []
+ Result0 = UnOpFunc(A)
+ then
+ ResultStr = int8_to_string(Result0)
+ catch_any _ ->
+ ResultStr = "<<exception>>"
+ ),
+ io.format("%s %s = %s\n",
+ [s(Desc), s(int8_to_string(A)), s(ResultStr)], !IO).
+
+%---------------------------------------------------------------------------%
+
+:- pred run_binop_test((func(int8, int8) = int8)::in,
+ string::in, io::di, io::uo) is cc_multi.
+
+run_binop_test(BinOpFunc, Desc, !IO) :-
+ io.format("*** Test binary operation '%s' ***\n\n", [s(Desc)], !IO),
+ As = numbers,
+ Bs = numbers,
+ list.foldl(run_binop_test_2(BinOpFunc, Desc, Bs), As, !IO).
+
+:- pred run_binop_test_2((func(int8, int8) = int8)::in, string::in,
+ list(int8)::in, int8::in, io::di, io::uo) is cc_multi.
+
+run_binop_test_2(BinOpFunc, Desc, Bs, A, !IO) :-
+ list.foldl(run_binop_test_3(BinOpFunc, Desc, A), Bs, !IO).
+
+:- pred run_binop_test_3((func(int8, int8) = int8)::in, string::in,
+ int8::in, int8::in, io::di, io::uo) is cc_multi.
+
+run_binop_test_3(BinOpFunc, Desc, A, B, !IO) :-
+ ( try []
+ Result0 = BinOpFunc(A, B)
+ then
+ ResultStr = int8_to_string(Result0)
+ catch_any _ ->
+ ResultStr = "<<exception>>"
+ ),
+ io.format("%s %s %s = %s\n",
+ [s(int8_to_string(A)), s(Desc), s(int8_to_string(B)), s(ResultStr)], !IO).
+
+:- func numbers = list(int8).
+
+numbers = [
+ -128i8,
+ -16i8,
+ -10i8,
+ -8i8,
+ -2i8,
+ -1i8,
+ 0i8,
+ 1i8,
+ 2i8,
+ 8i8,
+ 10i8,
+ 16i8,
+ 127i8
+].
+
+%---------------------------------------------------------------------------%
+:- end_module arith_int8.
+%---------------------------------------------------------------------------%
diff --git a/tests/hard_coded/arith_uint8.exp b/tests/hard_coded/arith_uint8.exp
index e69de29bb..2de0fe7e2 100644
--- a/tests/hard_coded/arith_uint8.exp
+++ b/tests/hard_coded/arith_uint8.exp
@@ -0,0 +1,259 @@
+*** Test binary operation '+' ***
+
+0 + 0 = 0
+0 + 1 = 1
+0 + 2 = 2
+0 + 8 = 8
+0 + 10 = 10
+0 + 16 = 16
+0 + 255 = 255
+1 + 0 = 1
+1 + 1 = 2
+1 + 2 = 3
+1 + 8 = 9
+1 + 10 = 11
+1 + 16 = 17
+1 + 255 = 0
+2 + 0 = 2
+2 + 1 = 3
+2 + 2 = 4
+2 + 8 = 10
+2 + 10 = 12
+2 + 16 = 18
+2 + 255 = 1
+8 + 0 = 8
+8 + 1 = 9
+8 + 2 = 10
+8 + 8 = 16
+8 + 10 = 18
+8 + 16 = 24
+8 + 255 = 7
+10 + 0 = 10
+10 + 1 = 11
+10 + 2 = 12
+10 + 8 = 18
+10 + 10 = 20
+10 + 16 = 26
+10 + 255 = 9
+16 + 0 = 16
+16 + 1 = 17
+16 + 2 = 18
+16 + 8 = 24
+16 + 10 = 26
+16 + 16 = 32
+16 + 255 = 15
+255 + 0 = 255
+255 + 1 = 0
+255 + 2 = 1
+255 + 8 = 7
+255 + 10 = 9
+255 + 16 = 15
+255 + 255 = 254
+
+*** Test binary operation '-' ***
+
+0 - 0 = 0
+0 - 1 = 255
+0 - 2 = 254
+0 - 8 = 248
+0 - 10 = 246
+0 - 16 = 240
+0 - 255 = 1
+1 - 0 = 1
+1 - 1 = 0
+1 - 2 = 255
+1 - 8 = 249
+1 - 10 = 247
+1 - 16 = 241
+1 - 255 = 2
+2 - 0 = 2
+2 - 1 = 1
+2 - 2 = 0
+2 - 8 = 250
+2 - 10 = 248
+2 - 16 = 242
+2 - 255 = 3
+8 - 0 = 8
+8 - 1 = 7
+8 - 2 = 6
+8 - 8 = 0
+8 - 10 = 254
+8 - 16 = 248
+8 - 255 = 9
+10 - 0 = 10
+10 - 1 = 9
+10 - 2 = 8
+10 - 8 = 2
+10 - 10 = 0
+10 - 16 = 250
+10 - 255 = 11
+16 - 0 = 16
+16 - 1 = 15
+16 - 2 = 14
+16 - 8 = 8
+16 - 10 = 6
+16 - 16 = 0
+16 - 255 = 17
+255 - 0 = 255
+255 - 1 = 254
+255 - 2 = 253
+255 - 8 = 247
+255 - 10 = 245
+255 - 16 = 239
+255 - 255 = 0
+
+*** Test binary operation '*' ***
+
+0 * 0 = 0
+0 * 1 = 0
+0 * 2 = 0
+0 * 8 = 0
+0 * 10 = 0
+0 * 16 = 0
+0 * 255 = 0
+1 * 0 = 0
+1 * 1 = 1
+1 * 2 = 2
+1 * 8 = 8
+1 * 10 = 10
+1 * 16 = 16
+1 * 255 = 255
+2 * 0 = 0
+2 * 1 = 2
+2 * 2 = 4
+2 * 8 = 16
+2 * 10 = 20
+2 * 16 = 32
+2 * 255 = 254
+8 * 0 = 0
+8 * 1 = 8
+8 * 2 = 16
+8 * 8 = 64
+8 * 10 = 80
+8 * 16 = 128
+8 * 255 = 248
+10 * 0 = 0
+10 * 1 = 10
+10 * 2 = 20
+10 * 8 = 80
+10 * 10 = 100
+10 * 16 = 160
+10 * 255 = 246
+16 * 0 = 0
+16 * 1 = 16
+16 * 2 = 32
+16 * 8 = 128
+16 * 10 = 160
+16 * 16 = 0
+16 * 255 = 240
+255 * 0 = 0
+255 * 1 = 255
+255 * 2 = 254
+255 * 8 = 248
+255 * 10 = 246
+255 * 16 = 240
+255 * 255 = 1
+
+*** Test binary operation '/' ***
+
+0 / 0 = <<exception>>
+0 / 1 = 0
+0 / 2 = 0
+0 / 8 = 0
+0 / 10 = 0
+0 / 16 = 0
+0 / 255 = 0
+1 / 0 = <<exception>>
+1 / 1 = 1
+1 / 2 = 0
+1 / 8 = 0
+1 / 10 = 0
+1 / 16 = 0
+1 / 255 = 0
+2 / 0 = <<exception>>
+2 / 1 = 2
+2 / 2 = 1
+2 / 8 = 0
+2 / 10 = 0
+2 / 16 = 0
+2 / 255 = 0
+8 / 0 = <<exception>>
+8 / 1 = 8
+8 / 2 = 4
+8 / 8 = 1
+8 / 10 = 0
+8 / 16 = 0
+8 / 255 = 0
+10 / 0 = <<exception>>
+10 / 1 = 10
+10 / 2 = 5
+10 / 8 = 1
+10 / 10 = 1
+10 / 16 = 0
+10 / 255 = 0
+16 / 0 = <<exception>>
+16 / 1 = 16
+16 / 2 = 8
+16 / 8 = 2
+16 / 10 = 1
+16 / 16 = 1
+16 / 255 = 0
+255 / 0 = <<exception>>
+255 / 1 = 255
+255 / 2 = 127
+255 / 8 = 31
+255 / 10 = 25
+255 / 16 = 15
+255 / 255 = 1
+
+*** Test binary operation 'rem' ***
+
+0 rem 0 = <<exception>>
+0 rem 1 = 0
+0 rem 2 = 0
+0 rem 8 = 0
+0 rem 10 = 0
+0 rem 16 = 0
+0 rem 255 = 0
+1 rem 0 = <<exception>>
+1 rem 1 = 0
+1 rem 2 = 1
+1 rem 8 = 1
+1 rem 10 = 1
+1 rem 16 = 1
+1 rem 255 = 1
+2 rem 0 = <<exception>>
+2 rem 1 = 0
+2 rem 2 = 0
+2 rem 8 = 2
+2 rem 10 = 2
+2 rem 16 = 2
+2 rem 255 = 2
+8 rem 0 = <<exception>>
+8 rem 1 = 0
+8 rem 2 = 0
+8 rem 8 = 0
+8 rem 10 = 8
+8 rem 16 = 8
+8 rem 255 = 8
+10 rem 0 = <<exception>>
+10 rem 1 = 0
+10 rem 2 = 0
+10 rem 8 = 2
+10 rem 10 = 0
+10 rem 16 = 10
+10 rem 255 = 10
+16 rem 0 = <<exception>>
+16 rem 1 = 0
+16 rem 2 = 0
+16 rem 8 = 0
+16 rem 10 = 6
+16 rem 16 = 0
+16 rem 255 = 16
+255 rem 0 = <<exception>>
+255 rem 1 = 0
+255 rem 2 = 1
+255 rem 8 = 7
+255 rem 10 = 5
+255 rem 16 = 15
+255 rem 255 = 0
diff --git a/tests/hard_coded/arith_uint8.m b/tests/hard_coded/arith_uint8.m
index e69de29bb..0d48fbd06 100644
--- a/tests/hard_coded/arith_uint8.m
+++ b/tests/hard_coded/arith_uint8.m
@@ -0,0 +1,81 @@
+%---------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%---------------------------------------------------------------------------%
+
+% Test arithmetic operations for unsigned 8-bit integers.
+
+:- module arith_uint8.
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is cc_multi.
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module uint8.
+
+:- import_module exception.
+:- import_module list.
+:- import_module string.
+
+%---------------------------------------------------------------------------%
+
+main(!IO) :-
+ run_binop_test((func(X, Y) = X + Y), "+", !IO),
+ io.nl(!IO),
+ run_binop_test((func(X, Y) = X - Y), "-", !IO),
+ io.nl(!IO),
+ run_binop_test((func(X, Y) = X * Y), "*", !IO),
+ io.nl(!IO),
+ run_binop_test((func(X, Y) = X / Y), "/", !IO),
+ io.nl(!IO),
+ run_binop_test((func(X, Y) = X rem Y), "rem", !IO).
+
+:- pred run_binop_test((func(uint8, uint8) = uint8)::in, string::in,
+ io::di, io::uo) is cc_multi.
+
+run_binop_test(BinOpFunc, Desc, !IO) :-
+ io.format("*** Test binary operation '%s' ***\n\n", [s(Desc)], !IO),
+ As = numbers,
+ Bs = numbers,
+ list.foldl(run_binop_test_2(BinOpFunc, Desc, Bs), As, !IO).
+
+:- pred run_binop_test_2((func(uint8, uint8) = uint8)::in, string::in,
+ list(uint8)::in, uint8::in, io::di, io::uo) is cc_multi.
+
+run_binop_test_2(BinOpFunc, Desc, Bs, A, !IO) :-
+ list.foldl(run_binop_test_3(BinOpFunc, Desc, A), Bs, !IO).
+
+:- pred run_binop_test_3((func(uint8, uint8) = uint8)::in, string::in,
+ uint8::in, uint8::in, io::di, io::uo) is cc_multi.
+
+run_binop_test_3(BinOpFunc, Desc, A, B, !IO) :-
+ ( try []
+ Result0 = BinOpFunc(A, B)
+ then
+ ResultStr = uint8_to_string(Result0)
+ catch_any _ ->
+ ResultStr = "<<exception>>"
+ ),
+ io.format("%s %s %s = %s\n",
+ [s(uint8_to_string(A)), s(Desc), s(uint8_to_string(B)), s(ResultStr)], !IO).
+
+:- func numbers = list(uint8).
+
+numbers = [
+ 0u8,
+ 1u8,
+ 2u8,
+ 8u8,
+ 10u8,
+ 16u8,
+ 255u8
+].
+
+%---------------------------------------------------------------------------%
+:- end_module arith_uint8.
+%---------------------------------------------------------------------------%
More information about the reviews
mailing list