Package edu.eltech

Source Code of edu.eltech.PlainSpamClassifierTest

package edu.eltech;

import edu.eltech.classifier.Category;
import edu.eltech.classifier.Letter;
import edu.eltech.classifier.PlainSpamClassifier;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
* User: ivan
* Date: 21.03.12
* Time: 17:17
*/
@Ignore public class PlainSpamClassifierTest {
   
    private List<Letter> spamSamples = new ArrayList<Letter>();
    private List<Letter> nonSpamSamples = new ArrayList<Letter>();
    private PlainSpamClassifier classifier = new PlainSpamClassifier();

    @Before
    public void setUp() throws Exception {
        spamSamples.add(new Letter("title1", "THIS LETTER IS SENT TO YOU BECAUSE..."));
        spamSamples.add(new Letter("title2", "you won 100000000000000000$"));
        spamSamples.add(new Letter("title3", "spam SPAM SPAM spam"));
        spamSamples.add(new Letter("title4", "you won !!!!!!!!!!!!!!!!!!!!!"));

        nonSpamSamples.add(new Letter("title5", "THIS IS not an undesired subscription") );
        nonSpamSamples.add(new Letter("title6", "i am sending you 3000$") );
        nonSpamSamples.add(new Letter("title7", "Just a plain letter with some text") );
        nonSpamSamples.add(new Letter("title8", "The concert was excellent !!!") );
    }

    @Test
    public void testClassifyPositive() throws Exception {

        for (Letter l : spamSamples)
            Assert.assertSame(classifier.classify(l).getType(), Category.Type.SPAM);

    }

    @Test
    public void testClassifyNegative() throws Exception {

        for (Letter l : nonSpamSamples)
            Assert.assertSame(classifier.classify(l).getType(), Category.Type.NOT_SPAM);

    }

    @Test
    public void testGetPattern() throws Exception {

        String pattern = classifier.getPattern();

        Assert.assertFalse( "1234567 !!! some text".matches(pattern) );
        Assert.assertTrue( "some text !!!! some text".matches(pattern) );
        Assert.assertTrue( "some text !!!!! some text".matches(pattern) );

        Assert.assertFalse( "1234567 12345$ some text".matches(pattern) );
        Assert.assertTrue( "some text 123456$ some text".matches(pattern) );
        Assert.assertTrue( "some text 12345678912345$ some text".matches(pattern) );
        Assert.assertTrue( "some text 99999999999999999$ some text".matches(pattern) );

        Assert.assertFalse( "1234567 Winner some text".matches(pattern) );
        Assert.assertTrue( "some text YOU WON ANN IPAD some text".matches(pattern));
    }

    @Test
    public void testGetSpamIndicators() throws Exception {

        String pattern = classifier.getPattern();

        Assert.assertFalse( "!!!".matches(pattern) );
        Assert.assertTrue( "!!!!".matches(pattern) );
        Assert.assertTrue( "!!!!!".matches(pattern) );

        Assert.assertFalse( "12345$".matches(pattern) );
        Assert.assertTrue( "123456$".matches(pattern) );
        Assert.assertTrue( "12345678912345$".matches(pattern) );
        Assert.assertTrue( "99999999999999999$".matches(pattern) );

        Assert.assertFalse( "you are winner".matches(pattern) );
        Assert.assertFalse( "THIS IS not an undesired subscription".matches(pattern) );
        Assert.assertTrue( "YES YOU ARE WINNER".matches(pattern));
    }



}
TOP

Related Classes of edu.eltech.PlainSpamClassifierTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.