2020-01-20 14:40:58 +03:00
|
|
|
// Copyright 2020 The Grin Developers
|
2018-06-20 22:18:52 +03:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2019-11-26 23:21:49 +03:00
|
|
|
mod common;
|
2019-05-14 19:17:38 +03:00
|
|
|
|
2019-11-26 23:21:49 +03:00
|
|
|
use self::core::core::pmmr::{VecBackend, PMMR};
|
|
|
|
use crate::common::TestElem;
|
2018-12-08 02:59:40 +03:00
|
|
|
use grin_core as core;
|
2018-06-20 22:18:52 +03:00
|
|
|
|
2019-11-26 23:21:49 +03:00
|
|
|
#[test]
|
|
|
|
fn leaf_pos_and_idx_iter_test() {
|
|
|
|
let elems = [
|
|
|
|
TestElem([0, 0, 0, 1]),
|
|
|
|
TestElem([0, 0, 0, 2]),
|
|
|
|
TestElem([0, 0, 0, 3]),
|
|
|
|
TestElem([0, 0, 0, 4]),
|
|
|
|
TestElem([0, 0, 0, 5]),
|
|
|
|
];
|
|
|
|
let mut backend = VecBackend::new();
|
|
|
|
let mut pmmr = PMMR::new(&mut backend);
|
|
|
|
for x in &elems {
|
|
|
|
pmmr.push(x).unwrap();
|
2018-06-20 22:18:52 +03:00
|
|
|
}
|
2019-11-26 23:21:49 +03:00
|
|
|
assert_eq!(
|
|
|
|
vec![0, 1, 2, 3, 4],
|
|
|
|
pmmr.leaf_idx_iter(0).collect::<Vec<_>>()
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
vec![1, 2, 4, 5, 8],
|
|
|
|
pmmr.leaf_pos_iter().collect::<Vec<_>>()
|
|
|
|
);
|
2018-06-20 22:18:52 +03:00
|
|
|
}
|
|
|
|
|
2019-11-26 23:21:49 +03:00
|
|
|
#[test]
|
|
|
|
fn leaf_pos_and_idx_iter_hash_only_test() {
|
|
|
|
let elems = [
|
|
|
|
TestElem([0, 0, 0, 1]),
|
|
|
|
TestElem([0, 0, 0, 2]),
|
|
|
|
TestElem([0, 0, 0, 3]),
|
|
|
|
TestElem([0, 0, 0, 4]),
|
|
|
|
TestElem([0, 0, 0, 5]),
|
|
|
|
];
|
|
|
|
let mut backend = VecBackend::new_hash_only();
|
|
|
|
let mut pmmr = PMMR::new(&mut backend);
|
|
|
|
for x in &elems {
|
|
|
|
pmmr.push(x).unwrap();
|
2018-06-20 22:18:52 +03:00
|
|
|
}
|
2019-11-26 23:21:49 +03:00
|
|
|
assert_eq!(
|
|
|
|
vec![0, 1, 2, 3, 4],
|
|
|
|
pmmr.leaf_idx_iter(0).collect::<Vec<_>>()
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
vec![1, 2, 4, 5, 8],
|
|
|
|
pmmr.leaf_pos_iter().collect::<Vec<_>>()
|
|
|
|
);
|
2018-06-20 22:18:52 +03:00
|
|
|
}
|