unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob c6ac2912b995de6934bb14d9473c082876d92254 3379 bytes (raw)
name: test/lisp/num-base-converters-tests.el 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
 
;;; num-base-converters-tests.el --- Test suite for num-base-converters. -*- lexical-binding: t -*-

;; Copyright (C) 2017 Free Software Foundation, Inc.

;; This file is part of GNU Emacs.

;; GNU Emacs 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 Emacs 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 Emacs.  If not, see <http://www.gnu.org/licenses/>.

;;; Code:
(require 'ert)
(require 'num-base-converters)


(ert-deftest nbc-test-converters ()
  ;; Input is case-insensitive.
  (dolist (x (list "a" "A"))
    (should (equal "10" (nbc-hex2dec x)))
    (should (equal "12" (nbc-hex2oct x)))
    (should (equal "1010" (nbc-hex2bin x))))
  ;;
  (should (equal "A" (nbc-dec2hex "10")))
  (should (equal "12" (nbc-dec2oct "10")))
  (should (equal "1010" (nbc-dec2bin "10")))
  ;;
  (should (equal "3F" (nbc-oct2hex "77")))
  (should (equal "63" (nbc-oct2dec "77")))
  (should (equal "111111" (nbc-oct2bin "77")))
  ;;
  (should (equal "A" (nbc-bin2hex "1010")))
  (should (equal "10" (nbc-bin2dec "1010")))
  (should (equal "12" (nbc-bin2oct "1010"))))

(ert-deftest nbc-test-nbc-number-base-converter ()
  ;; Bases `b' must be: 2 <= b <= 36:
  (should-error (nbc-number-base-converter "10" 37 10))
  (should-error (nbc-number-base-converter "10" 10 37))
  (should-error (nbc-number-base-converter "10" 10 1))
  (should-error (nbc-number-base-converter "10" 1 10))
  ;; Invalid input:
  (should-error (nbc-number-base-converter "1a" 8 10))
  (should-error (nbc-number-base-converter "az" 16 10))
  (should-error (nbc-number-base-converter "3" 2 10))
  (should-error (nbc-number-base-converter "z" 10 8))
  ;;
  (should (equal "8" (nbc-number-base-converter "10" 8 16)))
  (should (equal "10" (nbc-number-base-converter "8" 16 8)))
  (should (equal "12" (nbc-number-base-converter "10" 10 8)))
  (should (equal "10" (nbc-number-base-converter "12" 8 10)))
  (should (equal "1000" (nbc-number-base-converter "10" 8 2)))
  (should (equal "10" (nbc-number-base-converter "1000" 2 8)))
  ;;
  (should (equal "10" (nbc-number-base-converter "a" 16 10)))
  (should (equal "10" (nbc-number-base-converter "A" 16 10)))
  (should (equal "A" (nbc-number-base-converter "10" 10 16)))
  (should (equal "1010" (nbc-number-base-converter "a" 16 2)))
  (should (equal "1010" (nbc-number-base-converter "A" 16 2)))
  (should (equal "A" (nbc-number-base-converter "1010" 2 16)))
  ;;
  (should (equal "1010" (nbc-number-base-converter "10" 10 2)))
  (should (equal "10" (nbc-number-base-converter "1010" 2 10))))

(ert-deftest nbc-test-nbc-number-base-converter ()
  (let (nbc-define-aliases)
    (nbc--create-converters)
    (should (fboundp 'nbc-oct2dec))
    (should-not (fboundp 'oct2dec))
    (setq nbc-define-aliases t)
    ;; It should create the aliases, i.e. `oct2dec' etc.
    (nbc--create-converters)
    (should (fboundp 'oct2dec))))


(provide 'num-base-converters-tests)

;; num-base-converters-tests.el ends here

debug log:

solving c6ac2912b9 ...
found c6ac2912b9 in https://yhetil.org/emacs-devel/alpine.DEB.2.20.1708150225001.30658@calancha-pc/

applying [1/1] https://yhetil.org/emacs-devel/alpine.DEB.2.20.1708150225001.30658@calancha-pc/
diff --git a/test/lisp/num-base-converters-tests.el b/test/lisp/num-base-converters-tests.el
new file mode 100644
index 0000000000..c6ac2912b9

Checking patch test/lisp/num-base-converters-tests.el...
Applied patch test/lisp/num-base-converters-tests.el cleanly.

index at:
100644 c6ac2912b995de6934bb14d9473c082876d92254	test/lisp/num-base-converters-tests.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).