Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Code Need help

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Code Need help

    here is some code that i cant get to work :S can anyone help me please.


    import junit.framework.TestCase;
    class TextAnalyser
    {

    // These are the instance variables

    private String TextAnalyser;
    // This is the constructor

    public TextAnalyser(String TextAnalyser)
    {
    this.TextAnalyser = TextAnalyser;



    }


    public class TextAnalyserTest extends TestCase {

    String gettysburg = "Four score and seven years ago, our fathers brought forth upon this continent a new nation: conceived in liberty, and dedicated to the proposition that all men are created equal.Now we are engaged in a great civil war. . .testing whether that nation, or any nation so conceived and so dedicated. . . can long endure. We are met on a great battlefield of that war.We have come to dedicate a portion of that field as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.But, in a larger sense, we cannot dedicate. . .we cannot consecrate. . . we cannot hallow this ground. The brave men, living and dead, who struggled here have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember, what we say here, but it can never forget what they did here.It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us. . .that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion. . . that we here highly resolve that these dead shall not have died in vain. . . that this nation, under God, shall have a new birth of freedom. . . and that government of the people. . .by the people. . .for the people. . . shall not perish from the earth.";
    int[] vals = {102,14,31,58,165,27,28,80,68,0,3,42,13,77,93,16,1 ,79,44,126,22,24,28,0,10,0};
    String nonalpha = " *** 42 !!";
    String equalAB = "ABaabbAB";
    String sample = "The quick brown fox jumped over the lazy dog.";
    String programming = "Programming is related to several fields of technology and many university students are studying the basics of it. ";


    public void testTextAnalyserConstructorParam() {
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    assertEquals("TestCorpus", ta.getCorpusID());
    }


    public void testTextAnalyserInitialnumChars() {
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    assertEquals("Initial character count should be 0",0, ta.getNumChars());
    }



    public void testTextAnalyserCountOnlyChars() {
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    ta.addTexttoCorpus(sample);
    assertEquals(36, ta.getNumChars());
    }

    public void testCheckNonChars() {
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    ta.addTexttoCorpus(nonalpha);
    assertEquals("There are no alpha chars in "+nonalpha, 0, ta.getNumChars());
    }

    public void testClear() {
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    ta.addTexttoCorpus(sample);
    assertEquals("Clear sets charsAnalysed to 0", 36, ta.getNumChars());
    ta.clear();
    assertEquals("Clear sets charsAnalysed to 0", 0, ta.getNumChars());
    }

    public void testAddTextRepeated() {
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    ta.addTexttoCorpus("ABCDEfghijklmnopqrstuvwxyz");
    ta.addTexttoCorpus("Hellotherethisisjustanarbi");
    ta.addTexttoCorpus("ABCDEfghijklmnopqrstuvwxyz");
    assertEquals("Add chars analysed to totals for repeated calls of analyse", 26*3, ta.getNumChars());
    }

    public void testFrequencyShort() {
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    ta.addTexttoCorpus("Programming is related to several fields of technology and many university students are studying the basics of it. ");
    assertEquals(9,ta.frequencyOf('s'));
    assertEquals(10,ta.frequencyOf('e'));
    assertEquals(8,ta.frequencyOf('i'));
    assertEquals(6,ta.frequencyOf('o'));
    }


    public void testFrequencyLong() {
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    ta.addTexttoCorpus(gettysburg);
    for (char ch = 'a'; ch <= 'z'; ch++) {
    assertEquals(vals[ch-'a'], ta.frequencyOf(ch));
    }
    for (char ch = 'A'; ch <= 'Z'; ch++) {
    assertEquals(vals[ch-'A'], ta.frequencyOf(ch));
    }
    }



    public void testFrequencyLowerCase(){
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    ta.addTexttoCorpus(nonalpha);
    for (char ch = 'a'; ch <= 'z'; ch++) {
    assertEquals(0,ta.frequencyOf(ch));
    }
    }

    public void testFrequencyUpperCase(){
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    ta.addTexttoCorpus(nonalpha);
    for (char ch = 'A'; ch <= 'Z'; ch++) {
    assertEquals(0,ta.frequencyOf(ch));
    }
    }

    public void testPercentageShort() {
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    ta.addTexttoCorpus(programming);
    assertEquals(9.4,ta.percentageOf('s'),0.1); //to 1DP accuracy
    assertEquals(10.4,ta.percentageOf('e'),0.1);
    assertEquals(8.3,ta.percentageOf('i'),0.1);
    assertEquals(6.25,ta.percentageOf('o'),0.1);
    }

    public void testPercentageNonalpha(){
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    ta.addTexttoCorpus(nonalpha);
    assertEquals(0,ta.percentageOf('e'),0.1); //to 1DP accuracy
    }

    public void testMostFrequent(){
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    ta.addTexttoCorpus(gettysburg);
    assertEquals('e',ta.mostFrequent());
    }

    public void testMostFrequentNonalpha(){
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    ta.addTexttoCorpus(nonalpha);
    assertEquals("Error code ? expected for mostFrequent in "+nonalpha,'?',ta.mostFrequent());
    }

    public void testMostFrequentEmpty(){
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    assertEquals("Error code ? expected for mostFrequent in empty string",'?',ta.mostFrequent());
    }

    public void testMostFrequentEqual(){
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    ta.addTexttoCorpus(equalAB);
    boolean actual = ((ta.mostFrequent()=='a') || (ta.mostFrequent()=='b'));
    assertEquals("Either a or b is most frequent in "+equalAB, true, actual);
    }

    public void testMostFrequentuptoMax() {
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    ta.addTexttoCorpus("aAaAaA bB cCcC");
    assertEquals('a', ta.mostFrequentuptoMax(7) );
    assertEquals('c', ta.mostFrequentuptoMax(6) );
    assertEquals('b', ta.mostFrequentuptoMax(4) );
    }

    public void testTopLetters() {
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    ta.addTexttoCorpus(gettysburg);
    assertEquals("etao", ta.topLetters(4) );
    }

    public void testLong() {
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    ta.addTexttoCorpus( TextImporter.getURLText("alice30.txt") );
    assertEquals(1475, ta.frequencyOf('b'));
    assertEquals(13574, ta.frequencyOf('e'));
    //TODO could check some other letters
    }

    public void testLongTopLetters() {
    TextAnalyser ta = new TextAnalyser("TestCorpus");
    ta.addTexttoCorpus( TextImporter.getURLText("alice30.txt") );
    assertEquals("etaoi", ta.topLetters(5) );
    }

    }
    }


  2. #2
    Junior Member
    Join Date
    Mar 2010
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Code Need help

    I don't know what kind of help you want and what are you importing and where is your testcase??
    Well, be more explanatory that what problem you are facing?
    It's too difficult to look over the whole code. We are here, just to help you for your problems. Thanks