From 7f05ab665be8dbacd7b97d6d7e2737af781bf58c Mon Sep 17 00:00:00 2001 From: Klaus Treichel Date: Sun, 20 Apr 2008 10:44:02 +0000 Subject: [PATCH] Add more testcases. --- ChangeLog | 9 + tests/Makefile.am | 3 +- tests/cond.pas | 593 ++++++++++++++++++++++++++++++++++++++++++++++ tests/math.pas | 284 ++++++++++++++++++++-- 4 files changed, 871 insertions(+), 18 deletions(-) create mode 100644 tests/cond.pas diff --git a/ChangeLog b/ChangeLog index 7928b34..8512b19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-04-20 Klaus Treichel + + * tests/Makefile.am: Add cond.pas to the tests. + + * tests/math.pas: Add tests for more opcodes and execute existing + tests for more types. + + * tests/cond.pas: Add tests for conditions. + 2008-04-20 Aleksey Demakov * jit/jit-rules-x86.ins: fix the sign opcode for longs (based on diff --git a/tests/Makefile.am b/tests/Makefile.am index 45bfb19..b13a54c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,6 +2,7 @@ TESTS = coerce.pas \ loop.pas \ math.pas \ - param.pas + param.pas \ + cond.pas EXTRA_DIST = $(TESTS) TESTS_ENVIRONMENT = $(top_builddir)/dpas/dpas --dont-fold diff --git a/tests/cond.pas b/tests/cond.pas new file mode 100644 index 0000000..8178494 --- /dev/null +++ b/tests/cond.pas @@ -0,0 +1,593 @@ +(* + * cond.pas - Test conditions and branches. + * + * Copyright (C) 2008 Southern Storm Software, Pty Ltd. + * + * This file is part of the libjit library. + * + * The libjit library is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 2.1 of + * the License, or (at your option) any later version. + * + * The libjit library 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. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the libjit library. If not, see + * . + *) + +program cond; + +var + failed: Boolean; + +procedure run(msg: String; value: Boolean); +begin + Write(msg); + Write(" ... "); + if value then begin + WriteLn("ok"); + end else begin + WriteLn("failed"); + failed := True; + end; +end; + +procedure runcheck(msg: String; value, expected: Boolean); +begin + if value then begin + if expected then begin + run(msg, True); + end else begin + run(msg, False); + end; + end else begin + if expected then begin + run(msg, False); + end else begin + run(msg, True); + end; + end; +end; + +procedure const_integer_tests; +var + i1: Integer; +begin + runcheck("cond_ci_eq_0_0", (0 = 0), True); + i1 := 1; + runcheck("cond_ci_eq_1_0", (i1 = 0), False); + runcheck("cond_ci_eq_1_1", (i1 = 1), True); + i1 := 0; + runcheck("cond_ci_eq_0_1", (i1 = 1), False); + + runcheck("cond_ci_ne_0_0", (0 <> 0), False); + i1 := 1; + runcheck("cond_ci_ne_1_0", (i1 <> 0), True); + runcheck("cond_ci_ne_1_1", (i1 <> 1), False); + i1 := 0; + runcheck("cond_ci_ne_0_1", (i1 <> 1), True); + + runcheck("cond_ci_gt_0_0", (0 > 0), False); + i1 := 1; + runcheck("cond_ci_gt_1_0", (i1 > 0), True); + runcheck("cond_ci_gt_1_1", (i1 > 1), False); + i1 := 2; + runcheck("cond_ci_gt_2_1", (i1 > 1), True); + i1 := 0; + runcheck("cond_ci_gt_0_1", (i1 > 1), False); + i1 := -1; + runcheck("cond_ci_gt_m1_0", (i1 > 0), False); + runcheck("cond_ci_gt_m1_1", (i1 > 1), False); + runcheck("cond_ci_gt_m1_m2", (i1 > -2), True); + i1 := -2; + runcheck("cond_ci_gt_m2_m1", (i1 > -1), False); + + runcheck("cond_ci_ge_0_0", (0 >= 0), True); + i1 := 1; + runcheck("cond_ci_ge_1_0", (i1 >= 0), True); + runcheck("cond_ci_ge_1_1", (i1 >= 1), True); + i1 := 2; + runcheck("cond_ci_ge_2_1", (i1 >= 1), True); + i1 := 0; + runcheck("cond_ci_ge_0_1", (i1 >= 1), False); + i1 := -1; + runcheck("cond_ci_ge_m1_0", (i1 >= 0), False); + runcheck("cond_ci_ge_m1_1", (i1 >= 1), False); + runcheck("cond_ci_ge_m1_m1", (i1 >= -1), True); + runcheck("cond_ci_ge_m1_m2", (i1 >= -2), True); + i1 := -2; + runcheck("cond_ci_ge_m2_m1", (i1 >= -1), False); + + runcheck("cond_ci_lt_0_0", (0 < 0), False); + i1 := 1; + runcheck("cond_ci_lt_1_0", (i1 < 0), False); + runcheck("cond_ci_lt_1_1", (i1 < 1), False); + i1 := 2; + runcheck("cond_ci_lt_2_1", (i1 < 1), False); + i1 := 0; + runcheck("cond_ci_lt_0_1", (i1 < 1), True); + i1 := -1; + runcheck("cond_ci_lt_m1_0", (i1 < 0), True); + runcheck("cond_ci_lt_m1_1", (i1 < 1), True); + runcheck("cond_ci_lt_m1_m1", (i1 < -1), False); + runcheck("cond_ci_lt_m1_m2", (i1 < -2), False); + i1 := -2; + runcheck("cond_ci_lt_m2_m1", (i1 < -1), True); + + runcheck("cond_ci_le_0_0", (0 <= 0), True); + i1 := 1; + runcheck("cond_ci_le_1_0", (i1 <= 0), False); + runcheck("cond_ci_le_1_1", (i1 <= 1), True); + i1 := 2; + runcheck("cond_ci_le_2_1", (i1 <= 1), False); + i1 := 0; + runcheck("cond_ci_le_0_1", (i1 <= 1), True); + i1 := -1; + runcheck("cond_ci_le_m1_0", (i1 <= 0), True); + runcheck("cond_ci_le_m1_1", (i1 <= 1), True); + runcheck("cond_ci_le_m1_m1", (i1 <= -1), True); + runcheck("cond_ci_le_m1_m2", (i1 <= -2), False); + i1 := -2; + runcheck("cond_ci_le_m2_m1", (i1 <= -1), True); +end; + +function integer_eq(i1, i2: Integer): Boolean; +begin + integer_eq := (i1 = i2); +end; + +function integer_ne(i1, i2: Integer): Boolean; +begin + integer_ne := (i1 <> i2); +end; + +function integer_ge(i1, i2: Integer): Boolean; +begin + integer_ge := (i1 >= i2); +end; + +function integer_gt(i1, i2: Integer): Boolean; +begin + integer_gt := (i1 > i2); +end; + +function integer_le(i1, i2: Integer): Boolean; +begin + integer_le := (i1 <= i2); +end; + +function integer_lt(i1, i2: Integer): Boolean; +begin + integer_lt := (i1 < i2); +end; + +procedure integer_tests; +begin + runcheck("cond_i_eq_0_0", integer_eq(0, 0), True); + runcheck("cond_i_eq_1_1", integer_eq(1, 1), True); + runcheck("cond_i_eq_1_0", integer_eq(1, 0), False); + runcheck("cond_i_eq_1_0", integer_eq(0, 1), False); + runcheck("cond_i_ne_0_0", integer_ne(0, 0), False); + runcheck("cond_i_ne_1_1", integer_ne(1, 1), False); + runcheck("cond_i_ne_1_0", integer_ne(1, 0), True); + runcheck("cond_i_ne_0_1", integer_ne(0, 1), True); + runcheck("cond_i_gt_0_0", integer_gt(0, 0), False); + runcheck("cond_i_gt_1_1", integer_gt(1, 1), False); + runcheck("cond_i_gt_1_0", integer_gt(1, 0), True); + runcheck("cond_i_gt_0_1", integer_gt(0, 1), False); + runcheck("cond_i_gt_m1_0", integer_gt(-1, 0), False); + runcheck("cond_i_gt_0_m1", integer_gt(0, -1), True); + runcheck("cond_i_gt_m1_m1", integer_gt(-1, -1), False); + runcheck("cond_i_ge_0_0", integer_ge(0, 0), True); + runcheck("cond_i_ge_1_1", integer_ge(1, 1), True); + runcheck("cond_i_ge_1_0", integer_ge(1, 0), True); + runcheck("cond_i_ge_0_1", integer_ge(0, 1), False); + runcheck("cond_i_ge_m1_0", integer_ge(-1, 0), False); + runcheck("cond_i_ge_0_m1", integer_ge(0, -1), True); + runcheck("cond_i_ge_m1_m1", integer_ge(-1, -1), True); + runcheck("cond_i_lt_0_0", integer_lt(0, 0), False); + runcheck("cond_i_lt_1_1", integer_lt(1, 1), False); + runcheck("cond_i_lt_1_0", integer_lt(1, 0), False); + runcheck("cond_i_lt_0_1", integer_lt(0, 1), True); + runcheck("cond_i_lt_m1_0", integer_lt(-1, 0), True); + runcheck("cond_i_lt_0_m1", integer_lt(0, -1), False); + runcheck("cond_i_lt_m1_m1", integer_lt(-1, -1), False); + runcheck("cond_i_le_0_0", integer_le(0, 0), True); + runcheck("cond_i_le_1_1", integer_le(1, 1), True); + runcheck("cond_i_le_1_0", integer_le(1, 0), False); + runcheck("cond_i_le_0_1", integer_le(0, 1), True); + runcheck("cond_i_le_m1_0", integer_le(-1, 0), True); + runcheck("cond_i_le_0_m1", integer_le(0, -1), False); + runcheck("cond_i_le_m1_m1", integer_le(-1, -1), True); +end; + +function cardinal_eq(i1, i2: Cardinal): Boolean; +begin + cardinal_eq := (i1 = i2); +end; + +function cardinal_ne(i1, i2: Cardinal): Boolean; +begin + cardinal_ne := (i1 <> i2); +end; + +function cardinal_ge(i1, i2: Cardinal): Boolean; +begin + cardinal_ge := (i1 >= i2); +end; + +function cardinal_gt(i1, i2: Cardinal): Boolean; +begin + cardinal_gt := (i1 > i2); +end; + +function cardinal_le(i1, i2: Cardinal): Boolean; +begin + cardinal_le := (i1 <= i2); +end; + +function cardinal_lt(i1, i2: Cardinal): Boolean; +begin + cardinal_lt := (i1 < i2); +end; + +procedure cardinal_tests; +begin + runcheck("cond_ui_eq_0_0", cardinal_eq(0, 0), True); + runcheck("cond_ui_eq_1_1", cardinal_eq(1, 1), True); + runcheck("cond_ui_eq_1_0", cardinal_eq(1, 0), False); + runcheck("cond_ui_eq_1_0", cardinal_eq(0, 1), False); + runcheck("cond_ui_ne_0_0", cardinal_ne(0, 0), False); + runcheck("cond_ui_ne_1_1", cardinal_ne(1, 1), False); + runcheck("cond_ui_ne_1_0", cardinal_ne(1, 0), True); + runcheck("cond_ui_ne_0_1", cardinal_ne(0, 1), True); + runcheck("cond_ui_gt_0_0", cardinal_gt(0, 0), False); + runcheck("cond_ui_gt_1_1", cardinal_gt(1, 1), False); + runcheck("cond_ui_gt_1_0", cardinal_gt(1, 0), True); + runcheck("cond_ui_gt_0_1", cardinal_gt(0, 1), False); + runcheck("cond_ui_gt_80000000h_0", cardinal_gt(80000000h, 0), True); + runcheck("cond_ui_gt_0_80000000h", cardinal_gt(0, 80000000h), False); + runcheck("cond_ui_gt_80000000h_80000000h", cardinal_gt(80000000h, 80000000h), False); + runcheck("cond_ui_ge_0_0", cardinal_ge(0, 0), True); + runcheck("cond_ui_ge_1_1", cardinal_ge(1, 1), True); + runcheck("cond_ui_ge_1_0", cardinal_ge(1, 0), True); + runcheck("cond_ui_ge_0_1", cardinal_ge(0, 1), False); + runcheck("cond_ui_ge_80000000h_0", cardinal_ge(80000000h, 0), True); + runcheck("cond_ui_ge_0_80000000h", cardinal_ge(0, 80000000h), False); + runcheck("cond_ui_ge_80000000h_80000000h", cardinal_ge(80000000h, 80000000h), True); + runcheck("cond_ui_lt_0_0", cardinal_lt(0, 0), False); + runcheck("cond_ui_lt_1_1", cardinal_lt(1, 1), False); + runcheck("cond_ui_lt_1_0", cardinal_lt(1, 0), False); + runcheck("cond_ui_lt_0_1", cardinal_lt(0, 1), True); + runcheck("cond_ui_lt_80000000h_0", cardinal_lt(80000000h, 0), False); + runcheck("cond_ui_lt_0_80000000h", cardinal_lt(0, 80000000h), True); + runcheck("cond_ui_lt_80000000h_80000000h", cardinal_lt(80000000h, 80000000h), False); + runcheck("cond_ui_le_0_0", cardinal_le(0, 0), True); + runcheck("cond_ui_le_1_1", cardinal_le(1, 1), True); + runcheck("cond_ui_le_1_0", cardinal_le(1, 0), False); + runcheck("cond_ui_le_0_1", cardinal_le(0, 1), True); + runcheck("cond_ui_le_80000000h_0", cardinal_le(80000000h, 0), False); + runcheck("cond_ui_le_0_80000000h", cardinal_le(0, 80000000h), True); + runcheck("cond_ui_le_80000000h_80000000h", cardinal_le(80000000h, 80000000h), True); +end; + +function longint_eq(i1, i2: LongInt): Boolean; +begin + longint_eq := (i1 = i2); +end; + +function longint_ne(i1, i2: LongInt): Boolean; +begin + longint_ne := (i1 <> i2); +end; + +function longint_ge(i1, i2: LongInt): Boolean; +begin + longint_ge := (i1 >= i2); +end; + +function longint_gt(i1, i2: LongInt): Boolean; +begin + longint_gt := (i1 > i2); +end; + +function longint_le(i1, i2: LongInt): Boolean; +begin + longint_le := (i1 <= i2); +end; + +function longint_lt(i1, i2: LongInt): Boolean; +begin + longint_lt := (i1 < i2); +end; + +procedure longint_tests; +begin + runcheck("cond_l_eq_0_0", longint_eq(0, 0), True); + runcheck("cond_l_eq_1_1", longint_eq(1, 1), True); + runcheck("cond_l_eq_1_0", longint_eq(1, 0), False); + runcheck("cond_l_eq_1_0", longint_eq(0, 1), False); + runcheck("cond_l_ne_0_0", longint_ne(0, 0), False); + runcheck("cond_l_ne_1_1", longint_ne(1, 1), False); + runcheck("cond_l_ne_1_0", longint_ne(1, 0), True); + runcheck("cond_l_ne_0_1", longint_ne(0, 1), True); + runcheck("cond_l_gt_0_0", longint_gt(0, 0), False); + runcheck("cond_l_gt_1_1", longint_gt(1, 1), False); + runcheck("cond_l_gt_1_0", longint_gt(1, 0), True); + runcheck("cond_l_gt_0_1", longint_gt(0, 1), False); + runcheck("cond_l_gt_m1_0", longint_gt(-1, 0), False); + runcheck("cond_l_gt_0_m1", longint_gt(0, -1), True); + runcheck("cond_l_gt_m1_m1", longint_gt(-1, -1), False); + runcheck("cond_l_ge_0_0", longint_ge(0, 0), True); + runcheck("cond_l_ge_1_1", longint_ge(1, 1), True); + runcheck("cond_l_ge_1_0", longint_ge(1, 0), True); + runcheck("cond_l_ge_0_1", longint_ge(0, 1), False); + runcheck("cond_l_ge_m1_0", longint_ge(-1, 0), False); + runcheck("cond_l_ge_0_m1", longint_ge(0, -1), True); + runcheck("cond_l_ge_m1_m1", longint_ge(-1, -1), True); + runcheck("cond_l_lt_0_0", longint_lt(0, 0), False); + runcheck("cond_l_lt_1_1", longint_lt(1, 1), False); + runcheck("cond_l_lt_1_0", longint_lt(1, 0), False); + runcheck("cond_l_lt_0_1", longint_lt(0, 1), True); + runcheck("cond_l_lt_m1_0", longint_lt(-1, 0), True); + runcheck("cond_l_lt_0_m1", longint_lt(0, -1), False); + runcheck("cond_l_lt_m1_m1", longint_lt(-1, -1), False); + runcheck("cond_l_le_0_0", longint_le(0, 0), True); + runcheck("cond_l_le_1_1", longint_le(1, 1), True); + runcheck("cond_l_le_1_0", longint_le(1, 0), False); + runcheck("cond_l_le_0_1", longint_le(0, 1), True); + runcheck("cond_l_le_m1_0", longint_le(-1, 0), True); + runcheck("cond_l_le_0_m1", longint_le(0, -1), False); + runcheck("cond_l_le_m1_m1", longint_le(-1, -1), True); +end; + +function longcard_eq(i1, i2: LongCard): Boolean; +begin + longcard_eq := (i1 = i2); +end; + +function longcard_ne(i1, i2: LongCard): Boolean; +begin + longcard_ne := (i1 <> i2); +end; + +function longcard_ge(i1, i2: LongCard): Boolean; +begin + longcard_ge := (i1 >= i2); +end; + +function longcard_gt(i1, i2: LongCard): Boolean; +begin + longcard_gt := (i1 > i2); +end; + +function longcard_le(i1, i2: LongCard): Boolean; +begin + longcard_le := (i1 <= i2); +end; + +function longcard_lt(i1, i2: LongCard): Boolean; +begin + longcard_lt := (i1 < i2); +end; + +procedure longcard_tests; +begin + runcheck("cond_ul_eq_0_0", longcard_eq(0, 0), True); + runcheck("cond_ul_eq_1_1", longcard_eq(1, 1), True); + runcheck("cond_ul_eq_1_0", longcard_eq(1, 0), False); + runcheck("cond_ul_eq_1_0", longcard_eq(0, 1), False); + runcheck("cond_ul_ne_0_0", longcard_ne(0, 0), False); + runcheck("cond_ul_ne_1_1", longcard_ne(1, 1), False); + runcheck("cond_ul_ne_1_0", longcard_ne(1, 0), True); + runcheck("cond_ul_ne_0_1", longcard_ne(0, 1), True); + runcheck("cond_ul_gt_0_0", longcard_gt(0, 0), False); + runcheck("cond_ul_gt_1_1", longcard_gt(1, 1), False); + runcheck("cond_ul_gt_1_0", longcard_gt(1, 0), True); + runcheck("cond_ul_gt_0_1", longcard_gt(0, 1), False); + runcheck("cond_ul_gt_8000000000000000h_0", longcard_gt(8000000000000000h, 0), True); + runcheck("cond_ul_gt_0_8000000000000000h", longcard_gt(0, 8000000000000000h), False); + runcheck("cond_ul_gt_8000000000000000h_8000000000000000h", longcard_gt(8000000000000000h, 8000000000000000h), False); + runcheck("cond_ul_ge_0_0", longcard_ge(0, 0), True); + runcheck("cond_ul_ge_1_1", longcard_ge(1, 1), True); + runcheck("cond_ul_ge_1_0", longcard_ge(1, 0), True); + runcheck("cond_ul_ge_0_1", longcard_ge(0, 1), False); + runcheck("cond_ul_ge_8000000000000000h_0", longcard_ge(8000000000000000h, 0), True); + runcheck("cond_ul_ge_0_8000000000000000h", longcard_ge(0, 8000000000000000h), False); + runcheck("cond_ul_ge_8000000000000000h_8000000000000000h", longcard_ge(8000000000000000h, 8000000000000000h), True); + runcheck("cond_ul_lt_0_0", longcard_lt(0, 0), False); + runcheck("cond_ul_lt_1_1", longcard_lt(1, 1), False); + runcheck("cond_ul_lt_1_0", longcard_lt(1, 0), False); + runcheck("cond_ul_lt_0_1", longcard_lt(0, 1), True); + runcheck("cond_ul_lt_8000000000000000h_0", longcard_lt(8000000000000000h, 0), False); + runcheck("cond_ul_lt_0_8000000000000000h", longcard_lt(0, 8000000000000000h), True); + runcheck("cond_ul_lt_8000000000000000h_8000000000000000h", longcard_lt(8000000000000000h, 8000000000000000h), False); + runcheck("cond_ul_le_0_0", longcard_le(0, 0), True); + runcheck("cond_ul_le_1_1", longcard_le(1, 1), True); + runcheck("cond_ul_le_1_0", longcard_le(1, 0), False); + runcheck("cond_ul_le_0_1", longcard_le(0, 1), True); + runcheck("cond_ul_le_8000000000000000h_0", longcard_le(8000000000000000h, 0), False); + runcheck("cond_ul_le_0_8000000000000000h", longcard_le(0, 8000000000000000h), True); + runcheck("cond_ul_le_8000000000000000h_8000000000000000h", longcard_le(8000000000000000h, 8000000000000000h), True); +end; + +function shortreal_eq(f1, f2: ShortReal): Boolean; +begin + shortreal_eq := (f1 = f2); +end; + +function shortreal_ne(f1, f2: ShortReal): Boolean; +begin + shortreal_ne := (f1 <> f2); +end; + +function shortreal_ge(f1, f2: ShortReal): Boolean; +begin + shortreal_ge := (f1 >= f2); +end; + +function shortreal_gt(f1, f2: ShortReal): Boolean; +begin + shortreal_gt := (f1 > f2); +end; + +function shortreal_le(f1, f2: ShortReal): Boolean; +begin + shortreal_le := (f1 <= f2); +end; + +function shortreal_lt(f1, f2: ShortReal): Boolean; +begin + shortreal_lt := (f1 < f2); +end; + +procedure shortreal_tests; +begin + runcheck("cond_f_eq_0.0_0.0", shortreal_eq(0.0, 0.0), True); + runcheck("cond_f_eq_1.0_0.0", shortreal_eq(1.0, 0.0), False); + runcheck("cond_f_eq_0.0_1.0", shortreal_eq(0.0, 1.0), False); + runcheck("cond_f_ne_0.0_0.0", shortreal_ne(0.0, 0.0), False); + runcheck("cond_f_ne_1.0_0.0", shortreal_ne(1.0, 0.0), True); + runcheck("cond_f_ne_0.0_1.0", shortreal_ne(0.0, 1.0), True); + runcheck("cond_f_gt_0.0_0.0", shortreal_gt(0.0, 0.0), False); + runcheck("cond_f_gt_1.0_0.0", shortreal_gt(1.0, 0.0), True); + runcheck("cond_f_gt_0.0_1.0", shortreal_gt(0.0, 1.0), False); + runcheck("cond_f_ge_0.0_0.0", shortreal_ge(0.0, 0.0), true); + runcheck("cond_f_ge_1.0_0.0", shortreal_ge(1.0, 0.0), True); + runcheck("cond_f_ge_0.0_1.0", shortreal_ge(0.0, 1.0), False); + runcheck("cond_f_lt_0.0_0.0", shortreal_lt(0.0, 0.0), False); + runcheck("cond_f_lt_1.0_0.0", shortreal_lt(1.0, 0.0), False); + runcheck("cond_f_lt_0.0_1.0", shortreal_lt(0.0, 1.0), True); + runcheck("cond_f_le_0.0_0.0", shortreal_le(0.0, 0.0), True); + runcheck("cond_f_le_1.0_0.0", shortreal_le(1.0, 0.0), False); + runcheck("cond_f_le_0.0_1.0", shortreal_le(0.0, 1.0), True); +end; + +function real_eq(f1, f2: Real): Boolean; +begin + real_eq := (f1 = f2); +end; + +function real_ne(f1, f2: Real): Boolean; +begin + real_ne := (f1 <> f2); +end; + +function real_ge(f1, f2: Real): Boolean; +begin + real_ge := (f1 >= f2); +end; + +function real_gt(f1, f2: Real): Boolean; +begin + real_gt := (f1 > f2); +end; + +function real_le(f1, f2: Real): Boolean; +begin + real_le := (f1 <= f2); +end; + +function real_lt(f1, f2: Real): Boolean; +begin + real_lt := (f1 < f2); +end; + +procedure real_tests; +begin + runcheck("cond_d_eq_0.0_0.0", real_eq(0.0, 0.0), True); + runcheck("cond_d_eq_1.0_0.0", real_eq(1.0, 0.0), False); + runcheck("cond_d_eq_0.0_1.0", real_eq(0.0, 1.0), False); + runcheck("cond_d_ne_0.0_0.0", real_ne(0.0, 0.0), False); + runcheck("cond_d_ne_1.0_0.0", real_ne(1.0, 0.0), True); + runcheck("cond_d_ne_0.0_1.0", real_ne(0.0, 1.0), True); + runcheck("cond_d_gt_0.0_0.0", real_gt(0.0, 0.0), False); + runcheck("cond_d_gt_1.0_0.0", real_gt(1.0, 0.0), True); + runcheck("cond_d_gt_0.0_1.0", real_gt(0.0, 1.0), False); + runcheck("cond_d_ge_0.0_0.0", real_ge(0.0, 0.0), true); + runcheck("cond_d_ge_1.0_0.0", real_ge(1.0, 0.0), True); + runcheck("cond_d_ge_0.0_1.0", real_ge(0.0, 1.0), False); + runcheck("cond_d_lt_0.0_0.0", real_lt(0.0, 0.0), False); + runcheck("cond_d_lt_1.0_0.0", real_lt(1.0, 0.0), False); + runcheck("cond_d_lt_0.0_1.0", real_lt(0.0, 1.0), True); + runcheck("cond_d_le_0.0_0.0", real_le(0.0, 0.0), True); + runcheck("cond_d_le_1.0_0.0", real_le(1.0, 0.0), False); + runcheck("cond_d_le_0.0_1.0", real_le(0.0, 1.0), True); +end; + +function longreal_eq(f1, f2: LongReal): Boolean; +begin + longreal_eq := (f1 = f2); +end; + +function longreal_ne(f1, f2: LongReal): Boolean; +begin + longreal_ne := (f1 <> f2); +end; + +function longreal_ge(f1, f2: LongReal): Boolean; +begin + longreal_ge := (f1 >= f2); +end; + +function longreal_gt(f1, f2: LongReal): Boolean; +begin + longreal_gt := (f1 > f2); +end; + +function longreal_le(f1, f2: LongReal): Boolean; +begin + longreal_le := (f1 <= f2); +end; + +function longreal_lt(f1, f2: LongReal): Boolean; +begin + longreal_lt := (f1 < f2); +end; + +procedure longreal_tests; +begin + runcheck("cond_n_eq_0.0_0.0", longreal_eq(0.0, 0.0), True); + runcheck("cond_n_eq_1.0_0.0", longreal_eq(1.0, 0.0), False); + runcheck("cond_n_eq_0.0_1.0", longreal_eq(0.0, 1.0), False); + runcheck("cond_n_ne_0.0_0.0", longreal_ne(0.0, 0.0), False); + runcheck("cond_n_ne_1.0_0.0", longreal_ne(1.0, 0.0), True); + runcheck("cond_n_ne_0.0_1.0", longreal_ne(0.0, 1.0), True); + runcheck("cond_n_gt_0.0_0.0", longreal_gt(0.0, 0.0), False); + runcheck("cond_n_gt_1.0_0.0", longreal_gt(1.0, 0.0), True); + runcheck("cond_n_gt_0.0_1.0", longreal_gt(0.0, 1.0), False); + runcheck("cond_n_ge_0.0_0.0", longreal_ge(0.0, 0.0), true); + runcheck("cond_n_ge_1.0_0.0", longreal_ge(1.0, 0.0), True); + runcheck("cond_n_ge_0.0_1.0", longreal_ge(0.0, 1.0), False); + runcheck("cond_n_lt_0.0_0.0", longreal_lt(0.0, 0.0), False); + runcheck("cond_n_lt_1.0_0.0", longreal_lt(1.0, 0.0), False); + runcheck("cond_n_lt_0.0_1.0", longreal_lt(0.0, 1.0), True); + runcheck("cond_n_le_0.0_0.0", longreal_le(0.0, 0.0), True); + runcheck("cond_n_le_1.0_0.0", longreal_le(1.0, 0.0), False); + runcheck("cond_n_le_0.0_1.0", longreal_le(0.0, 1.0), True); +end; + +procedure run_tests; +begin + const_integer_tests; + integer_tests; + cardinal_tests; + longint_tests; + longcard_tests; + shortreal_tests; + real_tests; + longreal_tests; +end; + +begin + failed := False; + run_tests; + if failed then begin + Terminate(1); + end; +end. diff --git a/tests/math.pas b/tests/math.pas index 2d57b0f..135e810 100644 --- a/tests/math.pas +++ b/tests/math.pas @@ -40,6 +40,26 @@ begin end; end; +procedure runi(msg: String; value, expected, delta: Integer); +begin + run(msg, Abs(value - expected) <= delta); +end; + +procedure runl(msg: String; value, expected, delta: LongInt); +begin + run(msg, Abs(value - expected) <= delta); +end; + +procedure runui(msg: String; value, expected, delta: Cardinal); +begin + run(msg, Abs(value - expected) <= delta); +end; + +procedure runul(msg: String; value, expected, delta: LongCard); +begin + run(msg, Abs(value - expected) <= delta); +end; + procedure runf(msg: String; value, expected, delta: ShortReal); begin run(msg, Abs(value - expected) <= delta); @@ -55,6 +75,21 @@ begin run(msg, Abs(value - expected) <= delta); end; +function fneg(f: ShortReal): ShortReal; +begin + fneg := -f; +end; + +function dneg(f: Real): Real; +begin + dneg := -f; +end; + +function nfneg(f: LongReal): LongReal; +begin + nfneg := -f; +end; + procedure run_tests; var b: Byte; @@ -62,6 +97,10 @@ var f: ShortReal; d: Real; n: LongReal; + i1, i2: Integer; + l1, l2: LongInt; + ui1, ui2: Cardinal; + ul1, ul2: LongCard; begin { Initialize some values of odd type sizes } b := 3; @@ -82,25 +121,236 @@ begin run("math_coerce_nfloat", SameType(LongReal, Abs(n))); { Test that the operators give sane answers } - runf("math_sin_0", Sin(ShortReal(0.0)), ShortReal(0.0), 0.00001); - runf("math_sin_pi_2", Sin(ShortReal(pi / 2)), ShortReal(1.0), 0.00001); + { Integer versions } + runi("math_ci_abs_6", Abs(6), 6, 0); + runi("math_ci_abs_m6", Abs(-6), 6, 0); + runi("math_ci_max_1_6", Max(1, 6), 6, 0); + runi("math_ci_max_m1_6", Max(-1, 6), 6, 0); + runi("math_ci_max_1_m6", Max(1, -6), 1, 0); + runi("math_ci_max_m1_m6", Max(-1, -6), -1, 0); + runi("math_ci_min_1_6", Min(1, 6), 1, 0); + runi("math_ci_min_m1_6", Min(-1, 6), -1, 0); + runi("math_ci_min_1_m6", Min(1, -6), -6, 0); + runi("math_ci_min_m1_m6", Min(-1, -6), -6, 0); + runi("math_ci_sign_m6", Sign(-6), -1, 0); + runi("math_ci_sign_6", Sign(6), 1, 0); + runi("math_ci_sign_0", Sign(0), 0, 0); + + + runi("math_i_div_6_2", 6 / 2, 3, 0); + runi("math_i_div_9_3", 9 / 3, 3, 0); + runi("math_i_div_9_2", 9 / 2, 4, 0); + runi("math_i_div_m9_2", -9 / 2, -4, 0); + runi("math_i_div_m9_3", -9 / 3, -3, 0); + runi("math_i_div_m9_m2", -9 / (-2), 4, 0); + runi("math_i_div_m9_m3", -9 / (-3), 3, 0); + runi("math_i_mod_6_2", 6 mod 2, 0, 0); + runi("math_i_mod_9_3", 9 mod 3, 0, 0); + runi("math_i_mod_9_2", 9 mod 2, 1, 0); + runi("math_i_mod_m9_2", -9 mod 2, -1, 0); + runi("math_i_mod_m9_3", -9 mod 3, 0, 0); + runi("math_i_mod_m9_m2", -9 mod (-2), -1, 0); + runi("math_i_mod_m9_m3", -9 mod (-3), 0, 0); + i1 := 6; + runi("math_i_abs_6", Abs(i1), 6, 0); + i1 := -6; + runi("math_i_abs_m6", Abs(i1), 6, 0); + i1 := 1; + i2 := 6; + runi("math_i_max_1_6", Max(i1, i2), 6, 0); + i1 := -1; + runi("math_i_max_m1_6", Max(i1, i2), 6, 0); + i1 := 1; + i2 := -6; + runi("math_i_max_1_m6", Max(i1, i2), 1, 0); + i1 := -1; + runi("math_i_max_m1_m6", Max(i1, i2), -1, 0); + i1 := 1; + i2 := 6; + runi("math_i_min_1_6", Min(i1, i2), 1, 0); + i1 := -1; + runi("math_i_min_m1_6", Min(i1, i2), -1, 0); + i1 := 1; + i2 := -6; + runi("math_i_min_1_m6", Min(i1, i2), -6, 0); + i1 := -1; + runi("math_i_min_m1_m6", Min(i1, i2), -6, 0); + i1 := -6; + runi("math_i_sign_m6", Sign(i1), -1, 0); + i1 := 6; + runi("math_i_sign_6", Sign(i1), 1, 0); + i1 := 0; + runi("math_i_sign_0", Sign(i1), 0, 0); + + { LongInt versions } + runl("math_cl_abs_6", Abs(600000000h), 600000000h, 0); + runl("math_cl_abs_m6", Abs(-600000000h), 600000000h, 0); + runl("math_cl_max_1_6", Max(100000000h, 600000000h), 600000000h, 0); + runl("math_cl_max_m1_6", Max(-100000000h, 600000000h), 600000000h, 0); + runl("math_cl_max_1_m6", Max(100000000h, -600000000h), 100000000h, 0); + runl("math_cl_max_m1_m6", Max(-100000000h, -600000000h), -100000000h, 0); + runl("math_cl_min_1_6", Min(100000000h, 600000000h), 100000000h, 0); + runl("math_cl_min_m1_6", Min(-100000000h, 600000000h), -100000000h, 0); + runl("math_cl_min_1_m6", Min(100000000h, -600000000h), -600000000h, 0); + runl("math_cl_min_m1_m6", Min(-100000000h, -600000000h), -600000000h, 0); + runi("math_cl_sign_m6", Sign(-600000000h), -1, 0); + runi("math_cl_sign_6", Sign(600000000h), 1, 0); + runi("math_cl_sign_0", Sign(0), 0, 0); + + l1 := 6; + runl("math_l_div_6_2", l1 / 2, 3, 0); + l1 := 9; + runl("math_l_div_9_3", l1 / 3, 3, 0); + runl("math_l_div_9_2", l1 / 2, 4, 0); + l1 := -9; + runl("math_l_div_m9_2", l1 / 2, -4, 0); + runl("math_l_div_m9_3", l1 / 3, -3, 0); + runl("math_l_div_m9_m2", l1 / (-2), 4, 0); + runl("math_l_div_m9_m3", l1 / (-3), 3, 0); + l1 := 6; + runl("math_l_mod_6_2", l1 mod 2, 0, 0); + l1 := 9; + runl("math_l_mod_9_3", l1 mod 3, 0, 0); + runl("math_l_mod_9_2", l1 mod 2, 1, 0); + l1 := -9; + runl("math_l_mod_m9_2", l1 mod 2, -1, 0); + runl("math_l_mod_m9_3", l1 mod 3, 0, 0); + runl("math_l_mod_m9_m2", l1 mod (-2), -1, 0); + runl("math_l_mod_m9_m3", l1 mod (-3), 0, 0); + l1 := 6; + runl("math_l_abs_6", Abs(l1), 6, 0); + l1 := -6; + runl("math_l_abs_m6", Abs(l1), 6, 0); + l1 := 1; + l2 := 6; + runl("math_l_max_1_6", Max(l1, l2), 6, 0); + l1 := -1; + runl("math_l_max_m1_6", Max(l1, l2), 6, 0); + l1 := 1; + l2 := -6; + runl("math_l_max_1_m6", Max(l1, l2), 1, 0); + l1 := -1; + runl("math_l_max_m1_m6", Max(l1, l2), -1, 0); + l1 := 1; + l2 := 6; + runl("math_l_min_1_6", Min(l1, l2), 1, 0); + l1 := -1; + runl("math_l_min_m1_6", Min(l1, l2), -1, 0); + l1 := 1; + l2 := -6; + runl("math_l_min_1_m6", Min(l1, l2), -6, 0); + l1 := -1; + runl("math_l_min_m1_m6", Min(l1, l2), -6, 0); + l1 := -6; + runi("math_l_sign_m6", Sign(l1), -1, 0); + l1 := 6; + runi("math_l_sign_6", Sign(l1), 1, 0); + l1 := 0; + runi("math_l_sign_0", Sign(l1), 0, 0); + + { Unsigned integer versions } + ui1 := 1; + ui2 := 6; + runui("math_ui_max_1_6", Max(ui1, ui2), 6, 0); + ui1 := 0ffffffffh; + ui2 := 0fffffff1h; + runui("math_ui_max_ffffffff_fffffff1", Max(ui1, ui2), 0ffffffffh, 0); + ui1 := 1; + ui2 := 6; + runui("math_ui_min_1_6", Min(ui1, ui2), 1, 0); + ui1 := 0ffffffffh; + ui2 := 0fffffff1h; + runui("math_ui_min_ffffffff_fffffff1", Min(ui1, ui2), 0fffffff1h, 0); + + { Unsigned long versions } + ul1 := 1; + ul2 := 6; + runul("math_ul_max_1_6", Max(ul1, ul2), 6, 0); + ul1 := 0ffffffffffffffffh; + ul2 := 0fffffffffffffff1h; + runul("math_ui_max_ffffffffffffffff_fffffffffffffff1", Max(ul1, ul2), 0ffffffffffffffffh, 0); + ul1 := 1; + ul2 := 6; + runul("math_ul_min_1_6", Min(ul1, ul2), 1, 0); + ul1 := 0ffffffffffffffffh; + ul2 := 0fffffffffffffff1h; + runui("math_ul_min_ffffffffffffffff_fffffffffffffff1", Min(ul1, ul2), 0fffffffffffffff1h, 0); + + { short real versions } + runf("math_f_abs_1.5", Abs(ShortReal(1.5)), ShortReal(1.5), 0.00001); + runf("math_f_abs_m1.5", Abs(ShortReal(-1.5)), ShortReal(1.5), 0.00001); + runf("math_f_neg_1.5", fneg(1.5), ShortReal(-1.5), 0.00001); + runf("math_f_neg_m1.5", fneg(-1.5), ShortReal(1.5), 0.00001); + runf("math_f_max_1_6", Max(ShortReal(1.0), ShortReal(6.0)), ShortReal(6.0), 0.00001); + runf("math_f_min_1_6", Min(ShortReal(1.0), ShortReal(6.0)), ShortReal(1.0), 0.00001); + runf("math_f_sin_0", Sin(ShortReal(0.0)), ShortReal(0.0), 0.00001); + runf("math_f_sin_pi_2", Sin(ShortReal(pi / 2)), ShortReal(1.0), 0.00001); f := ShortReal(pi); - runf("math_sin_pi", Sin(f), ShortReal(0.0), 0.00001); - runf("math_cos_0", Cos(ShortReal(0.0)), ShortReal(1.0), 0.00001); - runf("math_sqrt_1", Sqrt(ShortReal(1.0)), ShortReal(1.0), 0.00001); - runf("math_sqrt_2", Sqrt(ShortReal(2.0)), ShortReal(1.4142), 0.0001); + runf("math_f_sin_pi", Sin(f), ShortReal(0.0), 0.00001); + runf("math_f_cos_0", Cos(ShortReal(0.0)), ShortReal(1.0), 0.00001); + runf("math_f_sqrt_1", Sqrt(ShortReal(1.0)), ShortReal(1.0), 0.00001); + runf("math_f_sqrt_2", Sqrt(ShortReal(2.0)), ShortReal(1.4142), 0.0001); f := Sqrt(ShortReal(-1.0)); - run("math_sqrt_m1", IsNaN(f)); - rund("math_ceil_1.5", Ceil(Real(1.5)), Real(2.0), 0.00001); - rund("math_ceil_m1.5", Ceil(Real(-1.5)), Real(-1.0), 0.00001); - rund("math_floor_1.5", Floor(Real(1.5)), Real(1.0), 0.00001); - rund("math_floor_m1.5", Floor(Real(-1.5)), Real(-2.0), 0.00001); - rund("math_rint_1.5", Rint(Real(1.5)), Real(2.0), 0.00001); - rund("math_rint_2.5", Rint(Real(2.5)), Real(2.0), 0.00001); - rund("math_round_1.5", Round(Real(1.5)), Real(2.0), 0.00001); - rund("math_round_2.5", Round(Real(2.5)), Real(3.0), 0.00001); - runn("math_max_1_6", Max(1.0, 6.0), 6.0, 0.00001); - runn("math_min_1_6", Min(1.0, 6.0), 1.0, 0.00001); + run("math_f_sqrt_m1", IsNaN(f)); + runf("math_f_ceil_1.5", Ceil(ShortReal(1.5)), ShortReal(2.0), 0.00001); + runf("math_f_ceil_m1.5", Ceil(ShortReal(-1.5)), ShortReal(-1.0), 0.00001); + runf("math_f_floor_1.5", Floor(ShortReal(1.5)), ShortReal(1.0), 0.00001); + runf("math_f_floor_m1.5", Floor(ShortReal(-1.5)), ShortReal(-2.0), 0.00001); + runf("math_f_rint_1.5", Rint(ShortReal(1.5)), ShortReal(2.0), 0.00001); + runf("math_f_rint_2.5", Rint(ShortReal(2.5)), ShortReal(2.0), 0.00001); + runf("math_f_round_1.5", Round(ShortReal(1.5)), ShortReal(2.0), 0.00001); + runf("math_f_round_2.5", Round(ShortReal(2.5)), ShortReal(3.0), 0.00001); + + { real versions } + rund("math_d_abs_1.5", Abs(Real(1.5)), Real(1.5), 0.00001); + rund("math_d_abs_m1.5", Abs(Real(-1.5)), Real(1.5), 0.00001); + rund("math_d_neg_1.5", dneg(1.5), Real(-1.5), 0.00001); + rund("math_d_neg_m1.5", dneg(-1.5), Real(1.5), 0.00001); + rund("math_d_max_1_6", Max(Real(1.0), Real(6.0)), Real(6.0), 0.00001); + rund("math_d_min_1_6", Min(Real(1.0), Real(6.0)), Real(1.0), 0.00001); + rund("math_d_sin_0", Sin(Real(0.0)), Real(0.0), 0.00001); + rund("math_d_sin_pi_2", Sin(Real(pi / 2)), Real(1.0), 0.00001); + d := Real(pi); + rund("math_d_sin_pi", Sin(d), Real(0.0), 0.00001); + rund("math_d_cos_0", Cos(Real(0.0)), Real(1.0), 0.00001); + rund("math_d_sqrt_1", Sqrt(Real(1.0)), Real(1.0), 0.00001); + rund("math_d_sqrt_2", Sqrt(Real(2.0)), Real(1.4142), 0.0001); + d := Sqrt(Real(-1.0)); + run("math_d_sqrt_m1", IsNaN(d)); + rund("math_d_ceil_1.5", Ceil(Real(1.5)), Real(2.0), 0.00001); + rund("math_d_ceil_m1.5", Ceil(Real(-1.5)), Real(-1.0), 0.00001); + rund("math_d_floor_1.5", Floor(Real(1.5)), Real(1.0), 0.00001); + rund("math_d_floor_m1.5", Floor(Real(-1.5)), Real(-2.0), 0.00001); + rund("math_d_rint_1.5", Rint(Real(1.5)), Real(2.0), 0.00001); + rund("math_d_rint_2.5", Rint(Real(2.5)), Real(2.0), 0.00001); + rund("math_d_round_1.5", Round(Real(1.5)), Real(2.0), 0.00001); + rund("math_d_round_2.5", Round(Real(2.5)), Real(3.0), 0.00001); + + { long real versions } + runn("math_n_abs_1.5", Abs(LongReal(1.5)), LongReal(1.5), 0.00001); + runn("math_n_abs_m1.5", Abs(LongReal(-1.5)), LongReal(1.5), 0.00001); + runn("math_n_neg_1.5", nfneg(1.5), LongReal(-1.5), 0.00001); + runn("math_n_neg_m1.5", nfneg(-1.5), LongReal(1.5), 0.00001); + runn("math_n_max_1_6", Max(LongReal(1.0), LongReal(6.0)), LongReal(6.0), 0.00001); + runn("math_n_min_1_6", Min(LongReal(1.0), LongReal(6.0)), LongReal(1.0), 0.00001); + runn("math_n_sin_0", Sin(LongReal(0.0)), LongReal(0.0), 0.00001); + runn("math_n_sin_pi_2", Sin(LongReal(pi / 2)), LongReal(1.0), 0.00001); + n := LongReal(pi); + runn("math_n_sin_pi", Sin(n), LongReal(0.0), 0.00001); + runn("math_n_cos_0", Cos(LongReal(0.0)), LongReal(1.0), 0.00001); + runn("math_n_sqrt_1", Sqrt(LongReal(1.0)), LongReal(1.0), 0.00001); + runn("math_n_sqrt_2", Sqrt(LongReal(2.0)), LongReal(1.4142), 0.0001); + n := Sqrt(LongReal(-1.0)); + run("math_n_sqrt_m1", IsNaN(n)); + runn("math_n_ceil_1.5", Ceil(LongReal(1.5)), LongReal(2.0), 0.00001); + runn("math_n_ceil_m1.5", Ceil(LongReal(-1.5)), LongReal(-1.0), 0.00001); + runn("math_n_floor_1.5", Floor(LongReal(1.5)), LongReal(1.0), 0.00001); + runn("math_n_floor_m1.5", Floor(LongReal(-1.5)), LongReal(-2.0), 0.00001); + runn("math_n_rint_1.5", Rint(LongReal(1.5)), LongReal(2.0), 0.00001); + runn("math_n_rint_2.5", Rint(LongReal(2.5)), LongReal(2.0), 0.00001); + runn("math_n_round_1.5", Round(LongReal(1.5)), LongReal(2.0), 0.00001); + runn("math_n_round_2.5", Round(LongReal(2.5)), LongReal(3.0), 0.00001); + end; begin -- 2.47.3