Skip to content

Instantly share code, notes, and snippets.

@wolfjohns
Created April 28, 2022 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolfjohns/d704dfc0420656a573c0dafadb8a680c to your computer and use it in GitHub Desktop.
Save wolfjohns/d704dfc0420656a573c0dafadb8a680c to your computer and use it in GitHub Desktop.
Topic8_unit_tests_ex10
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
#use_ok('Some::Module'); # This should be the module you're testing
use_ok('Airport::Data');
ok(1, '1 is always true');
is(1, "1", '1 is "1" according to "is"');
isnt(1, 0, '1 is not 0');
# FIXME write some proper tests
my $rah_airports = Airport::Data::parse_airports("t/data/airports1.csv");
my $ra_search_res = Airport::Search::get_name_matching_airports($rah_airports);
done_testing;
package Airport::Search;
use strict;
use warnings;
sub get_name_matching_airports {
#my $fields = parse_airports($filename);
#my ($match, $str) = @_;
my @match;
my %args = (
airports => undef,
#matching => undef, # ANDREW FIX B
matching_string => undef,
word => undef,
@_
);
for my $x ( @{ $args{"airports"} }) {
#for my $x (%args{"airports"}) {
#if ($x->{name} =~ /$args{"matching"}/i) { # ANDREW FIX C
if (defined $args{"word"}) {
if ($x->{name} =~ /\b$args{"matching_string"}\b/i) {
#push $rah_airports_found, $x;
push @match, $x;
}
} else {
if ($x->{name} =~ /$args{"matching_string"}/i) {
#push $rah_airports_found, $x;
push @match, $x;
}
}
}
#pp %args{airports};
#return $rah_airports_found;
return \@match;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment