testing with math::combinatorics

13
Testing with Math::Combinatorics Anirvan Chatterjee www.chatterjee.net

Upload: anirvanchatterjee

Post on 16-Jan-2015

1.083 views

Category:

Education


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Testing with Math::Combinatorics

Testing with Math::Combinatorics

Anirvan Chatterjee

www.chatterjee.net

Page 2: Testing with Math::Combinatorics

We run a comparison shopping site for new and used books

Page 3: Testing with Math::Combinatorics

Booksellers give us icky data

Henry Wadsworth Longfellow

Henry, Wadsworth Longfellow

Longfellow. H

H.W.Longfellow

Henri Longfellow

LONGFELLOW, HENRY WA.

Longfellow, Henry Wadssworth.

Page 4: Testing with Math::Combinatorics

Lots and lots of icky dataLongfellow, Henry

Wadsworth.LONGFELLOW, HENRY

WADSWORTH.Longfellow, Henry Longfellow, Henry WadworthLongfellow, Henry

Wadsworth. Edited By Anna H. Smith

Longfellow, H. W.LONGFELLOW, H.W.,LONGFELLOW, Henry

Wadsworth, edited byHenry W. LongfellowLongfellow. HLongfellow, H. WHenry Wadsworth

Longfellow, et alLongfellow, Henrry

WadsworthLONGFELLOW, HENRY

WADSWORTHLongfellow, H.Longfellow Henry WadsworthHenry LongfellowLongfellow H. W.Longfellow, Wadsworth

Henry

Longfellow, Henry Wadsworth

Longfellow, Henry Wadsworth [Signed]

Longfellow, Henry W.

Longfellow,Henry Wadsworth

Henry Wadsworth Longfellow

Henry, Wadsworth Longfellow

Henry, Wadsworth Longfellow

Longfellow, Henry Wadsworh

LONGFELLOW, H.W.

LONGFELLOW WADSWORTH, Henry

LONGFELLOW,H.W.

LONGFELLOW, Henry

Longfellow H. W

Longfellow, H.W.

LONGFELLOW Henry Wadsworth

H.W.Longfellow

Longfellow, Henry, W.

LONGFELLOW, Henry Wadsworrth

Longfellow, Henry Wadsworth [1807 - 1882].,

Longfellow. H.

LONGFELLOW, Henry Wadsworth

Longfellow, Henry Wadsworth (translated)

Henry Wadworth Longfellow

Longfellow Henry W

Henri Longfellow

Longfellow, (Henry Wadsworth)

Longfellow, Henry Wadsworth;

LONGFELLOW, H. W

Longfellow. H.W

Longfellow Henry W.

Longfellow, Henry Wadsworth,

H.W. LONGFELLOW

LONGFELLOW, HENRY WA.

Longfellow, Henry W.[adsworth]

Longfellow, H.W

Longfellow, (H. W.)

Longfellow, Henry Wadsworth"

HENRY WADSWORTH LONGFELLOW

LONGFELLOW, H. W.

longfellow, Henry Wadsworth

Longfellow, Henry W

Longfellow, Henry Longfellow

HENRY W. LONGFELLOW

Longfellow, , Henry W

Longfellow, Henry. Wadsworth.

Longfellow , Henry Wadsworth

Longfellow, Henry Wadsworth [Signed],

Longfellow, Henry W.,

Wadsworth Longfellow, Henry

WADSWORTH LONGFELLOW, HENRY

LONGFELLOW, Henry W.

Longfellow, Henry, Wadsworth

LONGFELLOW, (HENRY WADSWORTH)

Longfellow, Henry Wadssworth.

Longfellow H

LONGFELLOW, H.W

Page 5: Testing with Math::Combinatorics

We use clustering algorithms

my @authors =

author_cluster(

‘Henry Longfellow’

‘H.W.Longfellow (1807-82)’,

‘Henri Longfelow’);

# one single author cluster

is @authors, 1;

Page 6: Testing with Math::Combinatorics

Testing is critical

use Test::More tests => 2;

@authors = author_cluster( ‘Isaac Asimov’, ‘ASIMOV, Isaac’);is @authors, 1;

@authors = author_cluster( ‘Isaac Asimov’, ‘Issac Asimov’);is @authors, 1;

Page 7: Testing with Math::Combinatorics

We want to test combinations

author_cluster(A)

author_cluster(B)

author_cluster(C)

author_cluster(A, B)

author_cluster(A, C)

author_cluster(B, C)

author_cluster(A, B, C)

Page 8: Testing with Math::Combinatorics

We want to test permutations

author_cluster(A, B, C)

author_cluster(A, C, B)

author_cluster(B, A, C)

author_cluster(B, C, A)

author_cluster(C, A, B)

author_cluster(C, B, A)

Page 9: Testing with Math::Combinatorics

Math::Combinatoricsmakes things easy

Page 10: Testing with Math::Combinatorics

Iterate through combinations

my @data =

qw( A B C );

for my $i (1..@data) {

my $c = new Math::Combinatorics data => \@data, count => $i;

while (my @combination = $c->next_combination) {

print @combination, q{ };

}

}

# A B C AB AC BC ABC

Page 11: Testing with Math::Combinatorics

Add every permutation

my @data = qw( A B C );

for my $i (1..@data) { my $c = new Math::Combinatorics data => \@data, count => $i; while (my @combination = $c->next_combination) { my $p = new Math::Combinatorics data => \@combination; while (my @permutation = $p->next_permutation) { print @permutation, q{ }; } }}

# A B C AB BA AC CA BC CB ABC ACB BAC BCA CAB CBA

Page 12: Testing with Math::Combinatorics

Plug in the tests

my @data =

(‘Longfellow, Henry’, ‘H.W.Longfellow’, etc.)

for my $i (1..@data) {

my $c = new Math::Combinatorics data => \@data, count => $i;

while (my @combination = $c->next_combination) {

my $p = new Math::Combinatorics data => \@combination;

while (my @permutation = $p->next_permutation) {

test_author_clustering(@permutations);

}

}

}

Page 13: Testing with Math::Combinatorics

Tested codemeans happier users.

Yay, testing.