You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
3.2 KiB
EmacsLisp
87 lines
3.2 KiB
EmacsLisp
;; test-splayt.el --- Unit tests for phpinspect.el -*- lexical-binding: t; -*-
|
|
|
|
;; Copyright (C) 2021 Free Software Foundation, Inc.
|
|
|
|
;; Author: Hugo Thunnissen <devel@hugot.nl>
|
|
|
|
;; This program 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.
|
|
|
|
;; This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;;
|
|
|
|
;;; Code:
|
|
|
|
(require 'phpinspect-splayt)
|
|
|
|
(ert-deftest phpinspect-splayt-node-rotate ()
|
|
(let* ((one (phpinspect-make-splayt-node 1 "one"))
|
|
(node (phpinspect-make-splayt-node
|
|
3 "three"
|
|
one
|
|
(phpinspect-make-splayt-node 4 "four"))))
|
|
(phpinspect-splayt-node-rotate-right node)
|
|
(should (equal (phpinspect-make-splayt-node
|
|
1 "one" nil
|
|
(phpinspect-make-splayt-node
|
|
3 "three" nil (phpinspect-make-splayt-node 4 "four")))
|
|
one))
|
|
|
|
(phpinspect-splayt-node-rotate-left node one)
|
|
|
|
(should (equal (phpinspect-make-splayt-node
|
|
1 "one" nil
|
|
(phpinspect-make-splayt-node
|
|
4 "four" (phpinspect-make-splayt-node 3 "three")))
|
|
one))))
|
|
|
|
(ert-deftest phpinspect-splayt ()
|
|
(let ((tree (phpinspect-make-splayt)))
|
|
(phpinspect-splayt-insert tree 9 "nine")
|
|
(phpinspect-splayt-insert tree 3 "three")
|
|
(phpinspect-splayt-insert tree 11 "eleven")
|
|
(phpinspect-splayt-insert tree 8 "eight")
|
|
(phpinspect-splayt-insert tree 12 "twelve")
|
|
(phpinspect-splayt-insert tree 4 "four")
|
|
(phpinspect-splayt-insert tree 1 "one")
|
|
|
|
|
|
(should (string= "eight" (phpinspect-splayt-find tree 8)))
|
|
(should (string= "one" (phpinspect-splayt-find tree 1)))
|
|
(should (string= "three" (phpinspect-splayt-find tree 3)))
|
|
(should (string= "nine" (phpinspect-splayt-find tree 9)))
|
|
(should (string= "four" (phpinspect-splayt-find tree 4)))
|
|
(should (string= "twelve" (phpinspect-splayt-find tree 12)))
|
|
(should (string= "eleven" (phpinspect-splayt-find tree 11)))))
|
|
|
|
(ert-deftest phpinspect-splayt-traverse ()
|
|
(let ((tree (phpinspect-make-splayt)))
|
|
(phpinspect-splayt-insert tree 9 "nine")
|
|
(phpinspect-splayt-insert tree 3 "three")
|
|
(phpinspect-splayt-insert tree 11 "eleven")
|
|
(phpinspect-splayt-insert tree 8 "eight")
|
|
(phpinspect-splayt-insert tree 12 "twelve")
|
|
(phpinspect-splayt-insert tree 4 "four")
|
|
(phpinspect-splayt-insert tree 1 "one")
|
|
|
|
(let ((expected (sort '("nine" "three" "eleven" "eight" "twelve" "four" "one") #'string-lessp))
|
|
(result))
|
|
|
|
(phpinspect-splayt-traverse (item tree)
|
|
(push item result))
|
|
|
|
(setq result (sort result #'string-lessp))
|
|
|
|
(should (equal expected result)))))
|