]> code.delx.au - gnu-emacs-elpa/blob - packages/test-simple/example/gcd.el
Merge commit '0cda39255827f283e7578cd469ae42daad9556a2' from js2-mode
[gnu-emacs-elpa] / packages / test-simple / example / gcd.el
1 ;;; test-simple.el --- Simple Unit Test Framework for Emacs Lisp
2 ;; Copyright (C) 2015 Free Software Foundation, Inc
3
4 ;; Author: Rocky Bernstein <rocky@gnu.org>
5 ;; URL: http://github.com/rocky/emacs-test-simple
6 ;; Keywords: unit-test
7 ;; Version: 1.0
8
9 ;; This program is free software: you can redistribute it and/or
10 ;; modify it under the terms of the GNU General Public License as
11 ;; published by the Free Software Foundation, either version 3 of the
12 ;; License, or (at your option) any later version.
13
14 ;; This program is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;; General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see
21 ;; <http://www.gnu.org/licenses/>.
22 (defun gcd(a b)
23 "Greatest Common Divisor of A and B"
24 ;; Make a < b
25 (if (> a b)
26 (let ((c a))
27 (setq a b)
28 (setq b c)))
29 (cond
30 ((< a 0) nil)
31 ((or (= 0 (- b a)) (= a 1)) a)
32 (t (gcd (- b a) a))
33 )
34 )