1 | ;-*- Mode: Lisp -*- |
---|

2 | ;;;; Author: Paul Dietz |
---|

3 | ;;;; Created: Wed Feb 11 19:16:35 2004 |
---|

4 | ;;;; Contains: Tests of TANH |
---|

5 | |
---|

6 | (in-package :cl-test) |
---|

7 | |
---|

8 | (deftest tanh.1 |
---|

9 | (let ((result (tanh 0))) |
---|

10 | (or (eqlt result 0) |
---|

11 | (eqlt result 0.0))) |
---|

12 | t) |
---|

13 | |
---|

14 | (deftest tanh.2 |
---|

15 | (loop for type in '(short-float single-float double-float long-float) |
---|

16 | for zero = (coerce 0 type) |
---|

17 | unless (equal (multiple-value-list (tanh zero)) |
---|

18 | (list zero)) |
---|

19 | collect type) |
---|

20 | nil) |
---|

21 | |
---|

22 | (deftest tanh.3 |
---|

23 | (loop for type in '(short-float single-float double-float long-float) |
---|

24 | for zero = (coerce 0 `(complex ,type)) |
---|

25 | unless (equal (multiple-value-list (tanh zero)) |
---|

26 | (list zero)) |
---|

27 | collect type) |
---|

28 | nil) |
---|

29 | |
---|

30 | (deftest tanh.4 |
---|

31 | (loop for den = (1+ (random 10000)) |
---|

32 | for num = (random (* 10 den)) |
---|

33 | for x = (/ num den) |
---|

34 | for rlist = (multiple-value-list (tanh x)) |
---|

35 | for y = (car rlist) |
---|

36 | repeat 1000 |
---|

37 | unless (and (null (cdr rlist)) |
---|

38 | (numberp y)) |
---|

39 | collect (list x rlist)) |
---|

40 | nil) |
---|

41 | |
---|

42 | (deftest tanh.5 |
---|

43 | (loop for type in '(short-float single-float double-float long-float) |
---|

44 | nconc |
---|

45 | (loop |
---|

46 | for x = (- (random (coerce 20 type)) 10) |
---|

47 | for rlist = (multiple-value-list (tanh x)) |
---|

48 | for y = (car rlist) |
---|

49 | repeat 1000 |
---|

50 | unless (and (null (cdr rlist)) |
---|

51 | (typep y type)) |
---|

52 | collect (list x rlist))) |
---|

53 | nil) |
---|

54 | |
---|

55 | (deftest tanh.6 |
---|

56 | (loop for type in '(short-float single-float double-float long-float) |
---|

57 | nconc |
---|

58 | (loop |
---|

59 | for x1 = (- (random (coerce 20 type)) 10) |
---|

60 | for x2 = (- (random (coerce 20 type)) 10) |
---|

61 | for rlist = (multiple-value-list (tanh (complex x1 x2))) |
---|

62 | for y = (car rlist) |
---|

63 | repeat 1000 |
---|

64 | unless (and (null (cdr rlist)) |
---|

65 | (typep y `(complex ,type))) |
---|

66 | collect (list x1 x2 rlist))) |
---|

67 | nil) |
---|

68 | |
---|

69 | ;;; FIXME |
---|

70 | ;;; Add accuracy tests here |
---|

71 | |
---|

72 | ;;; Error tests |
---|

73 | |
---|

74 | (deftest tanh.error.1 |
---|

75 | (signals-error (tanh) program-error) |
---|

76 | t) |
---|

77 | |
---|

78 | (deftest tanh.error.2 |
---|

79 | (signals-error (tanh 1.0 1.0) program-error) |
---|

80 | t) |
---|

81 | |
---|

82 | (deftest tanh.error.3 |
---|

83 | (check-type-error #'tanh #'numberp) |
---|

84 | nil) |
---|