mirror of
https://github.com/vlang/v.git
synced 2025-09-12 08:57:09 -04:00
datatypes: make Direction
pub and fix and add tests for push_many
(#19983)
This commit is contained in:
parent
43709e9c58
commit
67fabddcaf
@ -1,6 +1,6 @@
|
|||||||
module datatypes
|
module datatypes
|
||||||
|
|
||||||
enum Direction {
|
pub enum Direction {
|
||||||
front
|
front
|
||||||
back
|
back
|
||||||
}
|
}
|
||||||
@ -88,7 +88,8 @@ pub fn (mut list DoublyLinkedList[T]) push_front(item T) {
|
|||||||
pub fn (mut list DoublyLinkedList[T]) push_many(elements []T, direction Direction) {
|
pub fn (mut list DoublyLinkedList[T]) push_many(elements []T, direction Direction) {
|
||||||
match direction {
|
match direction {
|
||||||
.front {
|
.front {
|
||||||
for v in elements {
|
for i := elements.len - 1; i >= 0; i-- {
|
||||||
|
v := elements[i]
|
||||||
list.push_front(v)
|
list.push_front(v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,3 +230,18 @@ fn test_back_iterator() {
|
|||||||
}
|
}
|
||||||
assert res == [3, 2, 1]
|
assert res == [3, 2, 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_push_many() {
|
||||||
|
mut list := DoublyLinkedList[int]{}
|
||||||
|
list.push_back(1)
|
||||||
|
list.push_back(2)
|
||||||
|
list.push_back(3)
|
||||||
|
list.push_many([4, 5, 6], .front)
|
||||||
|
list.push_many([7, 8, 9], .back)
|
||||||
|
|
||||||
|
mut res := []int{}
|
||||||
|
for x in list {
|
||||||
|
res << x
|
||||||
|
}
|
||||||
|
assert res == [4, 5, 6, 1, 2, 3, 7, 8, 9]
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user