Testing algorithm