#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests=>12;

BEGIN { use_ok('Student'); }

my $stu = Student->new('John Smith', '016-32-9823', '337');

#make sure $stu is a Student, and in turn, a Person
isa_ok($stu, 'Student');
isa_ok($stu, 'Person');

#make sure $stu has all the methods it should
can_ok($stu, qw/name SSN id GPA/);

is($stu->name(), 'John Smith', 'Name set');
is($stu->SSN(), '016-32-9823', 'Social Security Number set');
cmp_ok($stu->id(), '==', 337, 'Id set');

#set the GPA
$stu->GPA(100);
cmp_ok($stu->GPA(), '==', 100, 'GPA set');

#test status
is($stu->status(), 'passing', '\'Passing\' status');
$stu->GPA(64);
is($stu->status(), 'failing', '\'Failing\' status');

#test string overload
is("$stu", 'John Smith (016-32-9823)', "String overloading");

#test show() method.  To do this, we're going to create
#an "in-memory" file handle, and select() that filehandle,
#so that the print call in show() will print to that filehandle
open my $mem_fh, '>', \my $buffer or die "Cannot create in-memory FH: $!";
my $old_fh = select($mem_fh);
$stu->show();
#select() back to the old FH, so we don't screw up any output.
is($buffer, "John Smith has a SS# of 016-32-9823\n", 'show() method');

