mes/tests/math.test

97 lines
2.9 KiB
Plaintext
Raw Normal View History

#! /bin/sh
# -*-scheme-*-
exec ${MES-bin/mes} --no-auto-compile -L ${0%/*} -L module -C module -e '(tests math)' -s "$0" "$@"
!#
;;; -*-scheme-*-
;;; GNU Mes --- Maxwell Equations of Software
;;; Copyright © 2016,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;;
;;; This file is part of GNU Mes.
;;;
;;; GNU Mes is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Mes 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 General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
build: Refactor mes tests. * build-aux/check-mes.sh: New file. * check.sh: Invoke it for Guile and Mes. * .gitignore: Ignore new guile logs. * mes/module/mes/boot-0.scm: Ignore some standard Guile options. * module/mes/test.scm: Make a module. * tests/base.test: Use it. Make a module, support invoking with Guile or Mes alike. * tests/boot.test: Likewise. * tests/catch.test: Likewise. * tests/closure.test: Likewise. * tests/cwv.test: Likewise. * tests/display.test: Likewise. * tests/fluids.test: Likewise. * tests/getopt-long.test: Likewise. * tests/guile.test: Likewise. * tests/let-syntax.test: Likewise. * tests/let.test: Likewise. * tests/match.test: Likewise. * tests/math.test: Likewise. * tests/module.test: Likewise. * tests/optargs.test: Likewise. * tests/peg.test: Likewise. * tests/pmatch.test: Likewise. * tests/psyntax.test: Likewise. * tests/quasiquote.test: Likewise. * tests/read.test: Likewise. * tests/scm.test: Likewise. * tests/srfi-13.test: Likewise. * tests/srfi-14.test: Likewise. * tests/srfi-16.test: Likewise. * tests/srfi-1.test: Likewise. * tests/srfi-43.test: Likewise. * tests/srfi-9.test: Likewise. * tests/syntax.test: Likewise. * tests/vector.test: Likewise. * tests/base.test-guile: Remove. * tests/boot.test-guile: Remove. * tests/catch.test-guile: Remove. * tests/closure.test-guile: Remove. * tests/cwv.test-guile: Remove. * tests/display.test-guile: Remove. * tests/fluids.test-guile: Remove. * tests/getopt-long.test-guile: Remove. * tests/guile.test-guile: Remove. * tests/let-syntax.test-guile: Remove. * tests/let.test-guile: Remove. * tests/match.test-guile: Remove. * tests/math.test-guile: Remove. * tests/module.test-guile: Remove. * tests/optargs.test-guile: Remove. * tests/peg.test-guile: Remove. * tests/pmatch.test-guile: Remove. * tests/psyntax.test-guile: Remove. * tests/quasiquote.test-guile: Remove. * tests/read.test-guile: Remove. * tests/scm.test-guile: Remove. * tests/srfi-13.test-guile: Remove. * tests/srfi-14.test-guile: Remove. * tests/srfi-16.test-guile: Remove. * tests/srfi-1.test-guile: Remove. * tests/srfi-43.test-guile: Remove. * tests/srfi-9.test-guile: Remove. * tests/syntax.test-guile: Remove. * tests/vector.test-guile: Remove.
2018-07-21 11:48:50 +00:00
(define-module (tests math)
#:use-module (mes mes-0)
#:use-module (mes test))
(mes-use-module (mes test))
(pass-if-equal "string->number" 42 (string->number "42"))
(pass-if-equal "string->number neg" -42 (string->number "-42"))
(pass-if-equal "string->number #hex" 170 (string->number "#xaa"))
(pass-if-not "string->number hex" (string->number "aa"))
(pass-if-equal "string->number hex" 170 (string->number "aa" 16))
(pass-if-equal "string->number float" 1 (inexact->exact (string->number "1.0")))
(pass-if-equal "+" 6 (+ 1 2 3))
(pass-if-equal "*" 27 (* 3 3 3))
(pass-if-equal "/" 3 (/ 9 3))
(pass-if-equal "remainder" 2 (remainder 11 3))
(pass-if-equal "modulo" 2 (modulo 11 3))
(pass-if-equal "expt" 8 (expt 2 3))
(pass-if-equal "logior" 7 (logior 0 1 2 4))
(pass-if-equal "logxor" -2 (logxor 1 -1))
(pass-if-equal "ash"
8 (ash 1 3))
(pass-if-equal "ash -1"
5 (ash 10 -1))
(pass-if-equal "=" 3 '3)
(pass-if "= 2" (not (= 3 '4)))
(pass-if "=" (=))
(pass-if "= 1" (= 0))
(pass-if "= 2" (= 0 0))
(pass-if "= 3" (= 0 0))
(pass-if-not "= 4" (= 0 1 0))
(pass-if "<" (<))
(pass-if "< 1" (< 0))
(pass-if "< 2" (< 0 1))
(pass-if-not "< 3" (< 1 0))
(pass-if "< 4" (< 0 1 2))
(pass-if-not "< 5" (< 0 2 1))
(pass-if "< INT-MIN" (< -2147483648))
(pass-if "< INT-MIN" (< -2147483648 0))
(pass-if "< INT-MAX" (< 2147483647))
(pass-if ">" (>))
(pass-if "> 1" (> 0))
(pass-if "> 2" (> 1 0))
(pass-if-not "> 3" (> 0 1))
(pass-if "> 4" (> 2 1 0))
(pass-if-not "> 5" (> 1 2 0))
(pass-if "> INT-MAX" (> 2147483647))
(pass-if "> INT-MAX 0" (> 2147483647 0))
(pass-if "> INT-MIN" (> -2147483648))
(pass-if ">=" (>= 3 2 1))
(pass-if-not ">= 2" (>= 1 2 3))
(pass-if-not "<=" (<= 3 2 1))
(pass-if "<= 2" (<= 1 2 3))
(pass-if-equal "max" 0 (max 0))
(pass-if-equal "max 1" 1 (max 0 1))
(pass-if-equal "max 2" 2 (max 1 0 2))
(pass-if-equal "min" 0 (min 0))
(pass-if-equal "min 1" 0 (min 0 1))
(pass-if-equal "min 2" 0 (min 1 0 2))
(pass-if-equal "#x-10" -16 #x-10)
(result 'report)