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

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

3 | ;;;; Created: Mon Sep 8 21:47:22 2003 |
---|

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

5 | |
---|

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

7 | |
---|

8 | (compile-and-load "numbers-aux.lsp") |
---|

9 | |
---|

10 | ;;; Error tests |
---|

11 | |
---|

12 | (deftest logandc1.error.1 |
---|

13 | (check-type-error #'(lambda (x) (logandc1 x 0)) #'integerp) |
---|

14 | nil) |
---|

15 | |
---|

16 | (deftest logandc1.error.2 |
---|

17 | (check-type-error #'(lambda (x) (logandc1 0 x)) #'integerp) |
---|

18 | nil) |
---|

19 | |
---|

20 | (deftest logandc1.error.3 |
---|

21 | (signals-error (logandc1) program-error) |
---|

22 | t) |
---|

23 | |
---|

24 | (deftest logandc1.error.4 |
---|

25 | (signals-error (logandc1 0) program-error) |
---|

26 | t) |
---|

27 | |
---|

28 | (deftest logandc1.error.5 |
---|

29 | (signals-error (logandc1 1 2 3) program-error) |
---|

30 | t) |
---|

31 | |
---|

32 | ;;; Non-error tests |
---|

33 | |
---|

34 | (deftest logandc1.1 |
---|

35 | (logandc1 0 0) |
---|

36 | 0) |
---|

37 | |
---|

38 | (deftest logandc1.2 |
---|

39 | (logandc1 0 -1) |
---|

40 | -1) |
---|

41 | |
---|

42 | (deftest logandc1.3 |
---|

43 | (logandc1 0 123) |
---|

44 | 123) |
---|

45 | |
---|

46 | (deftest logandc1.4 |
---|

47 | (loop for x in *integers* |
---|

48 | always (and (eql x (logandc1 0 x)) |
---|

49 | (eql 0 (logandc1 x x)) |
---|

50 | (eql x (logandc1 (lognot x) x)) |
---|

51 | (eql (lognot x) (logandc1 x (lognot x))))) |
---|

52 | t) |
---|

53 | |
---|

54 | (deftest logandc1.5 |
---|

55 | (loop for x = (random-fixnum) |
---|

56 | for xc = (lognot x) |
---|

57 | repeat 1000 |
---|

58 | unless (eql x (logandc1 xc x)) |
---|

59 | collect x) |
---|

60 | nil) |
---|

61 | |
---|

62 | (deftest logandc1.6 |
---|

63 | (loop for x = (random-from-interval (ash 1 (random 200))) |
---|

64 | for y = (random-from-interval (ash 1 (random 200))) |
---|

65 | for z = (logandc1 x y) |
---|

66 | repeat 1000 |
---|

67 | unless (and (if (and (>= x 0) (< y 0)) |
---|

68 | (< z 0) |
---|

69 | (>= z 0)) |
---|

70 | (loop for i from 1 to 210 |
---|

71 | always (if (and (not (logbitp i x)) |
---|

72 | (logbitp i y)) |
---|

73 | (logbitp i z) |
---|

74 | (not (logbitp i z))))) |
---|

75 | collect (list x y z)) |
---|

76 | nil) |
---|

77 | |
---|

78 | (deftest logandc1.order.1 |
---|

79 | (let ((i 0) a b) |
---|

80 | (values |
---|

81 | (logandc1 (progn (setf a (incf i)) 0) |
---|

82 | (progn (setf b (incf i)) -1)) |
---|

83 | i a b)) |
---|

84 | -1 2 1 2) |
---|