-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_classes.pl
63 lines (53 loc) · 2.01 KB
/
test_classes.pl
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
use Test::More;
use strict;
BEGIN {
use_ok ( 'Transformation' );
use_ok ( 'ShapeCall' );
use_ok ( 'Rule' );
use_ok ( 'CFDGParser' );
}
require_ok ('Transformation');
require_ok ('ShapeCall');
require_ok ('Rule');
require_ok ('CFDGParser');
subtest "Transformation" => sub {
my $color_transform = Transformation->new({cmd => 'alpha', values => [0.5]});
is $color_transform->type, "color", "detects color type transformations";
my $geometric_transform = Transformation->new({cmd => 'size', values => [3]});
is $geometric_transform->type, "geometric", "detects geometric type transformations";
isa_ok $geometric_transform->{values}, 'ARRAY';
is_deeply $geometric_transform->{values}, [3], "preserve values";
isa_ok $color_transform->{values}, 'ARRAY';
is_deeply $color_transform->{values}, [0.5], "preserve values";
subtest "translation matrices" => sub {
my $translate_x_by_2 = Transformation->new( {cmd => 'x', values => [2]} );
my $matrix = $translate_x_by_2->matrix();
is_deeply $matrix, [
[1, 0, 2],
[0, 1, 0],
[0, 0, 1],
];
};
};
subtest "ShapeCall" => sub {
my $shape_call = ShapeCall->new( { call_name => 'CIRCLE', transformations => [ { cmd => 'x', values => [2] } ] } );
isa_ok($shape_call->{transformations}->[0], 'Transformation');
};
print "\n\n";
subtest "Rule" => sub {
my $text = <<TEXT
startshape Baba
rule Baba {
CIRCLE { x 2 y 3 }
SQUARE { s 7 }
}
TEXT
;
my $syntax_tree = CFDGParser::parse($text);
my $baba = Rule->new($syntax_tree->{rules}->[0]);
isa_ok($baba, 'Rule') || diag explain $baba;
is ($baba->{shape_name}, 'Baba', 'the rule has the name given');
isa_ok($baba->{calls}->[0], 'ShapeCall');
is_deeply $baba->{calls}->[0]->{transformations}->[0], { cmd => 'x', values => [2], type => 'geometric' }, "transformations are kept in the right places";
};
done_testing();