-5

I am using the following two tests for the common pangram program. But test2 passes while test3 fails.

    @Test
    public void test2(){
        Pangram4 pangram4 = new Pangram4(" b cd x rs  ijk pno f vu");
        Set<Character> actual = pangram4.getMissingAlphabets();
        Set <Character>expected = new HashSet<Character>();
        expected.add('a');
        expected.add('e');
        expected.add('g');
        expected.add('h');
        expected.add('l');
        expected.add('m');
        expected.add('q');
        expected.add('t');
        expected.add('w');
        expected.add('y');
        expected.add('z');

        assertEquals(expected,actual);
    }


    @Test
    public void test3(){
        Pangram4 pangram4 = new Pangram4("The quick browndoga lazy.");
        Set<Character> actual = pangram4.getMissingAlphabets();
        Set<Character> expected = new HashSet<Character>();
        expected.add('f');
        expected.add('o');
        expected.add('x');
        expected.add('j');
        expected.add('u');
        expected.add('m');
        expected.add('p');
        expected.add('s');
        expected.add('o');
        expected.add('v');
        expected.add('e');
        expected.add('r');          
        assertEquals(expected, actual);
    }

What can be the reason? I have only given the test methods here, not the entire junit class. Please use any pangram program with getMissingLetters() method that returns the Set and change test method accordingly.

Developer
  • 3
  • 2

1 Answers1

2

In your test case test3(), you are "expecting" an o:

expected.add('o');

The letter o is in the test case string, "The quick browndoga lazy.". The result is that the expected set contains an o while the actual set does not. This results in a false result.

As @JasonC mentioned, there is also the same problem with the r.

Robert Columbia
  • 6,313
  • 15
  • 32
  • 40
  • 2
    even added twice - to be sure? – Scary Wombat Sep 28 '16 at 02:29
  • R is there too. – Jason C Sep 28 '16 at 02:30
  • And U, lol... I think that's it. This is the most fun I've had in at least the last half hour. – Jason C Sep 28 '16 at 02:35
  • Thanks, I did not see that! – Developer Sep 28 '16 at 02:39
  • First I removed only the "fox" from the perfect pangram and then added it to the expected. I did not see that o is also in brown. And then I removed "jumps over" and tried to add it the expected. I did not see that these letters are repeated. – Developer Sep 28 '16 at 02:42
  • @Developer That's why printing the contents of actual would have helped. Then you look at it, you see that it's missing some of the expected letters, and you find out why. During that debugging progress you no doubt would have noticed those letters in that sentence. – Jason C Sep 28 '16 at 03:17