# Test::FIT Example Page

Click this link to run all the tests on this page: fit-run.cgi

### MathFixture Example

This is the same test that is discussed in the Test::FIT documentation.
You just create an table like this:

MathFixture
x | y | sum | diff
1 | 2 | 3 | -1
-8 | 12 | 4 | -4

The MathFixture Perl class looks like this:

    package MathFixture;
    use base 'Test::FIT::ColumnFixture';
    use Test::FIT;

    attribute 'x';
    attribute 'y';

    sub sum {
        my $self = shift;
        $self->eq_num($self->x + $self->y);
    }

    sub diff {
        my $self = shift;
        $self->eq_num($self->x - $self->y);
    }

    1;

### SampleFixture Example

Here is a demonstration of some of the various properties of a ColumnFixture class:

SampleFixture
first | last | perl_hacker | last_backwards
Brian | Ingerson |  | nosregnI
Ward | Cunningham |  | draW
George | Bush |  | hsuB

The SampleFixture.pm Perl class looks like this:

    package SampleFixture;
    use base 'Test::FIT::ColumnFixture';
    use Test::FIT;

    attribute 'first';
    attribute 'last';

    sub perl_hacker {
        my $self = shift;
        my $name = join ' ', $self->first, $self->last;
        if ($name =~ /(Ward|Brian)/) {
            $self->pass("Oh yes");
        }
        else {
            $self->fail("No way!");
            $self->stop;
        }
    }

    sub last_backwards {
        my $self = shift;
        $backwards = join '', reverse split '', $self->last;
        $self->eq_str($backwards);
    }

    1;

### Test::FIT::ColumnFixture Example

You can actually use the ColumnFixture class all by itself. This is only for very simple types of tests.

Test::FIT::ColumnFixture
x | x_eq_str | x_is_like
Brian Ingerson | Brian Ingerson | ingy
Ward Cunningham | Karen CunningHam | Cunning

The Test::FIT::Fixture provides a few dummy attributes like x, y and z for convenience. So the attribute definitions in the MathFixture example were not actually necessary.

### Error Examples

These tables show some various error conditions:
No header row defined...

Test::FIT::ColumnFixture

Invalid method for class...

Test::FIT::ColumnFixture
x | foo | is_like
Brian Ingerson | Brian Ingerson | ingy
Ward Cunningham | Karen CunningHam | Cunning

Invalid class altogether...

bogus_Fixture
x | eq_str | is_like
Brian Ingerson | Brian Ingerson | ingy
Ward Cunningham | Karen CunningHam | Cunning

Note how error messages appear directly in the cell that caused them.

Click this link to run all the tests on this page: fit-run.cgi

Download Test-FIT from http://www.cpan.org/modules/by-authors/id/I/IN/INGY/