mirror of
https://git.savannah.gnu.org/git/guix.git
synced 2026-04-06 21:20:33 +02:00
utils: Add string distance.
* guix/utils.scm (string-distance): New procedure.
(string-closest): New procedure.
* tests/utils.scm ("string-distance", "string-closest"): New tests.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
|
||||
;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
|
||||
;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
|
||||
;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
|
||||
;;;
|
||||
;;; This file is part of GNU Guix.
|
||||
;;;
|
||||
@@ -271,6 +272,23 @@ skip these tests."
|
||||
string-reverse)
|
||||
(call-with-input-file temp-file get-string-all)))
|
||||
|
||||
(test-equal "string-distance"
|
||||
'(0 1 1 5 5)
|
||||
(list
|
||||
(string-distance "hello" "hello")
|
||||
(string-distance "hello" "helo")
|
||||
(string-distance "helo" "hello")
|
||||
(string-distance "" "hello")
|
||||
(string-distance "hello" "")))
|
||||
|
||||
(test-equal "string-closest"
|
||||
'("hello" "hello" "helo" #f)
|
||||
(list
|
||||
(string-closest "hello" '("hello"))
|
||||
(string-closest "hello" '("helo" "hello" "halo"))
|
||||
(string-closest "hello" '("kikoo" "helo" "hihihi" "halo"))
|
||||
(string-closest "hello" '("aaaaa" "12345" "hellohello" "h"))))
|
||||
|
||||
(test-end)
|
||||
|
||||
(false-if-exception (delete-file temp-file))
|
||||
|
||||
Reference in New Issue
Block a user