4 use Test::More 'no_plan';
14 use_ok( 'Text::Tradition::Analysis::Result' );
16 # Make a problem with a graph and a set of groupings
18 my $datafile = 't/data/florilegium_tei_ps.xml';
19 my $tradition = Text::Tradition->new( 'input' => 'TEI',
21 'file' => $datafile );
22 my $s = $tradition->add_stemma( 'dotfile' => 't/data/florilegium.dot' );
24 my $sets = [ [ qw/ D Q / ], [ qw/ F H / ], [ qw/ A B C P S T / ] ];
26 foreach my $set ( @$sets ) {
27 map { $extant->{$_} = 1 } @$set;
29 my $sitgraph = $s->editable( { extant => $extant } );
30 my $result = Text::Tradition::Analysis::Result->new(
33 is( ref( $result ), 'Text::Tradition::Analysis::Result', "Got a Result object" );
34 is( $result->graph, $sitgraph, "Got identical graph string back" );
35 is( $result->status, "new", "Calculation status of result set correctly" );
36 my @rsets = $result->sets;
37 is( $rsets[0], '(A B C P S T)', "First set is biggest set" );
38 is( $rsets[1], '(D Q)', "Second set is by alphabetical order" );
39 is( $rsets[2], '(F H)', "Second set is by alphabetical order" );
41 # Add some calculation values
42 $result->is_genealogical( 1 );
43 $result->record_grouping( [ qw/ 4 5 D Q / ] );
45 $result->record_grouping( [ qw/ 3 4 D H / ] );
46 ok( 0, "Recorded a grouping that does not match the input sets" );
47 } catch ( Text::Tradition::Error $e ) {
48 like( $e->message, qr/Failed to find witness set that is a subset of/,
49 "Correct error thrown on bad record_grouping attempt" );
51 $result->record_grouping( [ qw/ 3 F H / ] );
52 my $gp1 = $result->grouping(1);
53 is( $result->minimum_grouping_for( $rsets[1] ), $gp1,
54 "Found a minimum grouping for D Q" );
55 is( "$gp1", "(4 5 D Q)", "Retrieved minimum grouping is correct" );
56 is( $result->minimum_grouping_for( $rsets[0] ), $rsets[0],
57 "Default minimum grouping found for biggest group" );
58 $result->record_grouping( [ qw/ 1 α δ A B C P S T / ] );
63 foreach my $gp ( $result->groupings ) {
64 map { my $c = $classes{$_} || 'copy'; $result->set_class( $_, $c ) } @$gp;
66 foreach my $gp ( $result->groupings ) {
67 foreach my $wit ( @$gp ) {
68 my $expected = $classes{$wit} || 'copy';
69 is( $result->class( $wit ), $expected, "Got expected witness class for $wit" );
73 # Now write it out to JSON
74 my $struct = $result->TO_JSON;
75 my $newresult = Text::Tradition::Analysis::Result->new( $struct );
76 is( $result->object_key, $newresult->object_key,
77 "Object key stayed constant on export/import" );
78 my $problem = Text::Tradition::Analysis::Result->new( graph => $sitgraph, setlist => $sets );
79 is( $problem->object_key, $result->object_key,
80 "Object key stayed constant for newly created problem" );