Mercurial > public > mercurial-scm > hg
comparison rust/hg-core/src/testing.rs @ 41241:168041fa6d5f
rust: factorized testing Graphs
it will useful to use these outside of `ancestors`, too.
Differential Revision: https://phab.mercurial-scm.org/D5579
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Mon, 14 Jan 2019 20:42:25 +0100 |
parents | |
children | 4c5f6e95df84 |
comparison
equal
deleted
inserted
replaced
41240:ff333620a4cc | 41241:168041fa6d5f |
---|---|
1 // testing.rs | |
2 // | |
3 // Copyright 2018 Georges Racinet <georges.racinet@octobus.net> | |
4 // | |
5 // This software may be used and distributed according to the terms of the | |
6 // GNU General Public License version 2 or any later version. | |
7 | |
8 use crate::{Graph, GraphError, Revision, NULL_REVISION}; | |
9 | |
10 /// A stub `Graph`, same as the one from `test-ancestor.py` | |
11 /// | |
12 /// o 13 | |
13 /// | | |
14 /// | o 12 | |
15 /// | | | |
16 /// | | o 11 | |
17 /// | | |\ | |
18 /// | | | | o 10 | |
19 /// | | | | | | |
20 /// | o---+ | 9 | |
21 /// | | | | | | |
22 /// o | | | | 8 | |
23 /// / / / / | |
24 /// | | o | 7 | |
25 /// | | | | | |
26 /// o---+ | 6 | |
27 /// / / / | |
28 /// | | o 5 | |
29 /// | |/ | |
30 /// | o 4 | |
31 /// | | | |
32 /// o | 3 | |
33 /// | | | |
34 /// | o 2 | |
35 /// |/ | |
36 /// o 1 | |
37 /// | | |
38 /// o 0 | |
39 #[derive(Clone, Debug)] | |
40 pub struct SampleGraph; | |
41 | |
42 impl Graph for SampleGraph { | |
43 fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { | |
44 match rev { | |
45 0 => Ok([NULL_REVISION, NULL_REVISION]), | |
46 1 => Ok([0, NULL_REVISION]), | |
47 2 => Ok([1, NULL_REVISION]), | |
48 3 => Ok([1, NULL_REVISION]), | |
49 4 => Ok([2, NULL_REVISION]), | |
50 5 => Ok([4, NULL_REVISION]), | |
51 6 => Ok([4, NULL_REVISION]), | |
52 7 => Ok([4, NULL_REVISION]), | |
53 8 => Ok([NULL_REVISION, NULL_REVISION]), | |
54 9 => Ok([6, 7]), | |
55 10 => Ok([5, NULL_REVISION]), | |
56 11 => Ok([3, 7]), | |
57 12 => Ok([9, NULL_REVISION]), | |
58 13 => Ok([8, NULL_REVISION]), | |
59 r => Err(GraphError::ParentOutOfRange(r)), | |
60 } | |
61 } | |
62 } | |
63 | |
64 // A Graph represented by a vector whose indices are revisions | |
65 // and values are parents of the revisions | |
66 pub type VecGraph = Vec<[Revision; 2]>; | |
67 | |
68 impl Graph for VecGraph { | |
69 fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { | |
70 Ok(self[rev as usize]) | |
71 } | |
72 } |