2 # Copyright (C) 2001-2010, Parrot Foundation.
7 t/op/integer.t - Integer Registers
11 % prove t/op/integer.t
15 Tests the use of Parrot integer registers.
19 .const int TESTS = 153
22 .include 'test_more.pir'
35 mod_negative_zero_rest()
51 test_negate_max_integer()
54 test_div_i_i_by_zero()
55 test_div_i_ic_by_zero()
56 test_div_i_i_i_by_zero()
57 test_div_i_ic_i_by_zero()
58 test_div_i_i_ic_by_zero()
59 test_fdiv_i_i_by_zero()
60 test_fdiv_i_ic_by_zero()
61 test_fdiv_i_i_i_by_zero()
62 test_fdiv_i_ic_i_by_zero()
63 test_fdiv_i_i_ic_by_zero()
64 test_mod_i_i_i_by_zero()
65 test_mod_i_ic_i_by_zero()
66 test_mod_i_i_ic_by_zero()
104 is($S0, "0", "set_i_ic with 0")
106 is($S0, "1", "set_i_ic with 1")
108 is($S0, "2", "set_i_ic with 2")
110 is($S0, "3", "set_i_ic with 3")
112 is($S0, "4", "set_i_ic with 4")
114 is($S0, "5", "set_i_ic with 5")
116 is($S0, "6", "set_i_ic with 6")
118 is($S0, "7", "set_i_ic with 7")
120 is($S0, "8", "set_i_ic with 8")
122 is($S0, "9", "set_i_ic with 9")
124 is($S0, "10", "set_i_ic with 10")
126 is($S0, "11", "set_i_ic with 11")
128 is($S0, "12", "set_i_ic with 12")
130 is($S0, "13", "set_i_ic with 13")
132 is($S0, "14", "set_i_ic with 14")
134 is($S0, "15", "set_i_ic with 15")
136 is($S0, "16", "set_i_ic with 16")
138 is($S0, "17", "set_i_ic with 17")
140 is($S0, "18", "set_i_ic with 18")
142 is($S0, "19", "set_i_ic with 19")
144 is($S0, "20", "set_i_ic with 20")
146 is($S0, "21", "set_i_ic with 21")
148 is($S0, "22", "set_i_ic with 22")
150 is($S0, "23", "set_i_ic with 23")
152 is($S0, "24", "set_i_ic with 24")
154 is($S0, "25", "set_i_ic with 25")
156 is($S0, "26", "set_i_ic with 26")
158 is($S0, "27", "set_i_ic with 27")
160 is($S0, "28", "set_i_ic with 28")
162 is($S0, "29", "set_i_ic with 29")
164 is($S0, "30", "set_i_ic with 30")
166 is($S0, "31", "set_i_ic with 31")
173 is($S0, '42', 'set_i')
176 .sub 'test_add_i_i_i'
179 is($I1, 574908040, 'add_i_i - first')
182 is($I2, 862362060, 'add_i_i - second')
185 is($I2, 1724724120, 'add_i_i - third')
194 is($I0, 2, 'add_i_i - zero is neutral')
197 is($I0, 0, 'add_i_i - inverse')
201 is($I0, 5, 'add_i_ic - zero is neutral')
204 is($I0, -5, 'add_i_ic')
218 is($I0, 1, 'abs_i_ic')
219 is($I1, 1, 'abs_i_i')
220 is($I2, 1, 'abs_i_nc')
221 is($I3, 1, 'abs_i_n')
228 is($I2, 286331153, 'sub_i_i_i')
233 is($I0, 4, 'sub_i_i_ic')
236 is($I0, 10, 'sub_i_ic_i')
239 is($I0, 1, 'sub_i_ic_ic')
247 is($I2, 203, 'mul_i_i_i')
250 is($I2, 203, 'mul_i_i_ic')
257 is($I2, 3, 'div_i_i_i - exact')
262 is($I2, 5, 'div_i_i_i - quotient with positive integers')
267 is($I2, -2, 'div_i_i_i - quotient with negative divisor')
272 is($I1, 12, 'div_i_ic_i')
275 is($I1, 4, 'div_i_i_ic')
278 is($I1, 10, 'div_i_ic_ic')
285 is($I0, -3, 'fdiv_i_i with negative divisor')
290 is($I2, -3, 'fdiv_i_i_i with negative divisor')
297 is($I2, 5, 'mod_i_i_i by 0')
302 is($I2, 0, 'mod_i_i_i of 0')
307 is($I2, 2, 'mod_i_i_i - remainder of 5 / 3')
312 is($I2, -1, 'mod_i_i_i - remainder of 5 / -3')
317 is($I2, 1, 'mod_i_i_i - remainder of -5 / 3')
322 is($I2, -2, 'mod_i_i_i - remainder of -5 / -3')
327 is($I1, 2, 'mod_i_i_ic')
330 is($I1, 2, 'mod_i_ic_i')
333 is($I1, 2, 'mod_i_ic_ic')
336 .sub 'mod_negative_zero_rest'
338 is($I1, 0, 'mod - negative, zero rest (#36003), 3 mod 3 = 0')
341 is($I1, 0, 'mod - negative, zero rest (#36003), -3 mod 3 = 0')
344 is($I1, 0, 'mod - negative, zero rest (#36003), 3 mod -3 = 0')
347 is($I1, 0, 'mod - negative, zero rest (#36003), -3 mod -3 = 0')
356 if $I0 == $I1 goto test_eq_1
359 ok($I3, 'eq_i_i - equal')
362 unless $I1 == $I2 goto test_eq_2
365 ok($I3, 'eq_i_i - different')
369 if $I0 == 42 goto test_eq_3
372 ok($I3, 'eq_i_ic - different')
375 unless $I0 == -42 goto test_eq_4
378 ok($I3, 'eq_i_ic - equal')
382 unless $I0 == 12 goto test_eq_5
385 ok($I3, 'eq_i_ic - 12 == 12')
388 unless 12 == 12 goto test_eq_6
391 ok($I3, 'eq_ic_ic - equal')
394 unless 12 == 21 goto test_eq_7
397 ok($I3, 'eq_ic_ic - different')
406 unless $I0 != $I2 goto test_ne_1
409 ok($I3, 'ne_i_i - different')
412 if $I0 != $I1 goto test_ne_2
415 ok($I3, 'ne_i_i - equal')
419 if $I0 != 427034409 goto test_ne_3
422 ok($I3, 'ne_i_ic - equal')
425 unless $I0 != 427034408 goto test_ne_4
428 ok($I3, 'ne_i_ic - different')
438 unless $I1 < $I0 goto test_lt_1
441 ok($I4, 'lt_i_i - true inequality')
444 if $I0 < $I1 goto test_lt_2
447 ok($I4, 'lt_i_i - false inequality')
450 if $I2 < $I3 goto test_lt_3
453 ok($I4, 'lt_i_i - irreflexivity')
456 if $I0 < -2147483648 goto test_lt_4
459 ok($I4, 'lt_i_ic - false inequality')
462 unless $I1 < 2147483647 goto test_lt_5
465 ok($I4, 'lt_i_ic - true inequality')
468 if $I0 < 0 goto test_lt_6
471 ok($I4, 'lt_i_ic - irreflexivity')
481 unless $I1 <= $I0 goto test_le_1
484 ok($I4, 'le_i_i - true inequality')
487 if $I0 <= $I1 goto test_le_2
490 ok($I4, 'le_i_i - false inequality')
493 unless $I2 <= $I3 goto test_le_3
496 ok($I4, 'le_i_i - reflexive')
499 if $I0 <= -2147483648 goto test_le_4
502 ok($I4, 'le_i_ic - false inequality')
505 unless $I1 <= 2147483647 goto test_le_5
508 ok($I4, 'le_i_ic - true inequality')
511 unless $I2 <= 0 goto test_le_6
514 ok($I4, 'le_i_ic - reflexivity')
524 unless $I1 > $I0 goto test_gt_1
527 ok($I4, 'gt_i_i - true inequality')
530 if $I0 > $I1 goto test_gt_2
533 ok($I4, 'gt_i_i - false inequality')
536 if $I2 > $I3 goto test_gt_3
539 ok($I4, 'gt_i_i - irreflexive')
542 if $I0 > 2147483647 goto test_gt_4
545 ok($I4, 'gt_i_ic - false inequality')
548 unless $I1 > -2147483648 goto test_gt_5
551 ok($I4, 'gt_i_ic - true inequality')
554 if $I0 > 0 goto test_gt_6
557 ok($I4, 'gt_i_ic - another false inequality')
567 unless $I1 >= $I0 goto test_ge_1
570 ok($I4, 'ge_i_i - true inequality')
573 if $I0 >= $I1 goto test_ge_2
576 ok($I4, 'ge_i_i - false inequality')
579 unless $I2 >= $I3 goto test_ge_3
582 ok($I4, 'ge_i_i - reflexive')
585 if $I0 >= 2147483647 goto test_ge_4
588 ok($I4, 'ge_i_ic - false inequality')
591 unless $I1 >= -2147483648 goto test_ge_5
594 ok($I4, 'ge_i_ic - true inequality')
597 unless $I2 >= 0 goto test_ge_6
600 ok($I4, 'ge_i_ic - reflexivity')
606 is($I1, 0, 'not_i_i - not 1')
609 is($I2, 1, 'not_i_i - not (not 1)')
613 is($I4, 0, 'not_i_i of a positive integer')
617 is($I6, 0, 'not_i_i of a negative integer')
621 is($I7, 0, 'not_i_ic')
630 is($I2, 0, 'and - zero is right absorbing')
634 is($I2, 0, 'and - zero is left absorbing')
638 is($I2, 0, 'and - diagonal zero')
642 is($I2, 10, 'and - true operands')
651 is($I2, 10, 'or_i_i')
655 is($I2, 10, 'or_i_i - symmetric case')
658 is($I2, 0, 'or_i_i - false arguments')
661 is($I2, 10, 'or_i_i - reflexive')
670 is($I2, 2, 'xor - zero is right neutral')
674 is($I2, 2, 'xor - zero is left neutral')
677 is($I2, 0, 'xor - nilpotent on zero')
680 is($I2, 0, 'xor - nilpotent on 2')
683 is($I2, 0, 'xor - nilpotent on other')
689 is($I0, 1, 'inc_i (first)')
694 is($I0, 5, 'inc_i (second)')
700 is($I0, -1, 'dec_i (first)')
705 is($I0, -5, 'dec_i (second)')
714 is($I0, -3, 'sub_i_i')
717 is($I0, 0, 'sub_i_i - inverse')
721 is($I0, -5, 'sub_i_ic - first')
724 is($I0, 5, 'sub_i_ic - second')
730 is($N0, 0.0, 'set_n_i -zero')
734 is($N1, 2147483647.0, 'set_n_i - positive integer')
738 is($N2, -2147483648.0, 'set_n_i - negative integer')
749 # Test to ensure that the negative of the maximum integer is equal to the
750 # minimum integer + 1. This should be true because we are assuming a
751 # two's-complement machine.
753 .include 'iglobals.pasm'
754 .sub test_negate_max_integer
758 $P1 = $P0[.IGLOBALS_CONFIG_HASH]
759 $I0 = $P1['intvalsize']
761 # XXX can't use sysinfo (from sys_ops) in coretest
762 # build up 2's compliment min and max integers manually
767 unless $I0 goto end_loop
785 is($I0, 12, 'mul_i_i')
790 is($I1, 1000, 'null_i - before null')
792 is($I1, 0, 'null_i - after null')
795 .sub 'test_div_i_i_by_zero'
798 push_eh test_div_i_i_by_zero_catch
802 goto test_div_i_i_by_zero_end
804 test_div_i_i_by_zero_catch:
807 test_div_i_i_by_zero_end:
808 ok($I2, 'div_i_i by zero')
811 .sub 'test_div_i_ic_by_zero'
813 push_eh test_div_i_ic_by_zero_catch
817 goto test_div_i_ic_by_zero_end
819 test_div_i_ic_by_zero_catch:
822 test_div_i_ic_by_zero_end:
823 ok($I2, 'div_i_ic by zero')
826 .sub 'test_div_i_i_i_by_zero'
829 push_eh test_div_i_i_i_by_zero_catch
833 goto test_div_i_i_i_by_zero_end
835 test_div_i_i_i_by_zero_catch:
838 test_div_i_i_i_by_zero_end:
839 ok($I3, 'div_i_i_i by zero')
842 .sub 'test_div_i_ic_i_by_zero'
844 push_eh test_div_i_ic_i_by_zero_catch
848 goto test_div_i_ic_i_by_zero_end
850 test_div_i_ic_i_by_zero_catch:
853 test_div_i_ic_i_by_zero_end:
854 ok($I3, 'div_i_ic_i by zero')
857 .sub 'test_div_i_i_ic_by_zero'
859 push_eh test_div_i_i_ic_by_zero_catch
863 goto test_div_i_i_ic_by_zero_end
865 test_div_i_i_ic_by_zero_catch:
868 test_div_i_i_ic_by_zero_end:
869 ok($I3, 'div_i_i_ic by zero')
872 .sub 'test_fdiv_i_i_by_zero'
875 push_eh test_fdiv_i_i_by_zero_catch
879 goto test_fdiv_i_i_by_zero_end
881 test_fdiv_i_i_by_zero_catch:
884 test_fdiv_i_i_by_zero_end:
885 ok($I2, 'fdiv_i_i by zero')
888 .sub 'test_fdiv_i_ic_by_zero'
890 push_eh test_fdiv_i_ic_by_zero_catch
894 goto test_fdiv_i_ic_by_zero_end
896 test_fdiv_i_ic_by_zero_catch:
899 test_fdiv_i_ic_by_zero_end:
900 ok($I2, 'fdiv_i_ic by zero')
903 .sub 'test_fdiv_i_i_i_by_zero'
906 push_eh test_fdiv_i_i_i_by_zero_catch
910 goto test_fdiv_i_i_i_by_zero_end
912 test_fdiv_i_i_i_by_zero_catch:
915 test_fdiv_i_i_i_by_zero_end:
916 ok($I3, 'fdiv_i_i_i by zero')
919 .sub 'test_fdiv_i_ic_i_by_zero'
921 push_eh test_fdiv_i_ic_i_by_zero_catch
925 goto test_fdiv_i_ic_i_by_zero_end
927 test_fdiv_i_ic_i_by_zero_catch:
930 test_fdiv_i_ic_i_by_zero_end:
931 ok($I3, 'fdiv_i_ic_i by zero')
934 .sub 'test_fdiv_i_i_ic_by_zero'
936 push_eh test_fdiv_i_i_ic_by_zero_catch
940 goto test_fdiv_i_i_ic_by_zero_end
942 test_fdiv_i_i_ic_by_zero_catch:
945 test_fdiv_i_i_ic_by_zero_end:
946 ok($I3, 'fdiv_i_i_ic by zero')
949 .sub 'test_mod_i_i_i_by_zero'
953 is($I2, 10, 'mod_i_i_i by zero')
956 .sub 'test_mod_i_ic_i_by_zero'
959 is($I2, 10, 'mod_i_ic_i by zero')
962 .sub 'test_mod_i_i_ic_by_zero'
965 is($I2, 10, 'mod_i_i_ic by zero')
972 # vim: expandtab shiftwidth=4 ft=pir: