1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-18 18:40:22 +02:00

fix vector-move-right! and vector-move-left!

* libguile/vectors.c (scm_vector_move_left_x, scm_vector_move_right_x):
  Fix some bugs reported by Michael Lucy -- both variants would happily
  write beyond the end, and vector-move-right! didn't increment the
  counter before copying in the reverse direction.

* test-suite/tests/vectors.test ("vector-move-left!"):
  ("vector-move-right!"): Add tests.
This commit is contained in:
Andy Wingo 2010-08-04 21:48:00 +02:00
parent 5c8c9d05ae
commit 3de9a08715
2 changed files with 89 additions and 4 deletions

View file

@ -1,6 +1,6 @@
;;;; vectors.test --- test suite for Guile's vector functions -*- scheme -*-
;;;;
;;;; Copyright (C) 2003, 2006 Free Software Foundation, Inc.
;;;; Copyright (C) 2003, 2006, 2010 Free Software Foundation, Inc.
;;;;
;;;; 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
@ -41,3 +41,82 @@
(let ((b (make-shared-array #(1) (lambda (x) '(0)) 2)))
(equal? b (list->vector (vector->list b))))))
(with-test-prefix "vector-move-left!"
(pass-if-exception "before start" exception:out-of-range
(let ((a (vector 1 2 3 4 5 6 7 8 9))
(b (vector 10 20 30 40 50 60 70 80 90)))
(vector-move-left! a 3 5 b -1)))
(pass-if "beginning"
(let ((a (vector 1 2 3 4 5 6 7 8 9))
(b (vector 10 20 30 40 50 60 70 80 90)))
(vector-move-left! a 3 5 b 0)
(equal? b #(4 5 30 40 50 60 70 80 90))))
(pass-if "middle"
(let ((a (vector 1 2 3 4 5 6 7 8 9))
(b (vector 10 20 30 40 50 60 70 80 90)))
(vector-move-left! a 3 5 b 2)
(equal? b #(10 20 4 5 50 60 70 80 90))))
(pass-if "overlap -"
(let ((a (vector 1 2 3 4 5 6 7 8 9)))
(vector-move-left! a 3 5 a 2)
(equal? a #(1 2 4 5 5 6 7 8 9))))
(pass-if "overlap +"
(let ((a (vector 1 2 3 4 5 6 7 8 9)))
(vector-move-left! a 3 5 a 4)
(equal? a #(1 2 3 4 4 4 7 8 9))))
(pass-if "end"
(let ((a (vector 1 2 3 4 5 6 7 8 9))
(b (vector 10 20 30 40 50 60 70 80 90)))
(vector-move-left! a 3 5 b 7)
(equal? b #(10 20 30 40 50 60 70 4 5))))
(pass-if-exception "past end" exception:out-of-range
(let ((a (vector 1 2 3 4 5 6 7 8 9))
(b (vector 10 20 30 40 50 60 70 80 90)))
(vector-move-left! a 3 5 b 8))))
(with-test-prefix "vector-move-right!"
(pass-if-exception "before start" exception:out-of-range
(let ((a (vector 1 2 3 4 5 6 7 8 9))
(b (vector 10 20 30 40 50 60 70 80 90)))
(vector-move-right! a 3 5 b -1)))
(pass-if "beginning"
(let ((a (vector 1 2 3 4 5 6 7 8 9))
(b (vector 10 20 30 40 50 60 70 80 90)))
(vector-move-right! a 3 5 b 0)
(equal? b #(4 5 30 40 50 60 70 80 90))))
(pass-if "middle"
(let ((a (vector 1 2 3 4 5 6 7 8 9))
(b (vector 10 20 30 40 50 60 70 80 90)))
(vector-move-right! a 3 5 b 2)
(equal? b #(10 20 4 5 50 60 70 80 90))))
(pass-if "overlap -"
(let ((a (vector 1 2 3 4 5 6 7 8 9)))
(vector-move-right! a 3 5 a 2)
(equal? a #(1 2 5 5 5 6 7 8 9))))
(pass-if "overlap +"
(let ((a (vector 1 2 3 4 5 6 7 8 9)))
(vector-move-right! a 3 5 a 4)
(equal? a #(1 2 3 4 4 5 7 8 9))))
(pass-if "end"
(let ((a (vector 1 2 3 4 5 6 7 8 9))
(b (vector 10 20 30 40 50 60 70 80 90)))
(vector-move-right! a 3 5 b 7)
(equal? b #(10 20 30 40 50 60 70 4 5))))
(pass-if-exception "past end" exception:out-of-range
(let ((a (vector 1 2 3 4 5 6 7 8 9))
(b (vector 10 20 30 40 50 60 70 80 90)))
(vector-move-right! a 3 5 b 8))))