4 use Test::More 'no_plan';
15 use_ok( 'Text::Tradition::Analysis::Result' );
17 # Make a problem with a graph and a set of groupings
19 my $datafile = 't/data/florilegium_tei_ps.xml';
20 my $tradition = Text::Tradition->new( 'input' => 'TEI',
22 'file' => $datafile );
23 my $s = $tradition->add_stemma( 'dotfile' => 't/data/florilegium.dot' );
25 my $sets = [ [ qw/ D Q / ], [ qw/ F H / ], [ qw/ A B C P S T / ] ];
27 foreach my $set ( @$sets ) {
28 map { $extant->{$_} = 1 } @$set;
30 my $sitgraph = $s->editable( { extant => $extant } );
31 my $result = Text::Tradition::Analysis::Result->new(
34 is( ref( $result ), 'Text::Tradition::Analysis::Result', "Got a Result object" );
35 is( $result->graph, $sitgraph, "Got identical graph string back" );
36 is( $result->status, "new", "Calculation status of result set correctly" );
37 my @rsets = $result->sets;
38 is( $rsets[0], '(A B C P S T)', "First set is biggest set" );
39 is( $rsets[1], '(D Q)', "Second set is by alphabetical order" );
40 is( $rsets[2], '(F H)', "Second set is by alphabetical order" );
42 # Add some calculation values
43 $result->is_genealogical( 1 );
44 $result->record_grouping( [ qw/ 4 5 D Q / ] );
46 $result->record_grouping( [ qw/ 3 4 D H / ] );
47 ok( 0, "Recorded a grouping that does not match the input sets" );
48 } catch ( Text::Tradition::Error $e ) {
49 like( $e->message, qr/Failed to find witness set that is a subset of/,
50 "Correct error thrown on bad record_grouping attempt" );
52 # Test manually setting an out-of-range group
54 $result->_set_grouping( 3, Set::Scalar->new( qw/ X Y / ) );
55 ok( 0, "Set a grouping at an invalid index" );
56 } catch ( Text::Tradition::Error $e ) {
57 is( $e->message, 'Set / group index 3 out of range for set_grouping',
58 "Caught attempt to set grouping at invalid index" );
60 $result->record_grouping( [ qw/ 3 F H / ] );
61 my $gp1 = $result->grouping(1);
62 is( $result->minimum_grouping_for( $rsets[1] ), $gp1,
63 "Found a minimum grouping for D Q" );
64 is( "$gp1", "(4 5 D Q)", "Retrieved minimum grouping is correct" );
65 is( $result->minimum_grouping_for( $rsets[0] ), $rsets[0],
66 "Default minimum grouping found for biggest group" );
67 $result->record_grouping( [ qw/ 1 α δ A B C P S T / ] );
72 foreach my $gp ( $result->groupings ) {
73 map { my $c = $classes{$_} || 'copy'; $result->set_class( $_, $c ) } @$gp;
75 foreach my $gp ( $result->groupings ) {
76 foreach my $wit ( @$gp ) {
77 my $expected = $classes{$wit} || 'copy';
78 is( $result->class( $wit ), $expected, "Got expected witness class for $wit" );
82 # Now write it out to JSON
83 my $struct = $result->TO_JSON;
84 my $newresult = Text::Tradition::Analysis::Result->new( $struct );
85 is( $result->object_key, $newresult->object_key,
86 "Object key stayed constant on export/import" );
87 my $problem = Text::Tradition::Analysis::Result->new( graph => $sitgraph, setlist => $sets );
88 is( $problem->object_key, $result->object_key,
89 "Object key stayed constant for newly created problem" );