| 1 | package Cheater::Eval; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use 5.010000; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | #use Smart::Comments; | ||||||||||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use Date::Calc qw( Localtime ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Data::Random qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | rand_chars | ||||||||||||||||||||||||||||||||||||||||||
| 10 | rand_date rand_time rand_datetime | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use Parse::RandGen::Regexp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use Scalar::Util qw( looks_like_number ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 7 | ▶ | use Cheater::Util qw( quote_sql_str ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | sub get_today (); | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 7 | our $NowDate = 'now'; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 7 | our $NowDatetime = 'now'; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | has 'ast' => (is => 'ro', isa => 'Cheater::AST'); | |||||||||||||||||||||||||||||||||||||||||
| 22 | 7 | has '_samples' => (is => 'ro', isa => 'HashRef'); | |||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | has '_cols_visited' => (is => 'ro', isa => 'HashRef'); | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | sub pick_elems ($$$); | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | sub gen_txt_col ($$$$$$$); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | sub gen_num_col ($$$$$$); | ||||||||||||||||||||||||||||||||||||||||||
| 29 | sub gen_domain_val ($); | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | sub gen_int ($); | ||||||||||||||||||||||||||||||||||||||||||
| 32 | sub gen_real ($); | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 30 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 30 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 30 | $self->{_samples} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 30 | $self->{_cols_visited} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 30 | ▶ | sub go { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
go: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 30 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 30 | my $ast = $self->ast; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 30 | my $goals = $ast->goals; | |||||||||||||||||||||||||||||||||||||||||
| 44 | ### $goals | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 30 | my %computed; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 30 | for my $goal (sort keys %$goals) { | |||||||||||||||||||||||||||||||||||||||||
| 48 | 32 | $computed{$goal} = $self->gen_goal($goal); | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 25 | return \%computed; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub rand_regex ($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rand_regex: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $regex = shift; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | Parse::RandGen::Regexp->new(qr/$regex/)->pick(); | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 32 | ▶ | sub gen_goal { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_goal: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 32 | my ($self, $table) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 32 | my $ast = $self->ast; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 32 | my $goals = $ast->goals; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 32 | my $tables = $ast->tables; | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 32 | my $rows = $goals->{$table}; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 32 | my @cols_data; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 32 | ▶ | my $tb_spec = $tables->{$table} or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | die "Table $table not defined.\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 32 | for my $col (@$tb_spec) { | |||||||||||||||||||||||||||||||||||||||||
| 73 | #say "col: ", $col->[0]; | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 35 | my $name = $col->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 35 | push @cols_data, $self->gen_column($table, $name); | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 27 | return \@cols_data; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 36 | ▶ | sub gen_column { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_column: called CC=10 SCAR=25.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 36 | my ($self, $table, $col_name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | #warn "gen column $table.$col_name...\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 36 | my $samples = $self->_samples; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 36 | my $cols_visited = $self->_cols_visited; | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 36 | my $ast = $self->ast; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 36 | my $deps = $ast->deps; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 36 | my $goals = $ast->goals; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 36 | my $cols = $ast->cols; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 36 | my $types = $ast->types; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 36 | my $col_clones = $ast->col_clones; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 36 | my $qcol = "$table.$col_name"; | |||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 36 | ▶ | if (defined $samples->{$qcol}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | return $samples->{$qcol}; | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 35 | ▶ | if (my $dep = $cols_visited->{$qcol}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | die "ERROR: Found circular column references: $qcol references $dep but $dep somehow depends on $qcol.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 35 | my $rows = $goals->{$table}; | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 35 | ▶ | my $spec = $cols->{$qcol} or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | die "Column spec not found for $qcol\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | my $type = $spec->{type} or | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 35 | ▶ | die "Type not found for $qcol"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 35 | my $attrs = $spec->{attrs}; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 35 | my $domain = $spec->{domain}; | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 35 | ▶ | if (my $dep = $deps->{$qcol}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | #warn "setting $qcol rely on $dep...\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | $cols_visited->{$qcol} = $dep; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | my ($dep_table, $dep_col_name) = split /\./, $dep, 2; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | ▶ | if (! $cols->{$dep}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | die "ERROR: Column $qcol references non-existent column $dep.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | my $refs_data = $self->gen_column($dep_table, $dep_col_name); | |||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | my $data; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | ▶ | if ($col_clones->{$qcol} && $col_clones->{$qcol} eq $dep) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$col_clones->{$qcol} and $col_clones->{$qcol} eq $dep
MC/DC0%0/2
$col_clones->{$qcol} and $col_clones->{$qcol} eq $dep
$col_clones->{$qcol}
$col_clones->{$qcol} eq $dep
Truth table33%1/3
A and B
A= $col_clones->{$qcol}B= $col_clones->{$qcol} eq $dep
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | $data = $refs_data; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $data = pick_elems($refs_data, $attrs, $rows); | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | $samples->{$qcol} = $data; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | return $data; | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 34 | given ($type) { | |||||||||||||||||||||||||||||||||||||||||
| 139 | 34 | when ('text') { | |||||||||||||||||||||||||||||||||||||||||
| 140 | my $data = gen_txt_col($table, $col_name, $domain, $attrs, $rows, | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub { join '', rand_chars( set => 'all', min => 5, max => 16 ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 143 | undef, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $samples->{$qcol} = $data; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | return $data; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 34 | when ('integer') { | |||||||||||||||||||||||||||||||||||||||||
| 149 | 13 | my $data = gen_num_col($table, $col_name, $domain, $attrs, $rows, 'i'); | |||||||||||||||||||||||||||||||||||||||||
| 150 | 10 | $samples->{$qcol} = $data; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 10 | return $data; | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 21 | when ('serial') { | |||||||||||||||||||||||||||||||||||||||||
| 154 | 3 | push @$attrs, 'serial'; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 3 | my $data = gen_num_col($table, $col_name, $domain, $attrs, $rows, 'i'); | |||||||||||||||||||||||||||||||||||||||||
| 156 | 3 | $samples->{$qcol} = $data; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 3 | return $data; | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 18 | when ('real') { | |||||||||||||||||||||||||||||||||||||||||
| 160 | #warn "HERE"; | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | my $data = gen_num_col($table, $col_name, $domain, $attrs, $rows, 'r'); | |||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $samples->{$qcol} = $data; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | return $data; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 18 | when ('date') { | |||||||||||||||||||||||||||||||||||||||||
| 166 | my $data = gen_txt_col($table, $col_name, $domain, $attrs, $rows, | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 29 | ▶ | sub { rand_date(min => $NowDate) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 10 | qr/^\d{4}-\d{2}-\d{2}$/, | |||||||||||||||||||||||||||||||||||||||||
| 169 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 10 | $samples->{$qcol} = $data; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 10 | return $data; | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 8 | when ('time') { | |||||||||||||||||||||||||||||||||||||||||
| 174 | 2 | my $data = gen_txt_col($table, $col_name, $domain, $attrs, $rows, | |||||||||||||||||||||||||||||||||||||||||
| 175 | \&rand_time, | ||||||||||||||||||||||||||||||||||||||||||
| 176 | qr/^\d{2}:\d{2}:\d{2}$/, | ||||||||||||||||||||||||||||||||||||||||||
| 177 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $samples->{$qcol} = $data; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | return $data; | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 6 | when ('datetime') { | |||||||||||||||||||||||||||||||||||||||||
| 182 | my $data = gen_txt_col($table, $col_name, $domain, $attrs, $rows, | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 19 | ▶ | sub { rand_datetime(min => $NowDatetime); }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 6 | qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/, | |||||||||||||||||||||||||||||||||||||||||
| 185 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 6 | $samples->{$qcol} = $data; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 6 | return $data; | |||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | default { | |||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | die "Type $type not defined.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 191 | # TODO | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my $type_def = $types->{$type}; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | if (! $type_def) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | die "Type $type not defined for table $table column $col_name.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my $data = gen_custom_type_col($table, $col_name, $attrs, $type_def, $domain, $rows); | |||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | $samples->{$qcol} = $data; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | return $data; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | # impossible to reach here... | ||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | sub pick_elems ($$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick_elems: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | my ($set, $attrs, $m) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | my $not_null; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | for (@$attrs) { | |||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | if ($_ eq 'not null') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | $not_null = 1; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | my $n = @$set; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | my @res; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | for (1..$m) { | |||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | if (! $not_null) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | if ((int rand 10) == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | push @res, undef; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | my $i = int rand $n; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | push @res, $set->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | return \@res; | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 36 | ▶ | sub gen_int ($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_int: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 36 | my $unsigned = shift; | |||||||||||||||||||||||||||||||||||||||||
| 236 | 36 | ▶ | return $unsigned ? (int rand 1_000_000) : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | (int rand 1_000_000) - 500_000; | ||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | sub gen_real ($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_real: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | my $unsigned = shift; | |||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | return $unsigned ? (rand 1_000_000) : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | (rand 1_000_000) - 500_000; | ||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 16 | ▶ | sub gen_num_col ($$$$$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_num_col: called CC=42 SCAR=44.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 16 | my ($table, $col_name, $domain, $attrs, $n, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 16 | my ($unique, $asc, $desc, $not_null, $unsigned, $empty_domain); | |||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 16 | ▶ | if ($domain && @$domain == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$domain and @$domain == 0
MC/DC0%0/2
$domain and @$domain == 0
$domain
@$domain == 0
Truth table66%2/3
A and B
A= $domainB= @$domain == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | $empty_domain = 1; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | ### $domain | ||||||||||||||||||||||||||||||||||||||||||
| 256 | ### $attrs | ||||||||||||||||||||||||||||||||||||||||||
| 257 | #warn "type: $type\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 16 | for (@$attrs) { | |||||||||||||||||||||||||||||||||||||||||
| 260 | 18 | ▶ | if ($_ eq 'serial') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 3 | $unique = 1; | |||||||||||||||||||||||||||||||||||||||||
| 262 | 3 | $asc = 1; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 3 | $not_null = 1; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 3 | $unsigned = 1; | |||||||||||||||||||||||||||||||||||||||||
| 265 | } elsif ($_ eq 'not null') { | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 10 | $not_null = 1; | |||||||||||||||||||||||||||||||||||||||||
| 267 | } elsif ($_ eq 'unique') { | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 3 | $unique = 1; | |||||||||||||||||||||||||||||||||||||||||
| 269 | } elsif ($_ eq 'unsigned') { | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | $unsigned = 1; | |||||||||||||||||||||||||||||||||||||||||
| 271 | } elsif ($_ eq 'asc') { | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | $asc = 1; | |||||||||||||||||||||||||||||||||||||||||
| 273 | } elsif ($_ eq 'desc') { | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 1 | $desc = 1; | |||||||||||||||||||||||||||||||||||||||||
| 275 | } elsif (ref $_) { | ||||||||||||||||||||||||||||||||||||||||||
| 276 | # do nothing | ||||||||||||||||||||||||||||||||||||||||||
| 277 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | die "Unknown attribute: $_\n"; | |||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 16 | ▶ | if ($asc && $desc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$asc and $desc
MC/DC0%0/2
$asc and $desc
$asc
$desc
Truth table66%2/3
A and B
A= $ascB= $desc
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | die "table $table, column $col_name: asc hates desc.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 16 | ▶ | if ($empty_domain && $not_null) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$empty_domain and $not_null
MC/DC0%0/2
$empty_domain and $not_null
$empty_domain
$not_null
Truth table33%1/3
A and B
A= $empty_domainB= $not_null
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | die "table $table, column $col_name: empty domain {} hates \"not null\".\n"; | |||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 16 | my @nums; | |||||||||||||||||||||||||||||||||||||||||
| 291 | my %hist; | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 16 | for (1..$n) { | |||||||||||||||||||||||||||||||||||||||||
| 293 | 65 | ▶ | if ($unique) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 24 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 295 | 24 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 296 | 24 | ▶ | if (++$i > 10_000) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | die "ERROR: Too many attempts failed for table $table, column $col_name.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 24 | my $gen_null; | |||||||||||||||||||||||||||||||||||||||||
| 301 | 24 | ▶ | if (!$not_null) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $gen_null = (int rand 10) == 0; | |||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | if ($gen_null) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | push @nums, undef; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 24 | ▶ | if (! $gen_null) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 24 | my $num; | |||||||||||||||||||||||||||||||||||||||||
| 311 | 24 | ▶ | if (defined $domain) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 9 | $num = gen_domain_val($domain); | |||||||||||||||||||||||||||||||||||||||||
| 313 | 8 | ▶ | if (!defined $num) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | if ($not_null) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | die "table $table, column $col_name: not null hates {} domain.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | push @nums, $num; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 8 | ▶ | if (! looks_like_number($num)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | die "table $table, column $col_name: \"$num\" does not look like a number.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 8 | ▶ | if ($type eq 'i') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 8 | $num = int $num; | |||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 330 | #warn "Type: $type"; | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 15 | ▶ | $num = $type eq 'i' ? gen_int($unsigned) : gen_real($unsigned); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 23 | ▶ | if (! $hist{$num}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 23 | push @nums, $num; | |||||||||||||||||||||||||||||||||||||||||
| 336 | 23 | $hist{$num} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 337 | 23 | last; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 23 | next; | |||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 41 | my $gen_null; | |||||||||||||||||||||||||||||||||||||||||
| 345 | 41 | ▶ | if (!$not_null) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 9 | $gen_null = (int rand 10) == 0; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 9 | ▶ | if ($gen_null) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 1 | push @nums, undef; | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 41 | ▶ | if (! $gen_null) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 40 | my $num; | |||||||||||||||||||||||||||||||||||||||||
| 354 | 40 | ▶ | if (defined $domain) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 19 | $num = gen_domain_val($domain); | |||||||||||||||||||||||||||||||||||||||||
| 356 | 18 | ▶ | if (defined $num) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | 18 | ▶ | if (! looks_like_number($num)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 1 | die "table $table, column $col_name: \"$num\" does not look like a number.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | 17 | ▶ | $num = int $num if $type eq 'i'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||
| 364 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 21 | ▶ | $num = $type eq 'i' ? gen_int($unsigned) : gen_real($unsigned); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | 38 | push @nums, $num; | |||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 13 | ▶ | if ($asc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | @nums = sort { | ||||||||||||||||||||||||||||||||||||||||||
| 374 | 4 | ▶ | my $aa = $a // 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$a // 0
MC/DC0%0/1
$a // 0
$a
Truth table50%1/2
A
A= $a
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 26 | ▶ | my $bb = $b // 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$b // 0
MC/DC0%0/1
$b // 0
$b
Truth table50%1/2
A
A= $b
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 26 | $aa <=> $bb | |||||||||||||||||||||||||||||||||||||||||
| 377 | } @nums; | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | } elsif ($desc) { | ||||||||||||||||||||||||||||||||||||||||||
| 380 | @nums = sort { | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 1 | ▶ | my $aa = $a // 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$a // 0
MC/DC0%0/1
$a // 0
$a
Truth table50%1/2
A
A= $a
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 8 | ▶ | my $bb = $b // 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$b // 0
MC/DC0%0/1
$b // 0
$b
Truth table50%1/2
A
A= $b
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 8 | $bb <=> $aa | |||||||||||||||||||||||||||||||||||||||||
| 384 | } @nums; | ||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 13 | return \@nums; | |||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | 18 | ▶ | sub gen_txt_col ($$$$$$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_txt_col: called CC=37 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | 18 | my ($table, $col_name, $domain, $attrs, $n, $gen, $check) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 18 | my ($unique, $asc, $desc, $not_null, $empty_domain); | |||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 18 | ▶ | if ($domain && @$domain == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$domain and @$domain == 0
MC/DC0%0/2
$domain and @$domain == 0
$domain
@$domain == 0
Truth table66%2/3
A and B
A= $domainB= @$domain == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | $empty_domain = 1; | |||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 18 | for (@$attrs) { | |||||||||||||||||||||||||||||||||||||||||
| 400 | 13 | ▶ | if ($_ eq 'not null') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 8 | $not_null = 1; | |||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | 13 | ▶ | if ($_ eq 'unique') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | $unique = 1; | |||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 13 | ▶ | if ($_ eq 'asc') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | 2 | $asc = 1; | |||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | 13 | ▶ | if ($_ eq 'desc') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | 2 | $desc = 1; | |||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | 18 | ▶ | if ($asc && $desc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$asc and $desc
MC/DC0%0/2
$asc and $desc
$asc
$desc
Truth table66%2/3
A and B
A= $ascB= $desc
| |||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | die "table $table, column $col_name: asc hates desc.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 18 | ▶ | if ($empty_domain && $not_null) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$empty_domain and $not_null
MC/DC0%0/2
$empty_domain and $not_null
$empty_domain
$not_null
Truth table33%1/3
A and B
A= $empty_domainB= $not_null
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | die "table $table, column $col_name: empty domain {} hates \"not null\".\n"; | |||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | 18 | my @txts; | |||||||||||||||||||||||||||||||||||||||||
| 426 | my %hist; | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 18 | for (1..$n) { | |||||||||||||||||||||||||||||||||||||||||
| 428 | 76 | ▶ | if ($unique) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | if (++$i > 10_000) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | die "ERROR: Too many attempts failed for table $table, column $col_name.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | #warn "unique looping"; | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | my $gen_null; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | if (! $not_null) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | $gen_null = (int rand 10) == 0; | |||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | if ($gen_null) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | push @txts, undef; | |||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | if (! $gen_null) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | my $txt; | |||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | if (defined $domain) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | $txt = gen_domain_val($domain); | |||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | if (!defined $txt) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | if ($not_null) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | die "table $table, column $col_name: not null hates {} domain.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | push @txts, $txt; | |||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | if (defined $check and $txt !~ $check) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $check and not $txt =~ /$check/
MC/DC0%0/2
defined $check and not $txt =~ /$check/
defined $check
not $txt =~ /$check/
Truth table0%0/3
A and not(B)
A= defined $checkB= not $txt =~ /$check/
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | die "table $table, column $col_name: Bad domain value \"$txt\" for the column type.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||
| 458 | #warn "txt: $txt"; | ||||||||||||||||||||||||||||||||||||||||||
| 459 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | $txt = $gen->(); | |||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | ▶ | if (! $hist{$txt}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | push @txts, $txt; | |||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | $hist{$txt} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | 76 | my $gen_null; | |||||||||||||||||||||||||||||||||||||||||
| 474 | 76 | ▶ | if (!$not_null) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 36 | $gen_null = (int rand 10) == 0; | |||||||||||||||||||||||||||||||||||||||||
| 476 | 36 | ▶ | if ($gen_null) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | 6 | push @txts, undef; | |||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | 76 | ▶ | if (! $gen_null) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | 70 | my $txt; | |||||||||||||||||||||||||||||||||||||||||
| 483 | 70 | ▶ | if (defined $domain) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 22 | $txt = gen_domain_val($domain); | |||||||||||||||||||||||||||||||||||||||||
| 485 | 21 | ▶ | if (defined $txt and defined $check and $txt !~ $check) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $txt and defined $check and not $txt =~ /$check/
defined $txt and defined $check
MC/DC33%1/3
defined $txt and defined $check and not $txt =~ /$check/
defined $txt
defined $check
not $txt =~ /$check/
Truth table50%2/4
A and B and not(C)
A= defined $txtB= defined $checkC= not $txt =~ /$check/
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | 1 | die "table $table, column $col_name: Bad domain value \"$txt\" for the column type.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||
| 488 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 489 | 48 | $txt = $gen->(); | |||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||
| 491 | 68 | push @txts, $txt; | |||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||
| 493 | } # for loop | ||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||
| 495 | 16 | ▶ | if ($asc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 496 | @txts = sort { | ||||||||||||||||||||||||||||||||||||||||||
| 497 | 2 | ▶ | my $aa = $a // 'NULL'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$a // "NULL"
MC/DC0%0/1
$a // "NULL"
$a
Truth table50%1/2
A
A= $a
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | 16 | ▶ | my $bb = $b // 'NULL'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$b // "NULL"
MC/DC0%0/1
$b // "NULL"
$b
Truth table50%1/2
A
A= $b
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | 16 | $aa cmp $bb | |||||||||||||||||||||||||||||||||||||||||
| 500 | } @txts; | ||||||||||||||||||||||||||||||||||||||||||
| 501 | } elsif ($desc) { | ||||||||||||||||||||||||||||||||||||||||||
| 502 | @txts = sort { | ||||||||||||||||||||||||||||||||||||||||||
| 503 | 2 | ▶ | my $aa = $a // 'NULL'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$a // "NULL"
MC/DC0%0/1
$a // "NULL"
$a
Truth table50%1/2
A
A= $a
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | 16 | ▶ | my $bb = $b // 'NULL'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$b // "NULL"
MC/DC0%0/1
$b // "NULL"
$b
Truth table50%1/2
A
A= $b
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | 16 | $bb cmp $aa | |||||||||||||||||||||||||||||||||||||||||
| 506 | } @txts; | ||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | 16 | return \@txts; | |||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | sub gen_custom_type_col ($$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_custom_type_col: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | 25 | ▶ | sub to_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 516 | 25 | my ($self, $computed) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | 25 | my $s = ''; | |||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | 25 | for my $table (sort keys %$computed) { | |||||||||||||||||||||||||||||||||||||||||
| 521 | 27 | $s .= "$table\n"; | |||||||||||||||||||||||||||||||||||||||||
| 522 | 27 | $s .= $self->stringify_table($table, $computed->{$table}); | |||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | 25 | return $s; | |||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | 27 | ▶ | sub stringify_table { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify_table: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 529 | 27 | my ($self, $table, $cols) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | 27 | my $ast = $self->ast; | |||||||||||||||||||||||||||||||||||||||||
| 532 | 27 | my $tables = $ast->tables; | |||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | ### $ast | ||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | 27 | ▶ | my $tb_spec = $tables->{$table} or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | die "Table $table not defined.\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | 27 | my $s = ''; | |||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | 27 | for my $col (@$tb_spec) { | |||||||||||||||||||||||||||||||||||||||||
| 542 | #say "col: ", $col->[0]; | ||||||||||||||||||||||||||||||||||||||||||
| 543 | 30 | my $name = $col->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 544 | 30 | $s .= "\t$name"; | |||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | 27 | $s .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | 27 | ▶ | if (!@$cols) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | return $s; | |||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | 27 | my $col = $cols->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 554 | 27 | my $nrows = @$col; | |||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||
| 556 | 27 | my @rows; | |||||||||||||||||||||||||||||||||||||||||
| 557 | 27 | for my $i (0 .. $nrows - 1) { | |||||||||||||||||||||||||||||||||||||||||
| 558 | 127 | my @row; | |||||||||||||||||||||||||||||||||||||||||
| 559 | 127 | for my $col (@$cols) { | |||||||||||||||||||||||||||||||||||||||||
| 560 | 140 | ▶ | my $val = $col->[$i] // 'NULL'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$col->[$i] // "NULL"
MC/DC100%1/1
$col->[$i] // "NULL"
$col->[$i]
Truth table100%2/2
A
A= $col->[$i]
| |||||||||||||||||||||||||||||||||||||||||||
| 561 | 140 | $s .= "\t$val"; | |||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||
| 563 | 127 | $s .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 564 | 127 | push @rows, \@row; | |||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | 27 | return $s; | |||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | 50 | ▶ | sub gen_domain_val ($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_domain_val: called CC=12 SCAR=30.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 571 | 50 | my $domain = shift; | |||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | ### $domain | ||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||
| 575 | 50 | ▶ | if (@$domain == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | 50 | my $i = int rand @$domain; | |||||||||||||||||||||||||||||||||||||||||
| 580 | 50 | my $atom = $domain->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 581 | #warn "domain size: ", scalar(@$domain); | ||||||||||||||||||||||||||||||||||||||||||
| 582 | #warn "ATOM: $i $atom\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 583 | 50 | ▶ | if (my $ref = ref $atom) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 584 | 32 | ▶ | if ($ref eq 'Parse::RandGen::Regexp') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | return $atom->pick; | |||||||||||||||||||||||||||||||||||||||||
| 586 | } elsif ($ref eq 'Regexp') { | ||||||||||||||||||||||||||||||||||||||||||
| 587 | 3 | $atom = Parse::RandGen::Regexp->new($atom); | |||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | return $atom->pick; | |||||||||||||||||||||||||||||||||||||||||
| 589 | } elsif ($ref eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||
| 590 | 29 | given ($atom->[0]) { | |||||||||||||||||||||||||||||||||||||||||
| 591 | 29 | when ('nrange') { | |||||||||||||||||||||||||||||||||||||||||
| 592 | 9 | my $a = $atom->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 593 | 9 | my $b = $atom->[2]; | |||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||
| 595 | 9 | ▶ | if ($b < $a) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | die "Bad range: $a .. $b: $b < $a\n"; | |||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||
| 598 | 9 | ▶ | if ($a =~ /^-?\d+$/ && $b =~ /^-?\d+$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$a =~ /^-?\d+$/ and $b =~ /^-?\d+$/
MC/DC0%0/2
$a =~ /^-?\d+$/ and $b =~ /^-?\d+$/
$a =~ /^-?\d+$/
$b =~ /^-?\d+$/
Truth table33%1/3
A and B
A= $a =~ /^-?\d+$/B= $b =~ /^-?\d+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 599 | # pure integer | ||||||||||||||||||||||||||||||||||||||||||
| 600 | 9 | return int(rand($b - $a + 1)) + $a; | |||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | return sprintf "%.5lf", rand($b - $a) + $a; | |||||||||||||||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||||||||||||||||
| 605 | 20 | when ('drange') { | |||||||||||||||||||||||||||||||||||||||||
| 606 | 10 | my $a = $atom->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 607 | 10 | my $b = $atom->[2]; | |||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | 10 | ▶ | if ($b lt $a) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | die "Bad date range: $a .. $b: $b is earlier than $a\n"; | |||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | 10 | return rand_date( min => $a, max => $b ); | |||||||||||||||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||||||||||||||||
| 615 | 10 | when ('trange') { | |||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | my $a = $atom->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | my $b = $atom->[2]; | |||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | ▶ | if ($b lt $a) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | die "Bad time range: $a .. $b: $b is earlier than $a\n"; | |||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | return rand_time( min => $a, max => $b); | |||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||
| 625 | 10 | when ('dtrange') { | |||||||||||||||||||||||||||||||||||||||||
| 626 | 10 | my $a = $atom->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 627 | 10 | my $b = $atom->[2]; | |||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | 10 | ▶ | if ($b lt $a) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | die "Bad datetime range: $a .. $b: $b is earlier than $a\n"; | |||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||
| 633 | 10 | return rand_datetime( min => $a, max => $b); | |||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | default { | |||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | die "Unknown domain atom type: $atom->[0]"; | |||||||||||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||||
| 639 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | die "Unkown domain atom ref: $ref"; | |||||||||||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||
| 644 | 18 | return $atom; | |||||||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | ▶ | sub canonicalize_table { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
canonicalize_table: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | my ($self, $table, $cols) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | my $ast = $self->ast; | |||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | my $tables = $ast->tables; | |||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | ▶ | my $tb_spec = $tables->{$table} or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 654 | die "Table $table not defined.\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | my @col_names; | |||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | for my $col (@$tb_spec) { | |||||||||||||||||||||||||||||||||||||||||
| 659 | #say "col: ", $col->[0]; | ||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | push @col_names, $col->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | my @rows = (\@col_names); | |||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | ▶ | if (!@$cols) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | return \@rows; | |||||||||||||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | my $col = $cols->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | my $nrows = @$col; | |||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | for my $i (0 .. $nrows - 1) { | |||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | my @row; | |||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | for my $col (@$cols) { | |||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | push @row, $col->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | push @rows, \@row; | |||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | return \@rows; | |||||||||||||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | ▶ | sub gen_table_schema { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_table_schema: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | my ($self, $table) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | my $ast = $self->ast; | |||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | my $deps = $ast->deps; | |||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | my $tables = $ast->tables; | |||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | my $cols = $ast->cols; | |||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | ▶ | my $tb_spec = $tables->{$table} or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 692 | die "Table $table not defined.\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | my @col_defs; | |||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | for my $col (@$tb_spec) { | |||||||||||||||||||||||||||||||||||||||||
| 697 | #use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | my $name = $col->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | my $qcol = "$table.$name"; | |||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | my $spec = $cols->{$qcol}; | |||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | my $type = $spec->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||
| 704 | #say "trying type: $type"; | ||||||||||||||||||||||||||||||||||||||||||
| 705 | 0 | ▶ | while ($type eq 'refs') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 706 | #use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | my $dep = $deps->{$qcol}; | |||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | my $col = $cols->{$dep}; | |||||||||||||||||||||||||||||||||||||||||
| 710 | #warn Dumper($col); | ||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | $type = $col->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 712 | #say "trying type for $dep $col: $type"; | ||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | $qcol = $dep; | |||||||||||||||||||||||||||||||||||||||||
| 714 | } | ||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||
| 716 | #say "type: $type"; | ||||||||||||||||||||||||||||||||||||||||||
| 717 | #say Dumper($spec); | ||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | my @attrs = grep { $_ =~ /^(?:not null|unique)$/ } @{ $spec->{attrs} }; | |||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||
| 720 | my ($cmt) = grep { | ||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | ▶ | ref $_ && ref $_ eq 'ARRAY' && $_->[0] eq 'for' | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
ref $_ && ref $_ eq 'ARRAY' && $_->[0] eq 'for'
ref $_ and ref $_ eq "ARRAY"
MC/DC0%0/3
ref $_ && ref $_ eq 'ARRAY' && $_->[0] eq 'for'
ref $_
ref $_ eq "ARRAY"
$_->[0] eq 'for'
Truth table0%0/4
A and B && C
A= ref $_B= ref $_ eq "ARRAY"C= $_->[0] eq 'for'
| |||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | } @{ $spec->{attrs} }; | |||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | ▶ | if ($cmt) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | push @attrs, "comment " . quote_sql_str($cmt->[1]); | |||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | push @col_defs, { | |||||||||||||||||||||||||||||||||||||||||
| 729 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 730 | type => $type, | ||||||||||||||||||||||||||||||||||||||||||
| 731 | attrs => \@attrs, | ||||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | return \@col_defs, | |||||||||||||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||
| 738 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||