summaryrefslogtreecommitdiffstats
path: root/tests/016
Commit message (Collapse)AuthorAgeFilesLines
* New macros: each-true, some-true, each-false, some-false.Kaz Kylheku2022-01-122-42/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lisplib.c (arith_each_set_entries): Trigger autoload on new symbols. * stdilb/arith-each.tl (sys:arith-each): Generalize macro to handle short-circuiting logical operations. The op-iv parameter, which is a cons, is spread into two op and iv parameter. One new argument appears, short-circ. This specifies a code for short-circuiting behavior: t means iteration continues while the result is true; nil means it continues while it is nil, and + means iteration continues while the accumulator is nonzero. A new convention is in effect: the operator has to be specified as a list in order to request accumulating behavior, e.g (+) or (*). Otherwise the operator specifies a predicate that is applied to the forms, without taking into account the prior value. (sum-each, sum-each*, mul-each, mul-each*): Spread the op-iv arguments. Wrap the op argument in a list to request accumulation. In the case of mul-each and mul-each*, specify + for the short-circ argument, which means that iteration stops when the accumulator becomes zerop. sum-each and sum-each* specify : for the short-circ argument which is unrecognized, and so ther is no short-circuiting behavior. (each-true, some-true, each-false, some-false): New macros. * tests/016/arith.tl: New tests. * txr.1: Documented new macros and added note about possible short-circuiting in mul-each and mul-each*. * stdlib/doc-syms.tl: Updated.
* sum-each, mul-each: handle no vars case.Kaz Kylheku2022-01-112-0/+62
| | | | | | | | | | | | | | | * stdlib/arith-each.tl (sys:arith-each): If there are no vars, then just reduce to the identity element value. This is alreading happening fine for the each-prod family of operators. * tests/016/arith.tl: Test cases covering the no vars and empty iteration identity element cases for sum-each and mul-each, as well as the *-prod variants. * txr.1: Document empty iteration and empty vars behavior for arithmetic each operators as well as the each-prod family.
* quantile: fix test needing nonportable amount of precision.Kaz Kylheku2021-09-271-11/+11
| | | | | | | | | | | | | | * tests/common.tl (sstest): New macro. Like stest, but the right hand side is an object which the macro turns to a string, rather than expecting a string. * tests/016/arith.tl: Use the sstest macro for the main quantile test to compare the result and expected value as character strings rather than objects. Specify the expected values using no more than 14 decimal digits of precision, and over the scope of the test case, restrict floating-point printing to 14 digits. Thus, we effectively have quick and dirty epsilon comparison to 14 digits that recurses over the list, without having to write that as a function.
* quantile: fix failing test.Kaz Kylheku2021-09-251-1/+1
| | | | | * arith.tl: Somehow I committed some wrong expected numbers in a quantile test, yet didn't catch the test failure.
* New variants of each operator for sum and product.Kaz Kylheku2021-09-231-0/+58
| | | | | | | | | | | | | | | | | | | | | | | | | * lisplib.c (arith_each_instantiate, arith_each_set_entries): New functions. (each_prod_set_entries): Add sum-each-prod, sum-each-prod*, mul-each-prod and mul-each-prod* as autoload triggers for each-prod.tl, where those macros are now defined. (lisplib_init): Register autoloading of arith-each.tl via the two new functions. * stdlib/arith-each.tl: New file. * stdlib/each-prod.tl (sys:expand-each-prod*): Handle sum-each-prod* and mul-each-prod* in the same way, by mapping to their parallel binding counterparts. (sys:expand-arith-each-prod): New function. (sym-each-prod, mul-each-prod, sum-each-prod*, mul-each-prod*): New macros. * tests/016/arith.tl: New tests. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* math: quantile estimator using P-Squared algorithm.Kaz Kylheku2021-09-221-0/+31
| | | | | | | | | | | | | | | | | | | * Makefile (psquare.o): New object file. * arith.c (psq_ops): New static structure. (quant_fun): New static function. (quantile): New function. (arith_init): Register quantile intrinsic. * arith.h (quantile): Declared. * psquare.c, psquare.h: New files. * tests/016/arith.tl: New tests. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* int-str: 0x bug.Kaz Kylheku2021-08-131-0/+50
| | | | | | | | | | | | | | | * lib.c (int_str): The problem here is that we are recognizing and skipping the 0x prefix for all bases. So for instance (int-str "0x123") produces 123. The correct requirement, and the intent of the code, is that the C conventions are only honored if the base is specified as the character #\c. In any other base, including omitted base defaulting to 10, a leading zero is just a leading zero, and 0x is a zero followed by the junk character x. Therefore, if we have any valid base that isn't #\c, and 0x has been seen, we must return zero. We must not do this only in the base 16 case. * tests/016/conv.tl: New file.
* math: forbid dubious inequality comparisons.Kaz Kylheku2021-06-151-0/+56
| | | | | | | | | | | | | | | | | | | The issue, reported by Paul A. Patience, is that code like (< 1 "abc") is successfully producing a result. The root cause is that 1 is an iterable object, and so is treated as a sequence opposite to the "abc" operand. We should allow only true sequences in this situation. * arith.c (seq_lt_compat_check): New static function. Checks that neither of two sequences is SEQ_NOTSEQ or SEQ_HASHLIKE. (seq_lt, seq_le): Use seq_lt_compat_check to reject dubious inputs. * txr.1: Minor wording change in the related documentation, removing a gratuitous adjective. * tests/016/arith.tl: Inequality tests.
* arith: switch sum and prod to seq_iter.Kaz Kylheku2021-06-091-0/+24
| | | | | | | | | | | | | | * arith.c (nary_op_keyfun): Static function removed. (nary_op_seq, nary_op_seq_keyfun): New static functions. (sumv, prodv): Static functions removed. (sum, prod): Reimplement using nary_op_seq and nary_op_seq_keyfun. Conversion of sequence to list smuggled via args is gone. * tests/016/arith.tl: new sum and prod tests. * txr.1: Note about sum and prod taking an iterable sequence added.
* match: binary-integer conv tests for #x-8000...Kaz Kylheku2021-05-211-0/+21
| | | | | | * tests/016/arith.tl: Test providing coverage for the most negative two's complement integer, #x-800...00 in various sizes. The 64 bit cases are failing.
* math: add some tests related to integer conversion.Kaz Kylheku2021-05-211-0/+50
| | | | | | * tests/016/arith.tl: Add tests covering the fixnum/bignum knee, and ffi operations of various sizes that provide coverage of various conversion routines.
* tests: implicitly generate empty .expected files.Kaz Kylheku2021-04-122-0/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Makefile (%.expected): New implicit rule. Whenever a test requires a .expected file, if it is missing, we create an empty one. This file will be treated as an intermediate by GNU Make, which means that it will be deleted when make terminates. * tests/012/compile.tl: Some of the .tl files no longer have an .expected file, so we have to test for that in the catenating logic. * tests/008/call-2.expected, * tests/008/no-stdin-hang.expected, * tests/011/macros-3.expected, * tests/011/patmatch.expected, * tests/012/aseq.expected, * tests/012/ashwin.expected, * tests/012/compile.tl, * tests/012/cont.expected, * tests/012/defset.expected, * tests/012/ifa.expected, * tests/012/oop-seq.expected, * tests/012/parse.expected, * tests/012/quasi.expected, * tests/012/quine.expected, * tests/012/seq.expected, * tests/012/struct.expected, * tests/012/stslot.expected, * tests/014/dgram-stream.expected, * tests/014/in6addr-str.expected, * tests/014/inaddr-str.expected, * tests/014/socket-basic.expected, * tests/015/awk-fconv.expected, * tests/015/split.expected, * tests/015/trim.expected, * tests/016/arith.expected, * tests/016/ud-arith.expected, * tests/017/ffi-misc.expected, * tests/018/chmod.expected: Empty file deleted.
* bracket: bug: wrong result when function is applied.Kaz Kylheku2019-09-101-0/+14
| | | | | | | | | | | | Reported by user vapnik spaknik. * lib.c (bracket): Don't rely on the index variable to step through the arguments, because it only counts fixed arguments. The args_get function doesn't increment the index beyond args->fill; when popping arguments from args->list, index stays unmodified. * tests/016/arith.tl: Tests for bracket added.
* tests: add tests for digits function.Kaz Kylheku2019-09-091-0/+18
| | | | * tests/016/arith.tl: Add various digits tests.
* u-d-arithmetic: proper treatment of ceil & round.Kaz Kylheku2019-03-301-2/+10
| | | | | | | | | | | | | | | * arith.c (r_ceil_s, r_round_s): New symbol variables. (ceildiv, roundiv): Route binary cases involving struts directly to binary methods so the object is responsible for the complete implementation. (arith_init): Initialize r_ceil_s and r_round_s. * tests/016/ud-arith.tl (numbase): Binary methods added for ceil and round. Test cases added. * txr.1: Descriptions for binary ceil and round methods added; Notes about non-existence of binary methods removed from unary ceil and round removed.
* Tests for user-defined arithmetic and fixes.Kaz Kylheku2019-03-302-0/+132
| | | | | | | | | | | | | | | | | | | | | | | * tests/016/ud-arith.expected b/tests/016/ud-arith.tl: New file. * tests/016/ud-arith.expected b/tests/016/ud-arith.expected: New file. * arith.c (divi): Bugfix: wrong argument tested for being a COBJ. (logtrunc): Fix incorrect method call: calling r-logtrunc-s for the object-in-left-position case. (sign_extend): Fix semantics not following documentation: dispatch method with original arguments. (divv): When there is just one argument, take advantage of the hitherto unused unary case of divi rather than giving it both arguments. The object dispatch is in that unary case, so we need it now. (arith_init): Fix wrong name of r_lognot_s symbol. * txr.1: Fix atan2 being documented as atan. Fix misspelling of r-lognot as lognot-r.
* New arithmetic tests.Kaz Kylheku2016-11-152-0/+41
* Makefile (TXR_DBG_OPTS): Suppress for new directory tests/016. * tests/016/arith.tl: New file. * tests/016/arith.expected: New file.