summaryrefslogtreecommitdiff
path: root/morphology/examples/test_all_sorting_options.rs
blob: e5e796f1945f495d08b788c728978c8fc5297bfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Test program demonstrating all sorting options working together

use meta_affine::{Sequence, Value};
use meta_affine::sequence::{
    sort_sequences, SequenceOptions,
    PrecedenceOrder, SortingMethod, SortingDirection, LengthSorting
};

fn print_sequences(label: &str, sequences: &[Sequence]) {
    println!("\n{}:", label);
    for (i, seq) in sequences.iter().enumerate() {
        print!("  {}: len={} [", i, seq.length());
        for (j, v) in seq.values().iter().enumerate() {
            if j > 0 { print!(", "); }
            print!("({},{})", v.outer, v.inner);
        }
        println!("]");
    }
}

fn main() {
    // Create diverse sequences to showcase all options
    let sequences = vec![
        Sequence::new(vec![Value::new(1, 0), Value::new(0, 0)]),
        Sequence::new(vec![Value::new(0, 0)]),
        Sequence::new(vec![Value::new(0, 1), Value::new(1, 0), Value::new(0, 0)]),
        Sequence::new(vec![Value::new(1, 0), Value::new(0, 1), Value::new(0, 0)]),
        Sequence::new(vec![Value::new(0, 1), Value::new(0, 0)]),
    ];

    print_sequences("Original sequences", &sequences);

    // Example 1: All defaults
    let mut test1 = sequences.clone();
    sort_sequences(&mut test1, None);
    print_sequences("Defaults (SegregateLength, Forward, DepthFirst, IncreasingPositiveFirst)", &test1);

    // Example 2: InterpolateLength only
    let mut test2 = sequences.clone();
    let opts = SequenceOptions::new()
        .length_sorting(LengthSorting::InterpolateLength);
    sort_sequences(&mut test2, opts);
    print_sequences("InterpolateLength + defaults", &test2);

    // Example 3: BreadthFirst + Backward
    let mut test3 = sequences.clone();
    let opts = SequenceOptions::new()
        .sorting_method(SortingMethod::BreadthFirst)
        .sorting_direction(SortingDirection::Backward);
    sort_sequences(&mut test3, opts);
    print_sequences("BreadthFirst + Backward + SegregateLength", &test3);

    // Example 4: All custom options combined
    let mut test4 = sequences.clone();
    let opts = SequenceOptions::new()
        .length_sorting(LengthSorting::SegregateLength)
        .sorting_direction(SortingDirection::Backward)
        .sorting_method(SortingMethod::BreadthFirst)
        .outer_order(PrecedenceOrder::IncreasingNegativeFirst)
        .inner_order(PrecedenceOrder::IncreasingPositiveFirst);
    sort_sequences(&mut test4, opts);
    print_sequences("All custom: SegregateLength + Backward + BreadthFirst + custom precedence", &test4);

    println!("\n=== Complete Sorting Options ===");
    println!("LengthSorting: SegregateLength (default) | InterpolateLength");
    println!("SortingDirection: Forward (default) | Backward");
    println!("SortingMethod: DepthFirst (default) | BreadthFirst");
    println!("PrecedenceOrder: IncreasingPositiveFirst (default) | IncreasingNegativeFirst");
}