use strict;
use warnings;
use Test::More tests => 10;
use WWW::MySociety::Gaze;

ok my $gaze = WWW::MySociety::Gaze->new, 'new';
isa_ok $gaze, 'WWW::MySociety::Gaze';

{
    ok my $country = $gaze->get_country_from_ip( '192.5.6.30' ),
      'got country code';
    like $country, qr{^[A-Z]+$}, 'country code looks OK';
}

{
    my @countries = $gaze->get_find_places_countries;
    ok @countries > 30, 'got some countries';
    my @nice = grep { qr{^[A-Z]+$} } @countries;
    is_deeply \@nice, \@countries, 'all valid ISO codes';
}

{
    my @places = $gaze->find_places(
        country => 'GB',
        query   => 'Newcastle upon Tyne'
    );
    ok @places > 3, 'got some places';
    like $places[0]->{Name}, qr{^Newcastle}, 'first name matches';
}

{
    my $density
      = $gaze->get_population_density( 54.9880556, -1.6194444 );

    # Should be OK until Newcastle disappears under water or becomes
    # uncomfortably crowded.
    ok $density > 100 && $density < 1_000_000, 'density looks OK';
}

{
    my $radius = $gaze->get_radius_containing_population(
        lat    => 54.9880556,
        lon    => -1.6194444,
        number => 10_000
    );

    ok $radius > 10 && $radius < 1_000_000, 'radius looks OK';
}
